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

no code provisioning in registry modules #562

Merged
merged 13 commits into from Nov 15, 2022

Conversation

miguelhrocha
Copy link
Contributor

@miguelhrocha miguelhrocha commented Oct 25, 2022

Description

This change aligns with the next release of TFE which will include no-code modules provisioning introduced on TFC during the last HashiConf.

The way to create these modules is to either enable this property at the time of creation or with the newly introduce update operation.

Testing plan

Using integration tests

  1. go test -run TestRegistryModulesCreate/with_valid_options/with_no-code_attribute -v ./... -tags=integration
  2. go test -run TestRegistryModuleUpdate -v ./... -tags=integration

Using TFE instance

  1. Flip the no_code feature on the TFE configuration
func main() {
	ctx := context.Background()
	cfg := &tfe.Config{
		Address:           "https://your-tfe-local-address",
		Token:             "API_TOKEN",
		RetryServerErrors: true,
	}

	client, _ := tfe.NewClient(cfg)

	org := "YOUR_ORG_NAME"
	opts := tfe.RegistryModuleCreateOptions{
		Name:         tfe.String("iam"),
		Provider:     tfe.String("aws"),
		NoCode:       true,
		RegistryName: tfe.PrivateRegistry,
		Namespace:    "terraform-aws-modules",
	}
	client.RegistryModules.Create(ctx, org, opts)
}

External links

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

Update endpoint changes

$ envchain go-tfe go test -run TestRegistryModuleUpdate -v ./... -tags=integration
=== RUN   TestRegistryModuleUpdate
=== RUN   TestRegistryModuleUpdate/enable_no-code
=== RUN   TestRegistryModuleUpdate/disable_no-code
--- PASS: TestRegistryModuleUpdate (5.34s)
    --- PASS: TestRegistryModuleUpdate/enable_no-code (0.42s)
    --- PASS: TestRegistryModuleUpdate/disable_no-code (0.35s)
PASS
ok  	github.com/hashicorp/go-tfe	5.511s
?   	github.com/hashicorp/go-tfe/examples/organizations	[no test files]
?   	github.com/hashicorp/go-tfe/examples/workspaces	[no test files]
?   	github.com/hashicorp/go-tfe/mocks	[no test files]
?   	github.com/hashicorp/go-tfe/test	[no test files]

Create endpoint changes

