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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e142f48
Modify codeowners to have wildcard access, removed duplicate CODEOWNE…
sebasslash 4350dd8
add support for both public and private module creation without VCS
Uk1288 599ef7c
update changelog
Uk1288 ddfffc7
Merge branch 'main' into uk1288-support-public-modules
Uk1288 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,9 @@ func TestRegistryModulesList(t *testing.T) { | |
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
|
||
registryModuleTest1, registryModuleTest1Cleanup := createRegistryModule(t, client, orgTest) | ||
registryModuleTest1, registryModuleTest1Cleanup := createRegistryModule(t, client, orgTest, PrivateRegistry) | ||
defer registryModuleTest1Cleanup() | ||
registryModuleTest2, registryModuleTest2Cleanup := createRegistryModule(t, client, orgTest) | ||
registryModuleTest2, registryModuleTest2Cleanup := createRegistryModule(t, client, orgTest, PrivateRegistry) | ||
defer registryModuleTest2Cleanup() | ||
|
||
t.Run("with no list options", func(t *testing.T) { | ||
|
@@ -71,29 +71,74 @@ func TestRegistryModulesCreate(t *testing.T) { | |
defer orgTestCleanup() | ||
|
||
t.Run("with valid options", func(t *testing.T) { | ||
options := RegistryModuleCreateOptions{ | ||
Name: String("name"), | ||
Provider: String("provider"), | ||
assertRegistryModuleAttributes := func(t *testing.T, registryModule *RegistryModule) { | ||
t.Run("permissions are properly decoded", func(t *testing.T) { | ||
require.NotEmpty(t, registryModule.Permissions) | ||
assert.True(t, registryModule.Permissions.CanDelete) | ||
assert.True(t, registryModule.Permissions.CanResync) | ||
assert.True(t, registryModule.Permissions.CanRetry) | ||
}) | ||
|
||
t.Run("relationships are properly decoded", func(t *testing.T) { | ||
require.NotEmpty(t, registryModule.Organization) | ||
assert.Equal(t, orgTest.Name, registryModule.Organization.Name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for |
||
}) | ||
|
||
t.Run("timestamps are properly decoded", func(t *testing.T) { | ||
assert.NotEmpty(t, registryModule.CreatedAt) | ||
assert.NotEmpty(t, registryModule.UpdatedAt) | ||
}) | ||
} | ||
rm, err := client.RegistryModules.Create(ctx, orgTest.Name, options) | ||
require.NoError(t, err) | ||
assert.NotEmpty(t, rm.ID) | ||
assert.Equal(t, *options.Name, rm.Name) | ||
assert.Equal(t, *options.Provider, rm.Provider) | ||
|
||
t.Run("permissions are properly decoded", func(t *testing.T) { | ||
assert.True(t, rm.Permissions.CanDelete) | ||
assert.True(t, rm.Permissions.CanResync) | ||
assert.True(t, rm.Permissions.CanRetry) | ||
t.Run("without RegistryName", func(t *testing.T) { | ||
options := RegistryModuleCreateOptions{ | ||
Name: String("name"), | ||
Provider: String("provider"), | ||
} | ||
rm, err := client.RegistryModules.Create(ctx, orgTest.Name, options) | ||
require.NoError(t, err) | ||
assert.NotEmpty(t, rm.ID) | ||
assert.Equal(t, *options.Name, rm.Name) | ||
assert.Equal(t, *options.Provider, rm.Provider) | ||
assert.Equal(t, PrivateRegistry, rm.RegistryName) | ||
assert.Equal(t, orgTest.Name, rm.Namespace) | ||
|
||
assertRegistryModuleAttributes(t, rm) | ||
}) | ||
|
||
t.Run("relationships are properly decoded", func(t *testing.T) { | ||
assert.Equal(t, orgTest.Name, rm.Organization.Name) | ||
t.Run("with private RegistryName", func(t *testing.T) { | ||
options := RegistryModuleCreateOptions{ | ||
Name: String("another_name"), | ||
Provider: String("provider"), | ||
RegistryName: PrivateRegistry, | ||
} | ||
rm, err := client.RegistryModules.Create(ctx, orgTest.Name, options) | ||
require.NoError(t, err) | ||
assert.NotEmpty(t, rm.ID) | ||
assert.Equal(t, *options.Name, rm.Name) | ||
assert.Equal(t, *options.Provider, rm.Provider) | ||
assert.Equal(t, options.RegistryName, rm.RegistryName) | ||
assert.Equal(t, orgTest.Name, rm.Namespace) | ||
|
||
assertRegistryModuleAttributes(t, rm) | ||
}) | ||
|
||
t.Run("timestamps are properly decoded", func(t *testing.T) { | ||
assert.NotEmpty(t, rm.CreatedAt) | ||
assert.NotEmpty(t, rm.UpdatedAt) | ||
t.Run("with public RegistryName", func(t *testing.T) { | ||
options := RegistryModuleCreateOptions{ | ||
Name: String("vpc"), | ||
Provider: String("aws"), | ||
RegistryName: PublicRegistry, | ||
Namespace: "terraform-aws-modules", | ||
} | ||
rm, err := client.RegistryModules.Create(ctx, orgTest.Name, options) | ||
require.NoError(t, err) | ||
assert.NotEmpty(t, rm.ID) | ||
assert.Equal(t, *options.Name, rm.Name) | ||
assert.Equal(t, *options.Provider, rm.Provider) | ||
assert.Equal(t, options.RegistryName, rm.RegistryName) | ||
assert.Equal(t, options.Namespace, rm.Namespace) | ||
|
||
assertRegistryModuleAttributes(t, rm) | ||
}) | ||
}) | ||
|
||
|
@@ -135,6 +180,40 @@ func TestRegistryModulesCreate(t *testing.T) { | |
assert.Nil(t, rm) | ||
assert.Equal(t, err, ErrInvalidProvider) | ||
}) | ||
|
||
t.Run("with an invalid registry name", func(t *testing.T) { | ||
options := RegistryModuleCreateOptions{ | ||
Name: String("name"), | ||
Provider: String("provider"), | ||
RegistryName: "PRIVATE", | ||
} | ||
rm, err := client.RegistryModules.Create(ctx, orgTest.Name, options) | ||
assert.Nil(t, rm) | ||
assert.Equal(t, err, ErrInvalidRegistryName) | ||
}) | ||
|
||
t.Run("without a namespace for public registry name", func(t *testing.T) { | ||
options := RegistryModuleCreateOptions{ | ||
Name: String("name"), | ||
Provider: String("provider"), | ||
RegistryName: PublicRegistry, | ||
} | ||
rm, err := client.RegistryModules.Create(ctx, orgTest.Name, options) | ||
assert.Nil(t, rm) | ||
assert.Equal(t, err, ErrRequiredNamespace) | ||
}) | ||
|
||
t.Run("with a namespace for private registry name", func(t *testing.T) { | ||
options := RegistryModuleCreateOptions{ | ||
Name: String("name"), | ||
Provider: String("provider"), | ||
RegistryName: PrivateRegistry, | ||
Namespace: "namespace", | ||
} | ||
rm, err := client.RegistryModules.Create(ctx, orgTest.Name, options) | ||
assert.Nil(t, rm) | ||
assert.Equal(t, err, ErrUnsupportedBothNamespaceAndPrivateRegistryName) | ||
}) | ||
}) | ||
|
||
t.Run("without a valid organization", func(t *testing.T) { | ||
|
@@ -155,7 +234,7 @@ func TestRegistryModulesCreateVersion(t *testing.T) { | |
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
|
||
registryModuleTest, registryModuleTestCleanup := createRegistryModule(t, client, orgTest) | ||
registryModuleTest, registryModuleTestCleanup := createRegistryModule(t, client, orgTest, PrivateRegistry) | ||
defer registryModuleTestCleanup() | ||
|
||
t.Run("with valid options", func(t *testing.T) { | ||
|
@@ -393,9 +472,12 @@ func TestRegistryModulesRead(t *testing.T) { | |
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
|
||
registryModuleTest, registryModuleTestCleanup := createRegistryModule(t, client, orgTest) | ||
registryModuleTest, registryModuleTestCleanup := createRegistryModule(t, client, orgTest, PrivateRegistry) | ||
defer registryModuleTestCleanup() | ||
|
||
publicRegistryModuleTest, publicRegistryModuleTestCleanup := createRegistryModule(t, client, orgTest, PublicRegistry) | ||
defer publicRegistryModuleTestCleanup() | ||
|
||
t.Run("with valid name and provider", func(t *testing.T) { | ||
rm, err := client.RegistryModules.Read(ctx, RegistryModuleID{ | ||
Organization: orgTest.Name, | ||
|
@@ -417,7 +499,7 @@ func TestRegistryModulesRead(t *testing.T) { | |
}) | ||
}) | ||
|
||
t.Run("with complete registry module ID fields", func(t *testing.T) { | ||
t.Run("with complete registry module ID fields for private module", func(t *testing.T) { | ||
rm, err := client.RegistryModules.Read(ctx, RegistryModuleID{ | ||
Organization: orgTest.Name, | ||
Name: registryModuleTest.Name, | ||
|
@@ -442,6 +524,31 @@ func TestRegistryModulesRead(t *testing.T) { | |
}) | ||
}) | ||
|
||
t.Run("with complete registry module ID fields for public module", func(t *testing.T) { | ||
rm, err := client.RegistryModules.Read(ctx, RegistryModuleID{ | ||
Organization: orgTest.Name, | ||
Name: publicRegistryModuleTest.Name, | ||
Provider: publicRegistryModuleTest.Provider, | ||
Namespace: publicRegistryModuleTest.Namespace, | ||
RegistryName: PublicRegistry, | ||
}) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, rm) | ||
assert.Equal(t, publicRegistryModuleTest.ID, rm.ID) | ||
|
||
t.Run("permissions are properly decoded", func(t *testing.T) { | ||
require.NotEmpty(t, rm.Permissions) | ||
assert.True(t, rm.Permissions.CanDelete) | ||
assert.True(t, rm.Permissions.CanResync) | ||
assert.True(t, rm.Permissions.CanRetry) | ||
}) | ||
|
||
t.Run("timestamps are properly decoded", func(t *testing.T) { | ||
assert.NotEmpty(t, rm.CreatedAt) | ||
assert.NotEmpty(t, rm.UpdatedAt) | ||
}) | ||
}) | ||
|
||
t.Run("without a name", func(t *testing.T) { | ||
rm, err := client.RegistryModules.Read(ctx, RegistryModuleID{ | ||
Organization: orgTest.Name, | ||
|
@@ -504,6 +611,17 @@ func TestRegistryModulesRead(t *testing.T) { | |
assert.EqualError(t, err, ErrInvalidOrg.Error()) | ||
}) | ||
|
||
t.Run("without a valid namespace for public registry module", func(t *testing.T) { | ||
rm, err := client.RegistryModules.Read(ctx, RegistryModuleID{ | ||
Organization: orgTest.Name, | ||
Name: publicRegistryModuleTest.Name, | ||
Provider: publicRegistryModuleTest.Provider, | ||
RegistryName: PublicRegistry, | ||
}) | ||
assert.Nil(t, rm) | ||
assert.EqualError(t, err, ErrRequiredNamespace.Error()) | ||
}) | ||
|
||
t.Run("when the registry module does not exist", func(t *testing.T) { | ||
rm, err := client.RegistryModules.Read(ctx, RegistryModuleID{ | ||
Organization: orgTest.Name, | ||
|
@@ -522,7 +640,7 @@ func TestRegistryModulesDelete(t *testing.T) { | |
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
|
||
registryModuleTest, _ := createRegistryModule(t, client, orgTest) | ||
registryModuleTest, _ := createRegistryModule(t, client, orgTest, PrivateRegistry) | ||
|
||
t.Run("with valid name", func(t *testing.T) { | ||
err := client.RegistryModules.Delete(ctx, orgTest.Name, registryModuleTest.Name) | ||
|
@@ -566,7 +684,7 @@ func TestRegistryModulesDeleteProvider(t *testing.T) { | |
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
|
||
registryModuleTest, _ := createRegistryModule(t, client, orgTest) | ||
registryModuleTest, _ := createRegistryModule(t, client, orgTest, PrivateRegistry) | ||
|
||
t.Run("with valid name and provider", func(t *testing.T) { | ||
err := client.RegistryModules.DeleteProvider(ctx, RegistryModuleID{ | ||
|
@@ -771,7 +889,7 @@ func TestRegistryModulesUpload(t *testing.T) { | |
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
|
||
rm, _ := createRegistryModule(t, client, orgTest) | ||
rm, _ := createRegistryModule(t, client, orgTest, PrivateRegistry) | ||
|
||
optionsModuleVersion := RegistryModuleCreateVersionOptions{ | ||
Version: String("1.0.0"), | ||
|
@@ -873,7 +991,7 @@ func TestRegistryModule_Unmarshal(t *testing.T) { | |
assert.Equal(t, rm.VersionStatuses[0].Error, "no error") | ||
} | ||
|
||
func TestRegistryCreateOptions_Marshal(t *testing.T) { | ||
func TestRegistryCreateWithVCSOptions_Marshal(t *testing.T) { | ||
// https://www.terraform.io/docs/cloud/api/modules.html#sample-payload | ||
opts := RegistryModuleCreateWithVCSConnectionOptions{ | ||
VCSRepo: &RegistryModuleVCSRepoOptions{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 benil
, otherwise this will panic ifPermissions
was not decoded properly.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.