@@ -18,7 +18,7 @@ func TestUnitTemplateResource(t *testing.T) {
18
18
19
19
const defaultVersion = "0.15.1"
20
20
21
- const defaultType = client .OPENTOFU
21
+ const testType = client .OPENTOFU
22
22
23
23
const defaultOpentofuVersion = "1.6.0"
24
24
@@ -505,6 +505,8 @@ func TestUnitTemplateResource(t *testing.T) {
505
505
506
506
if template .Type != "" {
507
507
templateAsDictionary ["type" ] = template .Type
508
+ } else {
509
+ templateAsDictionary ["type" ] = string (testType )
508
510
}
509
511
510
512
if template .Description != "" {
@@ -760,6 +762,11 @@ func TestUnitTemplateResource(t *testing.T) {
760
762
AnsibleVersion : templateUseCase .updatedTemplate .AnsibleVersion ,
761
763
}
762
764
765
+ if templateUseCase .template .Type == "" {
766
+ templateCreatePayload .Type = string (testType )
767
+ updateTemplateCreateTemplate .Type = string (testType )
768
+ }
769
+
763
770
if templateUseCase .template .Type == "terragrunt" {
764
771
templateCreatePayload .TerragruntTfBinary = templateUseCase .template .TerragruntTfBinary
765
772
}
@@ -815,14 +822,15 @@ func TestUnitTemplateResource(t *testing.T) {
815
822
Name : template .Name ,
816
823
Repository : template .Repository ,
817
824
TerraformVersion : defaultVersion ,
818
- Type : string (defaultType ),
825
+ Type : string (testType ),
819
826
OpentofuVersion : defaultOpentofuVersion ,
820
827
}
821
828
822
829
basicTemplateResourceConfig := func (resourceType string , resourceName string , template client.Template ) string {
823
830
return resourceConfigCreate (resourceType , resourceName , map [string ]interface {}{
824
831
"name" : template .Name ,
825
832
"repository" : template .Repository ,
833
+ "type" : string (testType ),
826
834
"terraform_version" : defaultVersion ,
827
835
"opentofu_version" : defaultOpentofuVersion ,
828
836
})
@@ -836,7 +844,7 @@ func TestUnitTemplateResource(t *testing.T) {
836
844
resource .TestCheckResourceAttr (resourceFullName , "id" , template .Id ),
837
845
resource .TestCheckResourceAttr (resourceFullName , "name" , template .Name ),
838
846
resource .TestCheckResourceAttr (resourceFullName , "repository" , template .Repository ),
839
- resource .TestCheckResourceAttr (resourceFullName , "type" , string (defaultType )),
847
+ resource .TestCheckResourceAttr (resourceFullName , "type" , string (testType )),
840
848
resource .TestCheckResourceAttr (resourceFullName , "terraform_version" , defaultVersion ),
841
849
resource .TestCheckResourceAttr (resourceFullName , "opentofu_version" , defaultOpentofuVersion ),
842
850
),
@@ -849,7 +857,7 @@ func TestUnitTemplateResource(t *testing.T) {
849
857
mock .EXPECT ().TemplateCreate (client.TemplateCreatePayload {
850
858
Name : template .Name ,
851
859
Repository : template .Repository ,
852
- Type : defaultType ,
860
+ Type : testType ,
853
861
OpentofuVersion : defaultOpentofuVersion ,
854
862
}).Times (1 ).Return (template , nil )
855
863
mock .EXPECT ().TemplateDelete (template .Id ).Times (1 ).Return (nil )
@@ -901,7 +909,7 @@ func TestUnitTemplateResource(t *testing.T) {
901
909
Name : "template0" ,
902
910
Repository : "env0/repo" ,
903
911
TerraformVersion : defaultVersion ,
904
- Type : string (defaultType ),
912
+ Type : string (testType ),
905
913
SshKeys : []client.TemplateSshKey {initialSshKey1 , initialSshKey2 },
906
914
OpentofuVersion : defaultOpentofuVersion ,
907
915
}
@@ -911,7 +919,7 @@ func TestUnitTemplateResource(t *testing.T) {
911
919
Name : template .Name ,
912
920
Repository : template .Repository ,
913
921
TerraformVersion : defaultVersion ,
914
- Type : string (defaultType ),
922
+ Type : string (testType ),
915
923
SshKeys : []client.TemplateSshKey {updatedSshKey1 , updatedSshKey2 },
916
924
OpentofuVersion : defaultOpentofuVersion ,
917
925
}
@@ -931,7 +939,7 @@ func TestUnitTemplateResource(t *testing.T) {
931
939
id = "%s"
932
940
name = "%s"
933
941
}]
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 )
935
943
}
936
944
937
945
sshTemplateResourceCheck := func (resourceFullName string , template client.Template , sshKey1 client.TemplateSshKey , sshKey2 client.TemplateSshKey ) resource.TestCheckFunc {
@@ -967,14 +975,14 @@ func TestUnitTemplateResource(t *testing.T) {
967
975
mock .EXPECT ().TemplateCreate (client.TemplateCreatePayload {
968
976
Name : template .Name ,
969
977
Repository : template .Repository ,
970
- Type : defaultType ,
978
+ Type : testType ,
971
979
SshKeys : template .SshKeys ,
972
980
OpentofuVersion : defaultOpentofuVersion ,
973
981
}).Times (1 ).Return (template , nil )
974
982
mock .EXPECT ().TemplateUpdate (updatedTemplate .Id , client.TemplateCreatePayload {
975
983
Name : updatedTemplate .Name ,
976
984
Repository : updatedTemplate .Repository ,
977
- Type : defaultType ,
985
+ Type : testType ,
978
986
SshKeys : updatedTemplate .SshKeys ,
979
987
OpentofuVersion : defaultOpentofuVersion ,
980
988
}).Times (1 ).Return (updatedTemplate , nil )
@@ -995,7 +1003,7 @@ func TestUnitTemplateResource(t *testing.T) {
995
1003
testCases = append (testCases , resource.TestCase {
996
1004
Steps : []resource.TestStep {
997
1005
{
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 }),
999
1007
ExpectError : regexp .MustCompile ("retries amount must be between 1 and 3" ),
1000
1008
},
1001
1009
},
@@ -1023,7 +1031,7 @@ func TestUnitTemplateResource(t *testing.T) {
1023
1031
testCases = append (testCases , resource.TestCase {
1024
1032
Steps : []resource.TestStep {
1025
1033
{
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" }),
1027
1035
ExpectError : regexp .MustCompile (fmt .Sprintf ("`%s,%s`\\ s+must\\ s+be\\ s+specified" , timesAttribute , regexAttribute )),
1028
1036
},
1029
1037
},
@@ -1045,12 +1053,12 @@ func TestUnitTemplateResource(t *testing.T) {
1045
1053
tfObject map [string ]interface {}
1046
1054
exception string
1047
1055
}{
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" },
1054
1062
}
1055
1063
1056
1064
for _ , mixUseCase := range mixedUsecases {
@@ -1077,28 +1085,30 @@ func TestUnitTemplateResource(t *testing.T) {
1077
1085
Id : "id0" ,
1078
1086
Name : "template0" ,
1079
1087
Repository : "env0/repo" ,
1088
+ Type : string (testType ),
1080
1089
}
1081
1090
1082
1091
updateTemplate := client.Template {
1083
1092
Id : "id0-update" ,
1084
1093
Name : "template0-update" ,
1085
1094
Repository : "env0/repo-update" ,
1095
+ Type : string (testType ),
1086
1096
}
1087
1097
1088
1098
templateWithDefaults := client.Template {
1089
1099
Id : template .Id ,
1090
1100
Name : template .Name ,
1091
1101
Repository : template .Repository ,
1092
1102
TerraformVersion : defaultVersion ,
1093
- Type : string (defaultType ),
1103
+ Type : string (testType ),
1094
1104
OpentofuVersion : defaultOpentofuVersion ,
1095
1105
}
1096
1106
templateWithDefaultsUpdate := client.Template {
1097
1107
Id : updateTemplate .Id ,
1098
1108
Name : updateTemplate .Name ,
1099
1109
Repository : updateTemplate .Repository ,
1100
1110
TerraformVersion : defaultVersion ,
1101
- Type : string (defaultType ),
1111
+ Type : string (testType ),
1102
1112
OpentofuVersion : defaultOpentofuVersion ,
1103
1113
}
1104
1114
@@ -1108,13 +1118,14 @@ func TestUnitTemplateResource(t *testing.T) {
1108
1118
Name : template .Name ,
1109
1119
Repository : template .Repository ,
1110
1120
TerraformVersion : defaultVersion ,
1111
- Type : string (defaultType ),
1121
+ Type : string (testType ),
1112
1122
OpentofuVersion : defaultOpentofuVersion ,
1113
1123
}
1114
1124
1115
1125
basicTemplateResourceConfig := func (resourceType string , resourceName string , template client.Template ) string {
1116
1126
return resourceConfigCreate (resourceType , resourceName , map [string ]interface {}{
1117
1127
"name" : template .Name ,
1128
+ "type" : string (template .Type ),
1118
1129
"repository" : template .Repository ,
1119
1130
"terraform_version" : defaultVersion ,
1120
1131
"opentofu_version" : defaultOpentofuVersion ,
@@ -1129,7 +1140,7 @@ func TestUnitTemplateResource(t *testing.T) {
1129
1140
resource .TestCheckResourceAttr (resourceFullName , "id" , template .Id ),
1130
1141
resource .TestCheckResourceAttr (resourceFullName , "name" , template .Name ),
1131
1142
resource .TestCheckResourceAttr (resourceFullName , "repository" , template .Repository ),
1132
- resource .TestCheckResourceAttr (resourceFullName , "type" , string (defaultType )),
1143
+ resource .TestCheckResourceAttr (resourceFullName , "type" , string (testType )),
1133
1144
resource .TestCheckResourceAttr (resourceFullName , "terraform_version" , defaultVersion ),
1134
1145
resource .TestCheckResourceAttr (resourceFullName , "opentofu_version" , defaultOpentofuVersion ),
1135
1146
),
@@ -1140,7 +1151,7 @@ func TestUnitTemplateResource(t *testing.T) {
1140
1151
resource .TestCheckResourceAttr (resourceFullName , "id" , updateTemplate .Id ),
1141
1152
resource .TestCheckResourceAttr (resourceFullName , "name" , updateTemplate .Name ),
1142
1153
resource .TestCheckResourceAttr (resourceFullName , "repository" , updateTemplate .Repository ),
1143
- resource .TestCheckResourceAttr (resourceFullName , "type" , string (defaultType )),
1154
+ resource .TestCheckResourceAttr (resourceFullName , "type" , string (testType )),
1144
1155
resource .TestCheckResourceAttr (resourceFullName , "terraform_version" , defaultVersion ),
1145
1156
resource .TestCheckResourceAttr (resourceFullName , "opentofu_version" , defaultOpentofuVersion ),
1146
1157
),
@@ -1152,14 +1163,14 @@ func TestUnitTemplateResource(t *testing.T) {
1152
1163
mock .EXPECT ().TemplateCreate (client.TemplateCreatePayload {
1153
1164
Name : template .Name ,
1154
1165
Repository : template .Repository ,
1155
- Type : defaultType ,
1166
+ Type : testType ,
1156
1167
OpentofuVersion : defaultOpentofuVersion ,
1157
1168
}).Times (1 ).Return (template , nil )
1158
1169
1159
1170
mock .EXPECT ().TemplateCreate (client.TemplateCreatePayload {
1160
1171
Name : updateTemplate .Name ,
1161
1172
Repository : updateTemplate .Repository ,
1162
- Type : defaultType ,
1173
+ Type : testType ,
1163
1174
OpentofuVersion : defaultOpentofuVersion ,
1164
1175
}).Times (1 ).Return (updateTemplate , nil )
1165
1176
@@ -1180,7 +1191,7 @@ func TestUnitTemplateResource(t *testing.T) {
1180
1191
Path : "path/zero" ,
1181
1192
Repository : "repo" ,
1182
1193
TerraformVersion : string (defaultVersion ),
1183
- Type : string (defaultType ),
1194
+ Type : string (testType ),
1184
1195
OpentofuVersion : defaultOpentofuVersion ,
1185
1196
}
1186
1197
@@ -1190,7 +1201,7 @@ func TestUnitTemplateResource(t *testing.T) {
1190
1201
Path : "path/one" ,
1191
1202
Repository : "repo" ,
1192
1203
TerraformVersion : string (defaultVersion ),
1193
- Type : string (defaultType ),
1204
+ Type : string (testType ),
1194
1205
OpentofuVersion : defaultOpentofuVersion ,
1195
1206
}
1196
1207
@@ -1203,6 +1214,7 @@ func TestUnitTemplateResource(t *testing.T) {
1203
1214
"repository" : pathTemplate .Repository ,
1204
1215
"terraform_version" : pathTemplate .TerraformVersion ,
1205
1216
"opentofu_version" : defaultOpentofuVersion ,
1217
+ "type" : pathTemplate .Type ,
1206
1218
}),
1207
1219
Check : resource .ComposeAggregateTestCheckFunc (
1208
1220
resource .TestCheckResourceAttr (resourceFullName , "id" , pathTemplate .Id ),
@@ -1221,6 +1233,7 @@ func TestUnitTemplateResource(t *testing.T) {
1221
1233
"repository" : updatedPathTemplate .Repository ,
1222
1234
"terraform_version" : updatedPathTemplate .TerraformVersion ,
1223
1235
"opentofu_version" : defaultOpentofuVersion ,
1236
+ "type" : updatedPathTemplate .Type ,
1224
1237
}),
1225
1238
Check : resource .ComposeAggregateTestCheckFunc (
1226
1239
resource .TestCheckResourceAttr (resourceFullName , "id" , updatedPathTemplate .Id ),
0 commit comments