$ envchain go-tfe go test -run TestRegistryModulesCreate/with_valid_options/with_no-code_attribute -v ./... -tags=integration
=== RUN   TestRegistryModulesCreate
=== RUN   TestRegistryModulesCreate/with_valid_options
=== RUN   TestRegistryModulesCreate/with_valid_options/with_no-code_attribute
=== RUN   TestRegistryModulesCreate/with_valid_options/with_no-code_attribute/permissions_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/with_no-code_attribute/relationships_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/with_no-code_attribute/timestamps_are_properly_decoded
--- PASS: TestRegistryModulesCreate (1.88s)
    --- PASS: TestRegistryModulesCreate/with_valid_options (0.37s)
        --- PASS: TestRegistryModulesCreate/with_valid_options/with_no-code_attribute (0.37s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/with_no-code_attribute/permissions_are_properly_decoded (0.00s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/with_no-code_attribute/relationships_are_properly_decoded (0.00s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/with_no-code_attribute/timestamps_are_properly_decoded (0.00s)
=== RUN   TestRegistryModulesCreateVersion
=== RUN   TestRegistryModulesCreateVersion/with_valid_options
--- PASS: TestRegistryModulesCreateVersion (2.49s)
    --- PASS: TestRegistryModulesCreateVersion/with_valid_options (0.38s)
=== RUN   TestRegistryModulesCreateWithVCSConnection
    registry_module_integration_test.go:443: Export a valid GITHUB_REGISTRY_MODULE_IDENTIFIER before running this test
--- SKIP: TestRegistryModulesCreateWithVCSConnection (0.00s)
PASS
ok  	github.com/hashicorp/go-tfe	5.348s
?   	github.com/hashicorp/go-tfe/examples/organizations	[no test files]
?   	github.com/hashicorp/go-tfe/examples/workspaces	[no test files]
?   	github.com/hashicorp/go-tfe/mocks	[no test files]
?   	github.com/hashicorp/go-tfe/test	[no test files]

@miguelhrocha miguelhrocha marked this pull request as ready for review October 26, 2022 10:34
@miguelhrocha miguelhrocha requested a review from a team as a code owner October 26, 2022 10:34
@annawinkler annawinkler changed the title no code provisiniong in registry modules no code provisioning in registry modules Oct 31, 2022
registry_module.go Outdated Show resolved Hide resolved
Co-authored-by: UKEME BASSEY <ukeme.bassey@hashicorp.com>
Uk1288
Uk1288 previously approved these changes Nov 3, 2022
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!

Copy link
Contributor

@annawinkler annawinkler left a comment

Choose a reason for hiding this comment

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

Hi @miguelhrocha - thank you for your PR! 🥳 Could you please add a changelog entry for this update? We have contributing guidelines here that might be helpful. Thanks!

@miguelhrocha
Copy link
Contributor Author

Thanks for reaching out @annawinkler ! Sorry for missing this, I've updated the PR b1e5d0c 👍🏼

@annawinkler
Copy link
Contributor

Hi @miguelhrocha - when I tested with the example you included in the PR description, I saw this error:

"Namespace" cannot be populated when "RegistryName" is "private"

Based on what I'm reading in the docs, I would still expect this error, so in my test, I changed: RegistryName: tfe.PublicRegistry.

namespace := url.QueryEscape(moduleID.Namespace)
name := url.QueryEscape(moduleID.Name)
provider := url.QueryEscape(moduleID.Provider)
url := fmt.Sprintf("organizations/%s/registry-modules/%s/%s/%s/%s", org, registryName, namespace, name, provider)
Copy link
Contributor

Choose a reason for hiding this comment

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

💅 A small style suggestion - in this file (& the rest of the code), we generally avoid creating variables for each URL element like on this line.

Copy link
Contributor

@annawinkler annawinkler left a comment

Choose a reason for hiding this comment

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

I think we're almost there - I left a few more suggestions.

@annawinkler annawinkler dismissed their stale review November 8, 2022 23:16

I'll be out and I don't want to block this PR. I think it's close!

@annawinkler
Copy link
Contributor

🥳 I tested locally with a local tfc, and verified that if I create one Registry Module with no code = true, and one with no code = false, when I look at the API scope RegistryModule.no_code_allowed_for_org the correct objects are returned.

@annawinkler
Copy link
Contributor

💅 One final request - please squash merge the commits into one commit. Thanks!

sebasslash
sebasslash previously approved these changes Nov 10, 2022
Copy link
Contributor

@sebasslash sebasslash left a comment

Choose a reason for hiding this comment

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

The code here looks great 🚀 . There is one minor non-blocking comment below ⬇️

I may even go so far as to say if you can squash your 10 commits to 3 (if possible): one for your implementation, one for your tests, and one for your changelog/housekeeping changes. You don't have to follow this structure but it helps keep our history clean 😄

registry_module.go Outdated Show resolved Hide resolved
@miguelhrocha
Copy link
Contributor Author

Hi @sebasslash !

Thanks for reviewing my code 😄 I had to resolve some conflicts so I implemented your proposal. I will use the merge squash functionality from GitHub 👍🏼

Copy link
Contributor

@sebasslash sebasslash left a comment

Choose a reason for hiding this comment

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

Changes look good! 🚀 Feel free to merge when you're ready 👍

@miguelhrocha miguelhrocha merged commit 6dcc99c into main Nov 15, 2022
@miguelhrocha miguelhrocha deleted the miguelhrocha/no-code-modules branch November 15, 2022 11:58
@github-actions
Copy link

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

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

4 participants