Skip to content

Commit

Permalink
Feat: support tagPrefix on modules (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Jan 10, 2024
1 parent 18cfc5c commit 414b6c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions env0/resource_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
}
Expand Down
14 changes: 14 additions & 0 deletions env0/resource_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestUnitModuleResource(t *testing.T) {
AuthorId: "author1",
Id: uuid.NewString(),
Path: "path1",
TagPrefix: "prefix1",
}

updatedModule := client.Module{
Expand All @@ -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) {
Expand All @@ -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),
Expand All @@ -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),
),
},
{
Expand All @@ -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),
Expand All @@ -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),
),
},
},
Expand All @@ -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{
Expand All @@ -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(
Expand Down Expand Up @@ -211,6 +219,7 @@ func TestUnitModuleResource(t *testing.T) {
"token_id": module.TokenId,
"token_name": module.TokenName,
"path": module.Path,
"tag_prefix": module.TagPrefix,
}),
},
{
Expand All @@ -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{
Expand Down Expand Up @@ -268,6 +278,7 @@ func TestUnitModuleResource(t *testing.T) {
"token_id": module.TokenId,
"token_name": module.TokenName,
"path": module.Path,
"tag_prefix": module.TagPrefix,
}),
},
{
Expand All @@ -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)
Expand All @@ -307,6 +319,7 @@ func TestUnitModuleResource(t *testing.T) {
"token_id": module.TokenId,
"token_name": module.TokenName,
"path": module.Path,
"tag_prefix": module.TagPrefix,
}),
},
{
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/integration/018_module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 414b6c9

Please sign in to comment.