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 support for both public and private module creation without VCS #460

Merged
merged 4 commits into from Jul 20, 2022

Conversation

Uk1288
Copy link
Contributor

@Uk1288 Uk1288 commented Jul 11, 2022

Description

Currently, private registry modules are created with an option containing: Name and Provider.
This PR adds the ability to create both public/private registry modules without VCS with options containing: Name, Provider, RegistryName and Namespace.

The existing behaviour of creating a private module by specifying just the Name and Provider still works.

Testing plan

External links

  • Related PR This PR must be merged and released before the related PR is merged

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.

$ TFE_ADDRESS="https://example" TFE_TOKEN="example" TF_ACC="1" go test ./... -v -tags=integration -run TestRegistryModulesCreate

=== RUN   TestRegistryModulesCreate
=== RUN   TestRegistryModulesCreate/with_valid_options
=== RUN   TestRegistryModulesCreate/with_valid_options/without_RegistryName
=== RUN   TestRegistryModulesCreate/with_valid_options/without_RegistryName/permissions_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/without_RegistryName/relationships_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/without_RegistryName/timestamps_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/with_private_RegistryName
=== RUN   TestRegistryModulesCreate/with_valid_options/with_private_RegistryName/permissions_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/with_private_RegistryName/relationships_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/with_private_RegistryName/timestamps_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/with_public_RegistryName
=== RUN   TestRegistryModulesCreate/with_valid_options/with_public_RegistryName/permissions_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/with_public_RegistryName/relationships_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_valid_options/with_public_RegistryName/timestamps_are_properly_decoded
=== RUN   TestRegistryModulesCreate/with_invalid_options
=== RUN   TestRegistryModulesCreate/with_invalid_options/without_a_name
=== RUN   TestRegistryModulesCreate/with_invalid_options/with_an_invalid_name
=== RUN   TestRegistryModulesCreate/with_invalid_options/without_a_provider
=== RUN   TestRegistryModulesCreate/with_invalid_options/with_an_invalid_provider
=== RUN   TestRegistryModulesCreate/with_invalid_options/with_an_invalid_registry_name
=== RUN   TestRegistryModulesCreate/with_invalid_options/without_a_namespace_for_public_registry_name
=== RUN   TestRegistryModulesCreate/with_invalid_options/with_a_namespace_for_private_registry_name
=== RUN   TestRegistryModulesCreate/without_a_valid_organization
--- PASS: TestRegistryModulesCreate (1.21s)
    --- PASS: TestRegistryModulesCreate/with_valid_options (0.44s)
        --- PASS: TestRegistryModulesCreate/with_valid_options/without_RegistryName (0.13s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/without_RegistryName/permissions_are_properly_decoded (0.00s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/without_RegistryName/relationships_are_properly_decoded (0.00s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/without_RegistryName/timestamps_are_properly_decoded (0.00s)
        --- PASS: TestRegistryModulesCreate/with_valid_options/with_private_RegistryName (0.13s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/with_private_RegistryName/permissions_are_properly_decoded (0.00s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/with_private_RegistryName/relationships_are_properly_decoded (0.00s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/with_private_RegistryName/timestamps_are_properly_decoded (0.00s)
        --- PASS: TestRegistryModulesCreate/with_valid_options/with_public_RegistryName (0.18s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/with_public_RegistryName/permissions_are_properly_decoded (0.00s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/with_public_RegistryName/relationships_are_properly_decoded (0.00s)
            --- PASS: TestRegistryModulesCreate/with_valid_options/with_public_RegistryName/timestamps_are_properly_decoded (0.00s)
    --- PASS: TestRegistryModulesCreate/with_invalid_options (0.00s)
        --- PASS: TestRegistryModulesCreate/with_invalid_options/without_a_name (0.00s)
        --- PASS: TestRegistryModulesCreate/with_invalid_options/with_an_invalid_name (0.00s)
        --- PASS: TestRegistryModulesCreate/with_invalid_options/without_a_provider (0.00s)
        --- PASS: TestRegistryModulesCreate/with_invalid_options/with_an_invalid_provider (0.00s)
        --- PASS: TestRegistryModulesCreate/with_invalid_options/with_an_invalid_registry_name (0.00s)
        --- PASS: TestRegistryModulesCreate/with_invalid_options/without_a_namespace_for_public_registry_name (0.00s)
        --- PASS: TestRegistryModulesCreate/with_invalid_options/with_a_namespace_for_private_registry_name (0.00s)
    --- PASS: TestRegistryModulesCreate/without_a_valid_organization (0.00s)

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.

Overall code looks 🔥 Some things down below ⬇️

Provider: String("provider"),
assertRegistryModuleAttributes := func(t *testing.T, registryModule *RegistryModule) {
t.Run("permissions are properly decoded", func(t *testing.T) {
assert.True(t, registryModule.Permissions.CanDelete)
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll want to require Permissions to not be nil, otherwise this will panic if Permissions was not decoded properly.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if my changes in #458 will be overwritten somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I will fix the conflicts once you merge the changes.

})

t.Run("relationships are properly decoded", func(t *testing.T) {
assert.Equal(t, orgTest.Name, registryModule.Organization.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here for Organization

@@ -436,6 +443,22 @@ func (o RegistryModuleCreateOptions) valid() error {
if !validStringID(o.Provider) {
return ErrInvalidProvider
}

// RegistryName is optional, only validate if specified
if validString((*string)(&o.RegistryName)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[For discussion] We can potentially simplify this logic:

We don't need to check if RegistryName is a valid string as there are only two possible values we would care about:

switch(&o.RegistryName) {
case PublicRegistry:
  if !validString(&o.Namespace) { 
    // return error 
  }
case PrivateRegistry:
  if validString(&o.Namespace) { 
    // return other error 
  }
// for all other strings or nil:
default:
  return ErrInvalidRegistryName
}

@Uk1288 Uk1288 force-pushed the uk1288-support-public-modules branch from bf74088 to 59db300 Compare July 14, 2022 13:41
@Uk1288 Uk1288 force-pushed the uk1288-support-public-modules branch from 2cfb379 to a8e68ec Compare July 15, 2022 13:18
@Uk1288 Uk1288 requested a review from a team as a code owner July 18, 2022 17:32
@Uk1288 Uk1288 force-pushed the uk1288-support-public-modules branch from 357e7af to 9b83a37 Compare July 18, 2022 17:36
brandonc
brandonc previously approved these changes Jul 18, 2022
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.

woop

CHANGELOG.md Outdated Show resolved Hide resolved
brandonc
brandonc previously approved these changes Jul 19, 2022
@Uk1288 Uk1288 merged commit 392b639 into main Jul 20, 2022
@Uk1288 Uk1288 deleted the uk1288-support-public-modules branch July 20, 2022 18:25
@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

3 participants