Skip to content

feat: Add Terraform Provider for agent resources#368

Merged
kylecarbs merged 12 commits into
mainfrom
tfprovider
Feb 28, 2022
Merged

feat: Add Terraform Provider for agent resources#368
kylecarbs merged 12 commits into
mainfrom
tfprovider

Conversation

@kylecarbs
Copy link
Copy Markdown
Member

This adds a coder Terraform Provider that adds two resources:

// Provides a script for fetching and starting the agent for the OS and architecture provided.
data "coder_agent_script" "name" {
  os = "windows"
  arch = "amd64"
}

// Adds metadata to the agent.
resource "coder_agent" "name" {
  startup_script = "echo test"
}

resource "kubernetes_pod" "example" {
  spec {
    containers {
      image = "example.io"
      env = {
        CODER_TOKEN = coder_agent.name.token
      }
      command = data.coder_agent_script.name.value
    }
  }
}

@kylecarbs kylecarbs self-assigned this Feb 26, 2022
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2022

Codecov Report

Merging #368 (7594657) into main (512e239) will increase coverage by 0.32%.
The diff coverage is 72.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #368      +/-   ##
==========================================
+ Coverage   67.70%   68.03%   +0.32%     
==========================================
  Files         148      148              
  Lines        8064     8096      +32     
  Branches       72       72              
==========================================
+ Hits         5460     5508      +48     
+ Misses       2041     2026      -15     
+ Partials      563      562       -1     
Flag Coverage Δ
unittest-go-macos-latest 66.18% <66.01%> (-0.10%) ⬇️
unittest-go-ubuntu-latest 67.44% <72.91%> (+0.14%) ⬆️
unittest-go-windows-2022 ?
unittest-js 66.10% <ø> (ø)
Impacted Files Coverage Δ
codersdk/files.go 66.66% <33.33%> (-10.26%) ⬇️
provisioner/terraform/provider/provider.go 55.22% <55.22%> (ø)
provisioner/terraform/provision.go 74.20% <78.10%> (+4.02%) ⬆️
provisionersdk/agent.go 85.00% <85.00%> (ø)
coderd/coderd.go 95.37% <100.00%> (ø)
coderd/files.go 74.46% <100.00%> (ø)
coderd/provisionerdaemons.go 60.51% <100.00%> (-0.29%) ⬇️
pty/ptytest/ptytest.go 85.18% <0.00%> (-5.56%) ⬇️
peer/channel.go 82.45% <0.00%> (-2.34%) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 512e239...7594657. Read the comment docs.

Comment thread Makefile
Comment on lines +2 to +3
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the foundation for cross-compilation coming in 🎉

Comment thread Makefile
Comment on lines +71 to +72
mkdir -p ~/.terraform.d/plugins/coder.com/internal/coder/0.2/$(OS_ARCH)
cp bin/terraform-provider-coder ~/.terraform.d/plugins/coder.com/internal/coder/0.2/$(OS_ARCH)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

Not a blocker or needed but eventually we'll need a nice way to set the VERSION (vs the hardcoded 0.2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened an issue to track here: #376

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, awesome!

Comment thread codersdk/files.go Outdated
Copy link
Copy Markdown
Contributor

@bryphe-coder bryphe-coder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for integrating this @kylecarbs - just minor nits but overall looks great.

Comment thread provisioner/terraform/provider/provider.go Outdated
Comment thread provisioner/terraform/provider/provider.go Outdated
Comment thread provisioner/terraform/provider/provider.go
Comment thread provisioner/terraform/provision_test.go
Co-authored-by: Bryan <bryan@coder.com>
@kylecarbs kylecarbs enabled auto-merge (squash) February 28, 2022 17:07
@kylecarbs kylecarbs merged commit 35ae532 into main Feb 28, 2022
@kylecarbs kylecarbs deleted the tfprovider branch February 28, 2022 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants