Skip to content

Commit 47c4816

Browse files
committed
Feat: remove default template type
1 parent d658cfa commit 47c4816

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

env0/resource_template.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ func getTemplateSchema(prefix string) map[string]*schema.Schema {
103103
"type": {
104104
Type: schema.TypeString,
105105
Description: fmt.Sprintf("template type (allowed values: %s)", strings.Join(allowedTemplateTypes, ", ")),
106-
Optional: true,
107-
Default: client.OPENTOFU,
106+
Required: true,
108107
ValidateDiagFunc: NewStringInValidator(allowedTemplateTypes),
109108
},
110109
"revision": {

env0/resource_template_test.go

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestUnitTemplateResource(t *testing.T) {
1818

1919
const defaultVersion = "0.15.1"
2020

21-
const defaultType = client.OPENTOFU
21+
const testType = client.OPENTOFU
2222

2323
const defaultOpentofuVersion = "1.6.0"
2424

@@ -505,6 +505,8 @@ func TestUnitTemplateResource(t *testing.T) {
505505

506506
if template.Type != "" {
507507
templateAsDictionary["type"] = template.Type
508+
} else {
509+
templateAsDictionary["type"] = string(testType)
508510
}
509511

510512
if template.Description != "" {
@@ -760,6 +762,11 @@ func TestUnitTemplateResource(t *testing.T) {
760762
AnsibleVersion: templateUseCase.updatedTemplate.AnsibleVersion,
761763
}
762764

765+
if templateUseCase.template.Type == "" {
766+
templateCreatePayload.Type = string(testType)
767+
updateTemplateCreateTemplate.Type = string(testType)
768+
}
769+
763770
if templateUseCase.template.Type == "terragrunt" {
764771
templateCreatePayload.TerragruntTfBinary = templateUseCase.template.TerragruntTfBinary
765772
}
@@ -815,14 +822,15 @@ func TestUnitTemplateResource(t *testing.T) {
815822
Name: template.Name,
816823
Repository: template.Repository,
817824
TerraformVersion: defaultVersion,
818-
Type: string(defaultType),
825+
Type: string(testType),
819826
OpentofuVersion: defaultOpentofuVersion,
820827
}
821828

822829
basicTemplateResourceConfig := func(resourceType string, resourceName string, template client.Template) string {
823830
return resourceConfigCreate(resourceType, resourceName, map[string]interface{}{
824831
"name": template.Name,
825832
"repository": template.Repository,
833+
"type": string(testType),
826834
"terraform_version": defaultVersion,
827835
"opentofu_version": defaultOpentofuVersion,
828836
})
@@ -836,7 +844,7 @@ func TestUnitTemplateResource(t *testing.T) {
836844
resource.TestCheckResourceAttr(resourceFullName, "id", template.Id),
837845
resource.TestCheckResourceAttr(resourceFullName, "name", template.Name),
838846
resource.TestCheckResourceAttr(resourceFullName, "repository", template.Repository),
839-
resource.TestCheckResourceAttr(resourceFullName, "type", string(defaultType)),
847+
resource.TestCheckResourceAttr(resourceFullName, "type", string(testType)),
840848
resource.TestCheckResourceAttr(resourceFullName, "terraform_version", defaultVersion),
841849
resource.TestCheckResourceAttr(resourceFullName, "opentofu_version", defaultOpentofuVersion),
842850
),
@@ -849,7 +857,7 @@ func TestUnitTemplateResource(t *testing.T) {
849857
mock.EXPECT().TemplateCreate(client.TemplateCreatePayload{
850858
Name: template.Name,
851859
Repository: template.Repository,
852-
Type: defaultType,
860+
Type: testType,
853861
OpentofuVersion: defaultOpentofuVersion,
854862
}).Times(1).Return(template, nil)
855863
mock.EXPECT().TemplateDelete(template.Id).Times(1).Return(nil)
@@ -901,7 +909,7 @@ func TestUnitTemplateResource(t *testing.T) {
901909
Name: "template0",
902910
Repository: "env0/repo",
903911
TerraformVersion: defaultVersion,
904-
Type: string(defaultType),
912+
Type: string(testType),
905913
SshKeys: []client.TemplateSshKey{initialSshKey1, initialSshKey2},
906914
OpentofuVersion: defaultOpentofuVersion,
907915
}
@@ -911,7 +919,7 @@ func TestUnitTemplateResource(t *testing.T) {
911919
Name: template.Name,
912920
Repository: template.Repository,
913921
TerraformVersion: defaultVersion,
914-
Type: string(defaultType),
922+
Type: string(testType),
915923
SshKeys: []client.TemplateSshKey{updatedSshKey1, updatedSshKey2},
916924
OpentofuVersion: defaultOpentofuVersion,
917925
}
@@ -931,7 +939,7 @@ func TestUnitTemplateResource(t *testing.T) {
931939
id = "%s"
932940
name = "%s"
933941
}]
934-
}`, name, repository, defaultVersion, string(defaultType), defaultOpentofuVersion, sshKey1.Id, sshKey1.Name, sshKey2.Id, sshKey2.Name)
942+
}`, name, repository, defaultVersion, string(testType), defaultOpentofuVersion, sshKey1.Id, sshKey1.Name, sshKey2.Id, sshKey2.Name)
935943
}
936944

937945
sshTemplateResourceCheck := func(resourceFullName string, template client.Template, sshKey1 client.TemplateSshKey, sshKey2 client.TemplateSshKey) resource.TestCheckFunc {
@@ -967,14 +975,14 @@ func TestUnitTemplateResource(t *testing.T) {
967975
mock.EXPECT().TemplateCreate(client.TemplateCreatePayload{
968976
Name: template.Name,
969977
Repository: template.Repository,
970-
Type: defaultType,
978+
Type: testType,
971979
SshKeys: template.SshKeys,
972980
OpentofuVersion: defaultOpentofuVersion,
973981
}).Times(1).Return(template, nil)
974982
mock.EXPECT().TemplateUpdate(updatedTemplate.Id, client.TemplateCreatePayload{
975983
Name: updatedTemplate.Name,
976984
Repository: updatedTemplate.Repository,
977-
Type: defaultType,
985+
Type: testType,
978986
SshKeys: updatedTemplate.SshKeys,
979987
OpentofuVersion: defaultOpentofuVersion,
980988
}).Times(1).Return(updatedTemplate, nil)
@@ -995,7 +1003,7 @@ func TestUnitTemplateResource(t *testing.T) {
9951003
testCases = append(testCases, resource.TestCase{
9961004
Steps: []resource.TestStep{
9971005
{
998-
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{"name": "test", "repository": "env0/test", attribute: amount}),
1006+
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{"name": "test", "type": testType, "repository": "env0/test", attribute: amount}),
9991007
ExpectError: regexp.MustCompile("retries amount must be between 1 and 3"),
10001008
},
10011009
},
@@ -1023,7 +1031,7 @@ func TestUnitTemplateResource(t *testing.T) {
10231031
testCases = append(testCases, resource.TestCase{
10241032
Steps: []resource.TestStep{
10251033
{
1026-
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{"name": "test", "repository": "env0/test", regexAttribute: "bla"}),
1034+
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{"name": "test", "type": testType, "repository": "env0/test", regexAttribute: "bla"}),
10271035
ExpectError: regexp.MustCompile(fmt.Sprintf("`%s,%s`\\s+must\\s+be\\s+specified", timesAttribute, regexAttribute)),
10281036
},
10291037
},
@@ -1045,12 +1053,12 @@ func TestUnitTemplateResource(t *testing.T) {
10451053
tfObject map[string]interface{}
10461054
exception string
10471055
}{
1048-
{"GitLab", "GitHub", map[string]interface{}{"name": "test", "repository": "env0/test", "github_installation_id": 1, "token_id": "2"}, "\"github_installation_id\": conflicts with token_id"},
1049-
{"GitLab", "GitLab EE", map[string]interface{}{"name": "test", "repository": "env0/test", "token_id": "2", "is_gitlab_enterprise": "true"}, "\"is_gitlab_enterprise\": conflicts with token_id"},
1050-
{"GitHub", "GitLab EE", map[string]interface{}{"name": "test", "repository": "env0/test", "github_installation_id": 1, "is_gitlab_enterprise": "true"}, "\"github_installation_id\": conflicts with is_gitlab_enterprise"},
1051-
{"GitHub", "Bitbucket", map[string]interface{}{"name": "test", "repository": "env0/test", "github_installation_id": 1, "bitbucket_client_key": "3"}, "\"bitbucket_client_key\": conflicts with github_installation_id"},
1052-
{"GitLab", "Bitbucket", map[string]interface{}{"name": "test", "repository": "env0/test", "token_id": "2", "bitbucket_client_key": "3"}, "\"bitbucket_client_key\": conflicts with token_id"},
1053-
{"GitLab EE", "GitHub EE", map[string]interface{}{"name": "test", "repository": "env0/test", "is_gitlab_enterprise": "true", "is_github_enterprise": "true"}, "\"is_github_enterprise\": conflicts with is_gitlab_enterprise"},
1056+
{"GitLab", "GitHub", map[string]interface{}{"name": "test", "type": testType, "repository": "env0/test", "github_installation_id": 1, "token_id": "2"}, "\"github_installation_id\": conflicts with token_id"},
1057+
{"GitLab", "GitLab EE", map[string]interface{}{"name": "test", "type": testType, "repository": "env0/test", "token_id": "2", "is_gitlab_enterprise": "true"}, "\"is_gitlab_enterprise\": conflicts with token_id"},
1058+
{"GitHub", "GitLab EE", map[string]interface{}{"name": "test", "type": testType, "repository": "env0/test", "github_installation_id": 1, "is_gitlab_enterprise": "true"}, "\"github_installation_id\": conflicts with is_gitlab_enterprise"},
1059+
{"GitHub", "Bitbucket", map[string]interface{}{"name": "test", "type": testType, "repository": "env0/test", "github_installation_id": 1, "bitbucket_client_key": "3"}, "\"bitbucket_client_key\": conflicts with github_installation_id"},
1060+
{"GitLab", "Bitbucket", map[string]interface{}{"name": "test", "type": testType, "repository": "env0/test", "token_id": "2", "bitbucket_client_key": "3"}, "\"bitbucket_client_key\": conflicts with token_id"},
1061+
{"GitLab EE", "GitHub EE", map[string]interface{}{"name": "test", "type": testType, "repository": "env0/test", "is_gitlab_enterprise": "true", "is_github_enterprise": "true"}, "\"is_github_enterprise\": conflicts with is_gitlab_enterprise"},
10541062
}
10551063

10561064
for _, mixUseCase := range mixedUsecases {
@@ -1077,28 +1085,30 @@ func TestUnitTemplateResource(t *testing.T) {
10771085
Id: "id0",
10781086
Name: "template0",
10791087
Repository: "env0/repo",
1088+
Type: string(testType),
10801089
}
10811090

10821091
updateTemplate := client.Template{
10831092
Id: "id0-update",
10841093
Name: "template0-update",
10851094
Repository: "env0/repo-update",
1095+
Type: string(testType),
10861096
}
10871097

10881098
templateWithDefaults := client.Template{
10891099
Id: template.Id,
10901100
Name: template.Name,
10911101
Repository: template.Repository,
10921102
TerraformVersion: defaultVersion,
1093-
Type: string(defaultType),
1103+
Type: string(testType),
10941104
OpentofuVersion: defaultOpentofuVersion,
10951105
}
10961106
templateWithDefaultsUpdate := client.Template{
10971107
Id: updateTemplate.Id,
10981108
Name: updateTemplate.Name,
10991109
Repository: updateTemplate.Repository,
11001110
TerraformVersion: defaultVersion,
1101-
Type: string(defaultType),
1111+
Type: string(testType),
11021112
OpentofuVersion: defaultOpentofuVersion,
11031113
}
11041114

@@ -1108,13 +1118,14 @@ func TestUnitTemplateResource(t *testing.T) {
11081118
Name: template.Name,
11091119
Repository: template.Repository,
11101120
TerraformVersion: defaultVersion,
1111-
Type: string(defaultType),
1121+
Type: string(testType),
11121122
OpentofuVersion: defaultOpentofuVersion,
11131123
}
11141124

11151125
basicTemplateResourceConfig := func(resourceType string, resourceName string, template client.Template) string {
11161126
return resourceConfigCreate(resourceType, resourceName, map[string]interface{}{
11171127
"name": template.Name,
1128+
"type": string(template.Type),
11181129
"repository": template.Repository,
11191130
"terraform_version": defaultVersion,
11201131
"opentofu_version": defaultOpentofuVersion,
@@ -1129,7 +1140,7 @@ func TestUnitTemplateResource(t *testing.T) {
11291140
resource.TestCheckResourceAttr(resourceFullName, "id", template.Id),
11301141
resource.TestCheckResourceAttr(resourceFullName, "name", template.Name),
11311142
resource.TestCheckResourceAttr(resourceFullName, "repository", template.Repository),
1132-
resource.TestCheckResourceAttr(resourceFullName, "type", string(defaultType)),
1143+
resource.TestCheckResourceAttr(resourceFullName, "type", string(testType)),
11331144
resource.TestCheckResourceAttr(resourceFullName, "terraform_version", defaultVersion),
11341145
resource.TestCheckResourceAttr(resourceFullName, "opentofu_version", defaultOpentofuVersion),
11351146
),
@@ -1140,7 +1151,7 @@ func TestUnitTemplateResource(t *testing.T) {
11401151
resource.TestCheckResourceAttr(resourceFullName, "id", updateTemplate.Id),
11411152
resource.TestCheckResourceAttr(resourceFullName, "name", updateTemplate.Name),
11421153
resource.TestCheckResourceAttr(resourceFullName, "repository", updateTemplate.Repository),
1143-
resource.TestCheckResourceAttr(resourceFullName, "type", string(defaultType)),
1154+
resource.TestCheckResourceAttr(resourceFullName, "type", string(testType)),
11441155
resource.TestCheckResourceAttr(resourceFullName, "terraform_version", defaultVersion),
11451156
resource.TestCheckResourceAttr(resourceFullName, "opentofu_version", defaultOpentofuVersion),
11461157
),
@@ -1152,14 +1163,14 @@ func TestUnitTemplateResource(t *testing.T) {
11521163
mock.EXPECT().TemplateCreate(client.TemplateCreatePayload{
11531164
Name: template.Name,
11541165
Repository: template.Repository,
1155-
Type: defaultType,
1166+
Type: testType,
11561167
OpentofuVersion: defaultOpentofuVersion,
11571168
}).Times(1).Return(template, nil)
11581169

11591170
mock.EXPECT().TemplateCreate(client.TemplateCreatePayload{
11601171
Name: updateTemplate.Name,
11611172
Repository: updateTemplate.Repository,
1162-
Type: defaultType,
1173+
Type: testType,
11631174
OpentofuVersion: defaultOpentofuVersion,
11641175
}).Times(1).Return(updateTemplate, nil)
11651176

@@ -1180,7 +1191,7 @@ func TestUnitTemplateResource(t *testing.T) {
11801191
Path: "path/zero",
11811192
Repository: "repo",
11821193
TerraformVersion: string(defaultVersion),
1183-
Type: string(defaultType),
1194+
Type: string(testType),
11841195
OpentofuVersion: defaultOpentofuVersion,
11851196
}
11861197

@@ -1190,7 +1201,7 @@ func TestUnitTemplateResource(t *testing.T) {
11901201
Path: "path/one",
11911202
Repository: "repo",
11921203
TerraformVersion: string(defaultVersion),
1193-
Type: string(defaultType),
1204+
Type: string(testType),
11941205
OpentofuVersion: defaultOpentofuVersion,
11951206
}
11961207

@@ -1203,6 +1214,7 @@ func TestUnitTemplateResource(t *testing.T) {
12031214
"repository": pathTemplate.Repository,
12041215
"terraform_version": pathTemplate.TerraformVersion,
12051216
"opentofu_version": defaultOpentofuVersion,
1217+
"type": pathTemplate.Type,
12061218
}),
12071219
Check: resource.ComposeAggregateTestCheckFunc(
12081220
resource.TestCheckResourceAttr(resourceFullName, "id", pathTemplate.Id),
@@ -1221,6 +1233,7 @@ func TestUnitTemplateResource(t *testing.T) {
12211233
"repository": updatedPathTemplate.Repository,
12221234
"terraform_version": updatedPathTemplate.TerraformVersion,
12231235
"opentofu_version": defaultOpentofuVersion,
1236+
"type": updatedPathTemplate.Type,
12241237
}),
12251238
Check: resource.ComposeAggregateTestCheckFunc(
12261239
resource.TestCheckResourceAttr(resourceFullName, "id", updatedPathTemplate.Id),

0 commit comments

Comments
 (0)