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

[BETA] CRUD support for no-code registry modules #836

Merged
merged 26 commits into from
Apr 19, 2023
Merged

Conversation

dsa0x
Copy link
Contributor

@dsa0x dsa0x commented Mar 29, 2023

Description

This adds support for managing a no-code registry modules. It introduces a new resource called tfe_nocode_module which can be attached to a tfe_registry_module resource, to make it a no-code module. The user can also define variable options for the no-code module, adding a finite number of values allowed for the variable.

Testing plan

Note: Because the organization needs to have permissions to the featureflag, and the organization will be created during the test, you'll have to test this against a local atlas instance where the flag is defaulted to true for everyone.

  • Create a User in TFC
  • Create an Organization (e.g my-org) and ensure they have access to the new no-code API (you can do that in launchdarkly)
  • Generate an API token for your user in TFC
  • Point the dev environment to your user and TFC instance. e.g
// tfe/resource_tfe_no_code_module_test.go
func init() {
	os.Setenv("TF_ACC", "1")
	os.Setenv("ENABLE_BETA", "1")
	os.Setenv("TFE_ADDRESS", "https://tfcdev-foobar.eu.ngrok.io")
	os.Setenv("TFE_HOSTNAME", "tfcdev-foobar.eu.ngrok.io")
	os.Setenv("TFE_TOKEN", "your-token")
}
  • Manually test with various configurations similar to:
    • Basic no-code module

      resource "tfe_organization" "foobar" {
      name  = "my-org"
      email = "admin@company.com"
      }
      
      resource "tfe_registry_module" "foobar" {
          organization    = tfe_organization.foobar.id
          module_provider = "my_provider"
          name            = "test_module"
      }
      
      resource "tfe_nocode_module" "foobar" {
          organization = tfe_organization.foobar.id
          registry_module = tfe_registry_module.foobar.id
      }
    • With variable options

      resource "tfe_organization" "foobar" {
      name  = "my-org"
      email = "admin@company.com"
      }
      
      resource "tfe_registry_module" "foobar" {
          organization    = tfe_organization.foobar.id
          module_provider = "my_provider"
          name            = "test_module"
      }
      
      resource "tfe_nocode_module" "foobar" {
          organization = tfe_organization.foobar.id
          registry_module = tfe_registry_module.foobar.id
      
          variable_options {
              name    = "ami"
              type    = "string"
              options = [ "ami-0", "ami-1", "ami-2" ]
          }
      
          variable_options {
              name    = "region"
              type    = "string"
              options = ["us-east-1","us-west-2"]
          }
      }
  • Ensure new tests pass

External links

Output from acceptance tests

Please run applicable acceptance tests locally and include the output here. See testing.md to learn how to run acceptance tests.

If you are an external contributor, your contribution(s) will first be reviewed before running them against the project's CI pipeline.

$ go test -timeout 30m -run ^TestAccTFENoCodeModule_ github.com/hashicorp/terraform-provider-tfe/tfe -v
=== RUN   TestAccTFENoCodeModule_basic
--- PASS: TestAccTFENoCodeModule_basic (8.64s)
=== RUN   TestAccTFENoCodeModule_with_variable_options
--- PASS: TestAccTFENoCodeModule_with_variable_options (8.09s)
=== RUN   TestAccTFENoCodeModule_update
--- PASS: TestAccTFENoCodeModule_update (12.67s)
=== RUN   TestAccTFENoCodeModule_update_variable_options
--- PASS: TestAccTFENoCodeModule_update_variable_options (12.78s)
=== RUN   TestAccTFENoCodeModule_delete
--- PASS: TestAccTFENoCodeModule_delete (12.63s)
=== RUN   TestAccTFENoCodeModule_import
--- PASS: TestAccTFENoCodeModule_import (9.76s)
PASS
ok      github.com/hashicorp/terraform-provider-tfe/tfe 65.336s

...

