Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Terraform Version Resource #400

Merged
merged 3 commits into from
Jan 5, 2022

Conversation

sebasslash
Copy link
Contributor

@sebasslash sebasslash commented Jan 3, 2022

Description

This PR implements the Terraform Version resource for creating and managing terraform versions using TFE provider. The resource block uses the name tfe_terraform_version and looks as follows:

resource "tfe_terraform_version" "foo" {
  version = "99.99.99"
  url = "https://my-tfe-host.com/path/to/terraform.zip"
  sha = "e75ac73deb69a6b3aa667cb0b8b731aee79e2904"
}

The Terraform version resource defines the following attributes:

  • version - (Required) A semantic version string in N.N.N or N.N.N-bundleName format.
  • url - (Required) The URL where a ZIP-compressed 64-bit Linux binary of this version can be downloaded.
  • sha - (Required) The SHA-256 checksum of the compressed Terraform binary.
  • official - (Optional) Whether or not this is an official release of Terraform. Defaults to false.
  • enabled - (Optional) Whether or not this version of Terraform is enabled for use in Terraform Cloud. Defaults to true.
  • beta - (Optional) Whether or not this version of Terraform is beta pre-release

Testing plan

  1. In order to create and manage Terraform versions you must be an site admin on the TFE host you specify with TFE_HOSTNAME. You can set TFE_TOKEN to be the user token for your TFE_HOST in your credentials file (depending on your TFE version you no longer need a TFE_ADMIN_TOKEN env var set).
  2. In order to run the unit tests run the following in your shell: TESTARGS="-run TestAccTFETerraformVersion" make testacc

If you wish to run this version of the provider locally ensure you've created a .tfrc configuration file with:

  dev_overrides {
    "hashicorp/tfe" = "path/to/provider/binary"
  }

Create your terraform configuration with the terraform version resource and run

TF_CLI_CONFIG_FILE=/path/to/tfrc terraform apply -auto-approve

External links

Output from acceptance tests

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run TestAccTFETerraformVersion -timeout 15m
?       github.com/hashicorp/terraform-provider-tfe     [no test files]
=== RUN   TestAccTFETerraformVersion_basic
--- PASS: TestAccTFETerraformVersion_basic (26.00s)
=== RUN   TestAccTFETerraformVersion_full
--- PASS: TestAccTFETerraformVersion_full (25.12s)
PASS
ok      github.com/hashicorp/terraform-provider-tfe/tfe 51.696s
?       github.com/hashicorp/terraform-provider-tfe/version     [no test files]

@sebasslash sebasslash requested a review from a team as a code owner January 3, 2022 20:33
@sebasslash sebasslash requested a review from lafentres January 3, 2022 21:08
Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

Looks great! I think the only thing you need is to add the new resource to the documentation. (website/r folder)

version := genVersion(rInt)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, // TODO: Find out what this means
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a couple of these TODOs in the change. What this does is configures the provider with creds, etc against the nightly TFC server and tests that no config errors happened.

@sebasslash sebasslash force-pushed the sebasslash/terraform-version-resource branch from 09c451b to 722c8dd Compare January 4, 2022 19:51
This commit implements the Terraform version resource block "tfe_terraform_version" which
allows practitioners to create and manage Terraform versions on TFE.

This commit also outlines two tests for this resource. It generates a mock terraform version using a random version number and SHA. The URL attribute points to hashicorp.com since the TFC API doesn't download or verify that the zip exists when the resource is created. The basic test tests against the required parameters and the full test includes the optional parameters.
@sebasslash sebasslash force-pushed the sebasslash/terraform-version-resource branch from 722c8dd to f25d34f Compare January 4, 2022 19:54
* `url` - (Required) The URL where a ZIP-compressed 64-bit Linux binary of this version can be downloaded.
* `sha` - (Required) The SHA-256 checksum of the compressed Terraform binary.
* `official` - (Optional) Whether or not this is an official release of Terraform. Defaults to "false".
* `enabled` - (Optional) Whether or not this version of Terraform is enabled for use in Terraform Cloud. Defaults to "true".
Copy link
Member

@chrisarcand chrisarcand Jan 4, 2022

Choose a reason for hiding this comment

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

This is actually an issue in the API docs, too - this is true of TFE as well as TFC, even though the docs seem to indicate TFC only, IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So just update the docs to say for use in Terraform Cloud or Enterprise ?

website/docs/r/terraform_version.html.markdown Outdated Show resolved Hide resolved
website/docs/r/terraform_version.html.markdown Outdated Show resolved Hide resolved
website/docs/r/terraform_version.html.markdown Outdated Show resolved Hide resolved
@sebasslash sebasslash merged commit ffff766 into main Jan 5, 2022
@sebasslash sebasslash deleted the sebasslash/terraform-version-resource branch January 5, 2022 17:00
@chrisarcand
Copy link
Member

Nice work!

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.

3 participants