From 414b6c9813e794a6001dcd2eec177bb40cd18d27 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Wed, 10 Jan 2024 07:03:08 -0600 Subject: [PATCH] Feat: support tagPrefix on modules (#776) --- client/module.go | 3 +++ env0/resource_module.go | 5 +++++ env0/resource_module_test.go | 14 ++++++++++++++ tests/integration/018_module/main.tf | 1 + 4 files changed, 23 insertions(+) diff --git a/client/module.go b/client/module.go index c2170b82..265c114b 100644 --- a/client/module.go +++ b/client/module.go @@ -26,6 +26,7 @@ type Module struct { UpdatedAt string `json:"updatedAt"` IsDeleted bool `json:"isDeleted"` Path string `json:"path"` + TagPrefix string `json:"tagPrefix"` } type ModuleCreatePayload struct { @@ -41,6 +42,7 @@ type ModuleCreatePayload struct { IsGitlab *bool `json:"isGitLab,omitempty"` SshKeys []ModuleSshKey `json:"sshkeys,omitempty"` Path string `json:"path,omitempty"` + TagPrefix string `json:"tagPrefix,omitempty"` } type ModuleCreatePayloadWith struct { @@ -62,6 +64,7 @@ type ModuleUpdatePayload struct { IsGitlab bool `json:"isGitLab"` SshKeys []ModuleSshKey `json:"sshkeys"` Path string `json:"path"` + TagPrefix string `json:"tagPrefix,omitempty"` } func (client *ApiClient) ModuleCreate(payload ModuleCreatePayload) (*Module, error) { diff --git a/env0/resource_module.go b/env0/resource_module.go index b2752d0c..4efdc881 100644 --- a/env0/resource_module.go +++ b/env0/resource_module.go @@ -87,6 +87,11 @@ func resourceModule() *schema.Resource { Description: "the folder in the repository to create the module from", Optional: true, }, + "tag_prefix": { + Type: schema.TypeString, + Description: "a tag prefix for the module", + Optional: true, + }, }, } } diff --git a/env0/resource_module_test.go b/env0/resource_module_test.go index 9b14e241..c4b0d4e9 100644 --- a/env0/resource_module_test.go +++ b/env0/resource_module_test.go @@ -34,6 +34,7 @@ func TestUnitModuleResource(t *testing.T) { AuthorId: "author1", Id: uuid.NewString(), Path: "path1", + TagPrefix: "prefix1", } updatedModule := client.Module{ @@ -47,6 +48,7 @@ func TestUnitModuleResource(t *testing.T) { AuthorId: "author1", Id: module.Id, Path: "path2", + TagPrefix: "prefix2", } t.Run("Success", func(t *testing.T) { @@ -61,6 +63,7 @@ func TestUnitModuleResource(t *testing.T) { "token_id": module.TokenId, "token_name": module.TokenName, "path": module.Path, + "tag_prefix": module.TagPrefix, }), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(accessor, "id", module.Id), @@ -71,6 +74,7 @@ func TestUnitModuleResource(t *testing.T) { resource.TestCheckResourceAttr(accessor, "token_id", module.TokenId), resource.TestCheckResourceAttr(accessor, "token_name", module.TokenName), resource.TestCheckResourceAttr(accessor, "path", module.Path), + resource.TestCheckResourceAttr(accessor, "tag_prefix", module.TagPrefix), ), }, { @@ -81,6 +85,7 @@ func TestUnitModuleResource(t *testing.T) { "description": updatedModule.Description, "bitbucket_client_key": *updatedModule.BitbucketClientKey, "path": updatedModule.Path, + "tag_prefix": updatedModule.TagPrefix, }), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(accessor, "id", updatedModule.Id), @@ -92,6 +97,7 @@ func TestUnitModuleResource(t *testing.T) { resource.TestCheckResourceAttr(accessor, "token_name", ""), resource.TestCheckResourceAttr(accessor, "bitbucket_client_key", *updatedModule.BitbucketClientKey), resource.TestCheckResourceAttr(accessor, "path", updatedModule.Path), + resource.TestCheckResourceAttr(accessor, "tag_prefix", updatedModule.TagPrefix), ), }, }, @@ -106,6 +112,7 @@ func TestUnitModuleResource(t *testing.T) { TokenId: module.TokenId, TokenName: module.TokenName, Path: module.Path, + TagPrefix: module.TagPrefix, }).Times(1).Return(&module, nil) mock.EXPECT().ModuleUpdate(updatedModule.Id, client.ModuleUpdatePayload{ @@ -119,6 +126,7 @@ func TestUnitModuleResource(t *testing.T) { GithubInstallationId: nil, BitbucketClientKey: *updatedModule.BitbucketClientKey, Path: updatedModule.Path, + TagPrefix: updatedModule.TagPrefix, }).Times(1).Return(&updatedModule, nil) gomock.InOrder( @@ -211,6 +219,7 @@ func TestUnitModuleResource(t *testing.T) { "token_id": module.TokenId, "token_name": module.TokenName, "path": module.Path, + "tag_prefix": module.TagPrefix, }), }, { @@ -236,6 +245,7 @@ func TestUnitModuleResource(t *testing.T) { TokenId: module.TokenId, TokenName: module.TokenName, Path: module.Path, + TagPrefix: module.TagPrefix, }).Times(1).Return(&module, nil) mock.EXPECT().ModuleUpdate(updatedModule.Id, client.ModuleUpdatePayload{ @@ -268,6 +278,7 @@ func TestUnitModuleResource(t *testing.T) { "token_id": module.TokenId, "token_name": module.TokenName, "path": module.Path, + "tag_prefix": module.TagPrefix, }), }, { @@ -288,6 +299,7 @@ func TestUnitModuleResource(t *testing.T) { TokenId: module.TokenId, TokenName: module.TokenName, Path: module.Path, + TagPrefix: module.TagPrefix, }).Times(1).Return(&module, nil) mock.EXPECT().Modules().Times(1).Return([]client.Module{module}, nil) mock.EXPECT().Module(module.Id).Times(2).Return(&module, nil) @@ -307,6 +319,7 @@ func TestUnitModuleResource(t *testing.T) { "token_id": module.TokenId, "token_name": module.TokenName, "path": module.Path, + "tag_prefix": module.TagPrefix, }), }, { @@ -327,6 +340,7 @@ func TestUnitModuleResource(t *testing.T) { TokenId: module.TokenId, TokenName: module.TokenName, Path: module.Path, + TagPrefix: module.TagPrefix, }).Times(1).Return(&module, nil) mock.EXPECT().Module(module.Id).Times(3).Return(&module, nil) mock.EXPECT().ModuleDelete(module.Id).Times(1) diff --git a/tests/integration/018_module/main.tf b/tests/integration/018_module/main.tf index 69e9fe43..ac55fbdb 100644 --- a/tests/integration/018_module/main.tf +++ b/tests/integration/018_module/main.tf @@ -14,4 +14,5 @@ resource "env0_module" "test_module" { repository = "https://gitlab.com/moooo/moooo-docs-aws-functions.git" github_installation_id = var.second_run ? 32112 : null path = var.second_run ? "/cool1" : "/cool2" + tag_prefix = var.second_run ? "t2" : "t1" }