@dsa0x dsa0x force-pushed the sams/no-code-var-opts branch 3 times, most recently from 363ad44 to df0a48a Compare March 31, 2023 10:24
@dsa0x dsa0x self-assigned this Mar 31, 2023
@dsa0x dsa0x marked this pull request as ready for review March 31, 2023 10:45
@dsa0x dsa0x requested a review from a team as a code owner March 31, 2023 10:45
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

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

Looking good! Comments below.

tfe/provider.go Outdated Show resolved Hide resolved
tfe/testing.go Outdated Show resolved Hide resolved
tfe/resource_tfe_no_code_module.go Show resolved Hide resolved
tfe/resource_tfe_no_code_module.go Outdated Show resolved Hide resolved
tfe/resource_tfe_no_code_module_test.go Show resolved Hide resolved
website/docs/r/nocode_module.html.markdown Outdated Show resolved Hide resolved
website/docs/r/nocode_module.html.markdown Outdated Show resolved Hide resolved
website/docs/r/registry_module.html.markdown Outdated Show resolved Hide resolved
organization = tfe_organization.test-organization.name
namespace = "terraform-aws-modules"
module_provider = "aws"
name = "vpc"
registry_name = "public"
no_code = true
}

resource "tfe_nocode_module" "foobar" {
Copy link
Contributor

Choose a reason for hiding this comment

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

this doc is for the tfe_registry_module, the "tfe_nocode_module" resource example should go into it's own doc, is there a reason for adding it here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Creating an entirely new no-code registry module is a combination of the no-code module and registry module resource.

website/docs/r/registry_module.html.markdown Show resolved Hide resolved
@dsa0x dsa0x force-pushed the sams/no-code-var-opts branch 2 times, most recently from a78bd38 to 7c52ad1 Compare April 11, 2023 13:29
@dsa0x dsa0x requested a review from MiniHeyd April 12, 2023 14:15
@dsa0x dsa0x changed the title CRUD support for no-code registry modules [BETA] CRUD support for no-code registry modules Apr 12, 2023
@dsa0x dsa0x requested a review from Uk1288 April 12, 2023 16:17
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.

Very nice! I couldn't break it during smoke testing.

tfe/resource_tfe_no_code_module.go Outdated Show resolved Hide resolved
tfe/resource_tfe_no_code_module.go Outdated Show resolved Hide resolved
tfe/resource_tfe_registry_module.go Show resolved Hide resolved
@dsa0x dsa0x requested a review from brandonc April 17, 2023 16:43
Copy link
Member

@nfagerlund nfagerlund left a comment

Choose a reason for hiding this comment

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

OK, it looks like you've addressed the review feedback, and Brandon already manually tested the feature and thought it worked well.

The one bit of feedback I see remaining is whether you wanted to use the built-in schema deprecation feature rather than hand-rolling one with GetOk(). But I'm OK either way! It also looks like you'll need to resolve a go.mod conflict, so ping me when you're ready for re-approval and I'll fast-track it.

@dsa0x dsa0x dismissed brandonc’s stale review April 19, 2023 07:16

addressed review

@dsa0x dsa0x merged commit 76bdd46 into main Apr 19, 2023
@dsa0x dsa0x deleted the sams/no-code-var-opts branch April 19, 2023 08:40
@dsa0x
Copy link
Contributor Author

dsa0x commented Apr 19, 2023

Thanks @nfagerlund . Looking forward to the next release

@lucymhdavies
Copy link
Contributor

lucymhdavies commented Apr 20, 2023

Docs reference module, but the actual argument is registry_module

$ terraform apply
╷
│ Error: Missing required argument
│
│   on registry.tf line 82, in resource "tfe_no_code_module" "foobar":
│   82: resource "tfe_no_code_module" "foobar" {
│
│ The argument "registry_module" is required, but no definition was found.
╵
╷
│ Error: Unsupported argument
│
│   on registry.tf line 85, in resource "tfe_no_code_module" "foobar":
│   85:   module = tfe_registry_module.private-nocode-modules[each.key].id
│
│ An argument named "module" is not expected here.

I'll get a PR to fix the docs :)

Edit: Looks like y'all are already on this :D
#858

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.

None yet

5 participants