@@ -18,7 +18,9 @@ func TestUnitTemplateResource(t *testing.T) {
18
18
19
19
const defaultVersion = "0.15.1"
20
20
21
- const defaultType = "terraform"
21
+ const defaultType = client .OPENTOFU
22
+
23
+ const defaultOpentofuVersion = "1.6.0"
22
24
23
25
var resourceFullName = resourceAccessor (resourceType , resourceName )
24
26
@@ -814,13 +816,15 @@ func TestUnitTemplateResource(t *testing.T) {
814
816
Repository : template .Repository ,
815
817
TerraformVersion : defaultVersion ,
816
818
Type : string (defaultType ),
819
+ OpentofuVersion : defaultOpentofuVersion ,
817
820
}
818
821
819
822
basicTemplateResourceConfig := func (resourceType string , resourceName string , template client.Template ) string {
820
823
return resourceConfigCreate (resourceType , resourceName , map [string ]interface {}{
821
824
"name" : template .Name ,
822
825
"repository" : template .Repository ,
823
826
"terraform_version" : defaultVersion ,
827
+ "opentofu_version" : defaultOpentofuVersion ,
824
828
})
825
829
}
826
830
@@ -834,6 +838,7 @@ func TestUnitTemplateResource(t *testing.T) {
834
838
resource .TestCheckResourceAttr (resourceFullName , "repository" , template .Repository ),
835
839
resource .TestCheckResourceAttr (resourceFullName , "type" , string (defaultType )),
836
840
resource .TestCheckResourceAttr (resourceFullName , "terraform_version" , defaultVersion ),
841
+ resource .TestCheckResourceAttr (resourceFullName , "opentofu_version" , defaultOpentofuVersion ),
837
842
),
838
843
},
839
844
},
@@ -842,10 +847,10 @@ func TestUnitTemplateResource(t *testing.T) {
842
847
runUnitTest (t , testCase , func (mock * client.MockApiClientInterface ) {
843
848
mock .EXPECT ().Template (template .Id ).AnyTimes ().Return (templateWithDefaults , nil )
844
849
mock .EXPECT ().TemplateCreate (client.TemplateCreatePayload {
845
- Name : template .Name ,
846
- Repository : template .Repository ,
847
- Type : defaultType ,
848
- TerraformVersion : defaultVersion ,
850
+ Name : template .Name ,
851
+ Repository : template .Repository ,
852
+ Type : defaultType ,
853
+ OpentofuVersion : defaultOpentofuVersion ,
849
854
}).Times (1 ).Return (template , nil )
850
855
mock .EXPECT ().TemplateDelete (template .Id ).Times (1 ).Return (nil )
851
856
})
@@ -898,6 +903,7 @@ func TestUnitTemplateResource(t *testing.T) {
898
903
TerraformVersion : defaultVersion ,
899
904
Type : string (defaultType ),
900
905
SshKeys : []client.TemplateSshKey {initialSshKey1 , initialSshKey2 },
906
+ OpentofuVersion : defaultOpentofuVersion ,
901
907
}
902
908
903
909
updatedTemplate := client.Template {
@@ -907,6 +913,7 @@ func TestUnitTemplateResource(t *testing.T) {
907
913
TerraformVersion : defaultVersion ,
908
914
Type : string (defaultType ),
909
915
SshKeys : []client.TemplateSshKey {updatedSshKey1 , updatedSshKey2 },
916
+ OpentofuVersion : defaultOpentofuVersion ,
910
917
}
911
918
912
919
sshKeyTemplateResourceConfig := func (name string , repository string , sshKey1 client.TemplateSshKey , sshKey2 client.TemplateSshKey ) string {
@@ -916,14 +923,15 @@ func TestUnitTemplateResource(t *testing.T) {
916
923
repository = "%s"
917
924
terraform_version = "%s"
918
925
type = "%s"
926
+ opentofu_version = "%s"
919
927
ssh_keys = [{
920
928
id = "%s"
921
929
name = "%s"
922
930
}, {
923
931
id = "%s"
924
932
name = "%s"
925
933
}]
926
- }` , name , repository , defaultVersion , string (defaultType ), sshKey1 .Id , sshKey1 .Name , sshKey2 .Id , sshKey2 .Name )
934
+ }` , name , repository , defaultVersion , string (defaultType ), defaultOpentofuVersion , sshKey1 .Id , sshKey1 .Name , sshKey2 .Id , sshKey2 .Name )
927
935
}
928
936
929
937
sshTemplateResourceCheck := func (resourceFullName string , template client.Template , sshKey1 client.TemplateSshKey , sshKey2 client.TemplateSshKey ) resource.TestCheckFunc {
@@ -957,18 +965,18 @@ func TestUnitTemplateResource(t *testing.T) {
957
965
mock .EXPECT ().Template (template .Id ).Times (1 ).Return (updatedTemplate , nil ), // 1 after update
958
966
)
959
967
mock .EXPECT ().TemplateCreate (client.TemplateCreatePayload {
960
- Name : template .Name ,
961
- Repository : template .Repository ,
962
- Type : defaultType ,
963
- TerraformVersion : defaultVersion ,
964
- SshKeys : template . SshKeys ,
968
+ Name : template .Name ,
969
+ Repository : template .Repository ,
970
+ Type : defaultType ,
971
+ SshKeys : template . SshKeys ,
972
+ OpentofuVersion : defaultOpentofuVersion ,
965
973
}).Times (1 ).Return (template , nil )
966
974
mock .EXPECT ().TemplateUpdate (updatedTemplate .Id , client.TemplateCreatePayload {
967
- Name : updatedTemplate .Name ,
968
- Repository : updatedTemplate .Repository ,
969
- Type : defaultType ,
970
- TerraformVersion : defaultVersion ,
971
- SshKeys : updatedTemplate . SshKeys ,
975
+ Name : updatedTemplate .Name ,
976
+ Repository : updatedTemplate .Repository ,
977
+ Type : defaultType ,
978
+ SshKeys : updatedTemplate . SshKeys ,
979
+ OpentofuVersion : defaultOpentofuVersion ,
972
980
}).Times (1 ).Return (updatedTemplate , nil )
973
981
mock .EXPECT ().TemplateDelete (template .Id ).Times (1 ).Return (nil )
974
982
})
@@ -1083,13 +1091,15 @@ func TestUnitTemplateResource(t *testing.T) {
1083
1091
Repository : template .Repository ,
1084
1092
TerraformVersion : defaultVersion ,
1085
1093
Type : string (defaultType ),
1094
+ OpentofuVersion : defaultOpentofuVersion ,
1086
1095
}
1087
1096
templateWithDefaultsUpdate := client.Template {
1088
1097
Id : updateTemplate .Id ,
1089
1098
Name : updateTemplate .Name ,
1090
1099
Repository : updateTemplate .Repository ,
1091
1100
TerraformVersion : defaultVersion ,
1092
1101
Type : string (defaultType ),
1102
+ OpentofuVersion : defaultOpentofuVersion ,
1093
1103
}
1094
1104
1095
1105
templateWithDrift := client.Template {
@@ -1099,13 +1109,15 @@ func TestUnitTemplateResource(t *testing.T) {
1099
1109
Repository : template .Repository ,
1100
1110
TerraformVersion : defaultVersion ,
1101
1111
Type : string (defaultType ),
1112
+ OpentofuVersion : defaultOpentofuVersion ,
1102
1113
}
1103
1114
1104
1115
basicTemplateResourceConfig := func (resourceType string , resourceName string , template client.Template ) string {
1105
1116
return resourceConfigCreate (resourceType , resourceName , map [string ]interface {}{
1106
1117
"name" : template .Name ,
1107
1118
"repository" : template .Repository ,
1108
1119
"terraform_version" : defaultVersion ,
1120
+ "opentofu_version" : defaultOpentofuVersion ,
1109
1121
})
1110
1122
}
1111
1123
@@ -1119,6 +1131,7 @@ func TestUnitTemplateResource(t *testing.T) {
1119
1131
resource .TestCheckResourceAttr (resourceFullName , "repository" , template .Repository ),
1120
1132
resource .TestCheckResourceAttr (resourceFullName , "type" , string (defaultType )),
1121
1133
resource .TestCheckResourceAttr (resourceFullName , "terraform_version" , defaultVersion ),
1134
+ resource .TestCheckResourceAttr (resourceFullName , "opentofu_version" , defaultOpentofuVersion ),
1122
1135
),
1123
1136
},
1124
1137
{
@@ -1129,24 +1142,25 @@ func TestUnitTemplateResource(t *testing.T) {
1129
1142
resource .TestCheckResourceAttr (resourceFullName , "repository" , updateTemplate .Repository ),
1130
1143
resource .TestCheckResourceAttr (resourceFullName , "type" , string (defaultType )),
1131
1144
resource .TestCheckResourceAttr (resourceFullName , "terraform_version" , defaultVersion ),
1145
+ resource .TestCheckResourceAttr (resourceFullName , "opentofu_version" , defaultOpentofuVersion ),
1132
1146
),
1133
1147
},
1134
1148
},
1135
1149
}
1136
1150
1137
1151
runUnitTest (t , testCase , func (mock * client.MockApiClientInterface ) {
1138
1152
mock .EXPECT ().TemplateCreate (client.TemplateCreatePayload {
1139
- Name : template .Name ,
1140
- Repository : template .Repository ,
1141
- Type : defaultType ,
1142
- TerraformVersion : defaultVersion ,
1153
+ Name : template .Name ,
1154
+ Repository : template .Repository ,
1155
+ Type : defaultType ,
1156
+ OpentofuVersion : defaultOpentofuVersion ,
1143
1157
}).Times (1 ).Return (template , nil )
1144
1158
1145
1159
mock .EXPECT ().TemplateCreate (client.TemplateCreatePayload {
1146
- Name : updateTemplate .Name ,
1147
- Repository : updateTemplate .Repository ,
1148
- Type : defaultType ,
1149
- TerraformVersion : defaultVersion ,
1160
+ Name : updateTemplate .Name ,
1161
+ Repository : updateTemplate .Repository ,
1162
+ Type : defaultType ,
1163
+ OpentofuVersion : defaultOpentofuVersion ,
1150
1164
}).Times (1 ).Return (updateTemplate , nil )
1151
1165
1152
1166
gomock .InOrder (
@@ -1167,6 +1181,7 @@ func TestUnitTemplateResource(t *testing.T) {
1167
1181
Repository : "repo" ,
1168
1182
TerraformVersion : string (defaultVersion ),
1169
1183
Type : string (defaultType ),
1184
+ OpentofuVersion : defaultOpentofuVersion ,
1170
1185
}
1171
1186
1172
1187
updatedPathTemplate := client.Template {
@@ -1176,6 +1191,7 @@ func TestUnitTemplateResource(t *testing.T) {
1176
1191
Repository : "repo" ,
1177
1192
TerraformVersion : string (defaultVersion ),
1178
1193
Type : string (defaultType ),
1194
+ OpentofuVersion : defaultOpentofuVersion ,
1179
1195
}
1180
1196
1181
1197
testCase := resource.TestCase {
@@ -1186,6 +1202,7 @@ func TestUnitTemplateResource(t *testing.T) {
1186
1202
"path" : "/" + pathTemplate .Path ,
1187
1203
"repository" : pathTemplate .Repository ,
1188
1204
"terraform_version" : pathTemplate .TerraformVersion ,
1205
+ "opentofu_version" : defaultOpentofuVersion ,
1189
1206
}),
1190
1207
Check : resource .ComposeAggregateTestCheckFunc (
1191
1208
resource .TestCheckResourceAttr (resourceFullName , "id" , pathTemplate .Id ),
@@ -1194,6 +1211,7 @@ func TestUnitTemplateResource(t *testing.T) {
1194
1211
resource .TestCheckResourceAttr (resourceFullName , "type" , pathTemplate .Type ),
1195
1212
resource .TestCheckResourceAttr (resourceFullName , "terraform_version" , pathTemplate .TerraformVersion ),
1196
1213
resource .TestCheckResourceAttr (resourceFullName , "path" , "/" + pathTemplate .Path ),
1214
+ resource .TestCheckResourceAttr (resourceFullName , "opentofu_version" , defaultOpentofuVersion ),
1197
1215
),
1198
1216
},
1199
1217
{
@@ -1202,6 +1220,7 @@ func TestUnitTemplateResource(t *testing.T) {
1202
1220
"path" : "/" + updatedPathTemplate .Path ,
1203
1221
"repository" : updatedPathTemplate .Repository ,
1204
1222
"terraform_version" : updatedPathTemplate .TerraformVersion ,
1223
+ "opentofu_version" : defaultOpentofuVersion ,
1205
1224
}),
1206
1225
Check : resource .ComposeAggregateTestCheckFunc (
1207
1226
resource .TestCheckResourceAttr (resourceFullName , "id" , updatedPathTemplate .Id ),
@@ -1210,6 +1229,7 @@ func TestUnitTemplateResource(t *testing.T) {
1210
1229
resource .TestCheckResourceAttr (resourceFullName , "type" , updatedPathTemplate .Type ),
1211
1230
resource .TestCheckResourceAttr (resourceFullName , "terraform_version" , updatedPathTemplate .TerraformVersion ),
1212
1231
resource .TestCheckResourceAttr (resourceFullName , "path" , "/" + updatedPathTemplate .Path ),
1232
+ resource .TestCheckResourceAttr (resourceFullName , "opentofu_version" , defaultOpentofuVersion ),
1213
1233
),
1214
1234
},
1215
1235
},
@@ -1218,19 +1238,19 @@ func TestUnitTemplateResource(t *testing.T) {
1218
1238
runUnitTest (t , testCase , func (mock * client.MockApiClientInterface ) {
1219
1239
gomock .InOrder (
1220
1240
mock .EXPECT ().TemplateCreate (client.TemplateCreatePayload {
1221
- Path : "/" + pathTemplate .Path ,
1222
- Name : pathTemplate .Name ,
1223
- Type : pathTemplate .Type ,
1224
- TerraformVersion : pathTemplate .TerraformVersion ,
1225
- Repository : pathTemplate . Repository ,
1241
+ Path : "/" + pathTemplate .Path ,
1242
+ Name : pathTemplate .Name ,
1243
+ Type : pathTemplate .Type ,
1244
+ Repository : pathTemplate .Repository ,
1245
+ OpentofuVersion : defaultOpentofuVersion ,
1226
1246
}).Times (1 ).Return (pathTemplate , nil ),
1227
1247
mock .EXPECT ().Template (pathTemplate .Id ).Times (2 ).Return (pathTemplate , nil ),
1228
1248
mock .EXPECT ().TemplateUpdate (updatedPathTemplate .Id , client.TemplateCreatePayload {
1229
- Path : "/" + updatedPathTemplate .Path ,
1230
- Name : updatedPathTemplate .Name ,
1231
- Type : updatedPathTemplate .Type ,
1232
- TerraformVersion : updatedPathTemplate .TerraformVersion ,
1233
- Repository : updatedPathTemplate . Repository ,
1249
+ Path : "/" + updatedPathTemplate .Path ,
1250
+ Name : updatedPathTemplate .Name ,
1251
+ Type : updatedPathTemplate .Type ,
1252
+ Repository : updatedPathTemplate .Repository ,
1253
+ OpentofuVersion : defaultOpentofuVersion ,
1234
1254
}).Times (1 ).Return (updatedPathTemplate , nil ),
1235
1255
mock .EXPECT ().Template (pathTemplate .Id ).Times (1 ).Return (updatedPathTemplate , nil ),
1236
1256
mock .EXPECT ().TemplateDelete (pathTemplate .Id ).Times (1 ).Return (nil ),
0 commit comments