@@ -286,6 +286,15 @@ func TestAccTemplateResource(t *testing.T) {
286
286
cfg5 .Versions = slices .Clone (cfg5 .Versions )
287
287
cfg5 .Versions [1 ].Directory = PtrTo ("../../integration/template-test/example-template/" )
288
288
289
+ cfg6 := cfg5
290
+ cfg6 .Versions = slices .Clone (cfg6 .Versions )
291
+ cfg6 .Versions [0 ].TerraformVariables = []testAccTemplateKeyValueConfig {
292
+ {
293
+ Key : PtrTo ("name" ),
294
+ Value : PtrTo ("world2" ),
295
+ },
296
+ }
297
+
289
298
resource .Test (t , resource.TestCase {
290
299
PreCheck : func () { testAccPreCheck (t ) },
291
300
IsUnitTest : true ,
@@ -343,6 +352,66 @@ func TestAccTemplateResource(t *testing.T) {
343
352
testAccCheckNumTemplateVersions (ctx , client , 4 ),
344
353
),
345
354
},
355
+ // Update the Terraform variables of the first version
356
+ {
357
+ Config : cfg6 .String (t ),
358
+ Check : resource .ComposeAggregateTestCheckFunc (
359
+ testAccCheckNumTemplateVersions (ctx , client , 5 ),
360
+ ),
361
+ },
362
+ },
363
+ })
364
+ })
365
+
366
+ t .Run ("AutoGenNameUpdateTFVars" , func (t * testing.T ) {
367
+ cfg1 := testAccTemplateResourceConfig {
368
+ URL : client .URL .String (),
369
+ Token : client .SessionToken (),
370
+ Name : PtrTo ("example-template3" ),
371
+ Versions : []testAccTemplateVersionConfig {
372
+ {
373
+ // Auto-generated version name
374
+ Directory : PtrTo ("../../integration/template-test/example-template-2/" ),
375
+ TerraformVariables : []testAccTemplateKeyValueConfig {
376
+ {
377
+ Key : PtrTo ("name" ),
378
+ Value : PtrTo ("world" ),
379
+ },
380
+ },
381
+ Active : PtrTo (true ),
382
+ },
383
+ },
384
+ ACL : testAccTemplateACLConfig {
385
+ null : true ,
386
+ },
387
+ }
388
+
389
+ cfg2 := cfg1
390
+ cfg2 .Versions = slices .Clone (cfg2 .Versions )
391
+ cfg2 .Versions [0 ].TerraformVariables = []testAccTemplateKeyValueConfig {
392
+ {
393
+ Key : PtrTo ("name" ),
394
+ Value : PtrTo ("world2" ),
395
+ },
396
+ }
397
+
398
+ resource .Test (t , resource.TestCase {
399
+ PreCheck : func () { testAccPreCheck (t ) },
400
+ IsUnitTest : true ,
401
+ ProtoV6ProviderFactories : testAccProtoV6ProviderFactories ,
402
+ Steps : []resource.TestStep {
403
+ {
404
+ Config : cfg1 .String (t ),
405
+ Check : resource .ComposeAggregateTestCheckFunc (
406
+ testAccCheckNumTemplateVersions (ctx , client , 1 ),
407
+ ),
408
+ },
409
+ {
410
+ Config : cfg2 .String (t ),
411
+ Check : resource .ComposeAggregateTestCheckFunc (
412
+ testAccCheckNumTemplateVersions (ctx , client , 2 ),
413
+ ),
414
+ },
346
415
},
347
416
})
348
417
})
@@ -779,14 +848,16 @@ func TestReconcileVersionIDs(t *testing.T) {
779
848
Name : "IdenticalDontRename" ,
780
849
planVersions : []TemplateVersion {
781
850
{
782
- Name : types .StringValue ("foo" ),
783
- DirectoryHash : types .StringValue ("aaa" ),
784
- ID : NewUUIDUnknown (),
851
+ Name : types .StringValue ("foo" ),
852
+ DirectoryHash : types .StringValue ("aaa" ),
853
+ ID : NewUUIDUnknown (),
854
+ TerraformVariables : []Variable {},
785
855
},
786
856
{
787
- Name : types .StringValue ("bar" ),
788
- DirectoryHash : types .StringValue ("aaa" ),
789
- ID : NewUUIDUnknown (),
857
+ Name : types .StringValue ("bar" ),
858
+ DirectoryHash : types .StringValue ("aaa" ),
859
+ ID : NewUUIDUnknown (),
860
+ TerraformVariables : []Variable {},
790
861
},
791
862
},
792
863
configVersions : []TemplateVersion {
@@ -800,36 +871,41 @@ func TestReconcileVersionIDs(t *testing.T) {
800
871
inputState : map [string ][]PreviousTemplateVersion {
801
872
"aaa" : {
802
873
{
803
- ID : aUUID ,
804
- Name : "bar" ,
874
+ ID : aUUID ,
875
+ Name : "bar" ,
876
+ TFVars : map [string ]string {},
805
877
},
806
878
},
807
879
},
808
880
expectedVersions : []TemplateVersion {
809
881
{
810
- Name : types .StringValue ("foo" ),
811
- DirectoryHash : types .StringValue ("aaa" ),
812
- ID : NewUUIDUnknown (),
882
+ Name : types .StringValue ("foo" ),
883
+ DirectoryHash : types .StringValue ("aaa" ),
884
+ ID : NewUUIDUnknown (),
885
+ TerraformVariables : []Variable {},
813
886
},
814
887
{
815
- Name : types .StringValue ("bar" ),
816
- DirectoryHash : types .StringValue ("aaa" ),
817
- ID : UUIDValue (aUUID ),
888
+ Name : types .StringValue ("bar" ),
889
+ DirectoryHash : types .StringValue ("aaa" ),
890
+ ID : UUIDValue (aUUID ),
891
+ TerraformVariables : []Variable {},
818
892
},
819
893
},
820
894
},
821
895
{
822
896
Name : "IdenticalRenameFirst" ,
823
897
planVersions : []TemplateVersion {
824
898
{
825
- Name : types .StringValue ("foo" ),
826
- DirectoryHash : types .StringValue ("aaa" ),
827
- ID : NewUUIDUnknown (),
899
+ Name : types .StringValue ("foo" ),
900
+ DirectoryHash : types .StringValue ("aaa" ),
901
+ ID : NewUUIDUnknown (),
902
+ TerraformVariables : []Variable {},
828
903
},
829
904
{
830
- Name : types .StringValue ("bar" ),
831
- DirectoryHash : types .StringValue ("aaa" ),
832
- ID : NewUUIDUnknown (),
905
+ Name : types .StringValue ("bar" ),
906
+ DirectoryHash : types .StringValue ("aaa" ),
907
+ ID : NewUUIDUnknown (),
908
+ TerraformVariables : []Variable {},
833
909
},
834
910
},
835
911
configVersions : []TemplateVersion {
@@ -843,36 +919,41 @@ func TestReconcileVersionIDs(t *testing.T) {
843
919
inputState : map [string ][]PreviousTemplateVersion {
844
920
"aaa" : {
845
921
{
846
- ID : aUUID ,
847
- Name : "baz" ,
922
+ ID : aUUID ,
923
+ Name : "baz" ,
924
+ TFVars : map [string ]string {},
848
925
},
849
926
},
850
927
},
851
928
expectedVersions : []TemplateVersion {
852
929
{
853
- Name : types .StringValue ("foo" ),
854
- DirectoryHash : types .StringValue ("aaa" ),
855
- ID : UUIDValue (aUUID ),
930
+ Name : types .StringValue ("foo" ),
931
+ DirectoryHash : types .StringValue ("aaa" ),
932
+ ID : UUIDValue (aUUID ),
933
+ TerraformVariables : []Variable {},
856
934
},
857
935
{
858
- Name : types .StringValue ("bar" ),
859
- DirectoryHash : types .StringValue ("aaa" ),
860
- ID : NewUUIDUnknown (),
936
+ Name : types .StringValue ("bar" ),
937
+ DirectoryHash : types .StringValue ("aaa" ),
938
+ ID : NewUUIDUnknown (),
939
+ TerraformVariables : []Variable {},
861
940
},
862
941
},
863
942
},
864
943
{
865
944
Name : "IdenticalHashesInState" ,
866
945
planVersions : []TemplateVersion {
867
946
{
868
- Name : types .StringValue ("foo" ),
869
- DirectoryHash : types .StringValue ("aaa" ),
870
- ID : NewUUIDUnknown (),
947
+ Name : types .StringValue ("foo" ),
948
+ DirectoryHash : types .StringValue ("aaa" ),
949
+ ID : NewUUIDUnknown (),
950
+ TerraformVariables : []Variable {},
871
951
},
872
952
{
873
- Name : types .StringValue ("bar" ),
874
- DirectoryHash : types .StringValue ("aaa" ),
875
- ID : NewUUIDUnknown (),
953
+ Name : types .StringValue ("bar" ),
954
+ DirectoryHash : types .StringValue ("aaa" ),
955
+ ID : NewUUIDUnknown (),
956
+ TerraformVariables : []Variable {},
876
957
},
877
958
},
878
959
configVersions : []TemplateVersion {
@@ -886,40 +967,46 @@ func TestReconcileVersionIDs(t *testing.T) {
886
967
inputState : map [string ][]PreviousTemplateVersion {
887
968
"aaa" : {
888
969
{
889
- ID : aUUID ,
890
- Name : "qux" ,
970
+ ID : aUUID ,
971
+ Name : "qux" ,
972
+ TFVars : map [string ]string {},
891
973
},
892
974
{
893
- ID : bUUID ,
894
- Name : "baz" ,
975
+ ID : bUUID ,
976
+ Name : "baz" ,
977
+ TFVars : map [string ]string {},
895
978
},
896
979
},
897
980
},
898
981
expectedVersions : []TemplateVersion {
899
982
{
900
- Name : types .StringValue ("foo" ),
901
- DirectoryHash : types .StringValue ("aaa" ),
902
- ID : UUIDValue (aUUID ),
983
+ Name : types .StringValue ("foo" ),
984
+ DirectoryHash : types .StringValue ("aaa" ),
985
+ ID : UUIDValue (aUUID ),
986
+ TerraformVariables : []Variable {},
903
987
},
904
988
{
905
- Name : types .StringValue ("bar" ),
906
- DirectoryHash : types .StringValue ("aaa" ),
907
- ID : UUIDValue (bUUID ),
989
+ Name : types .StringValue ("bar" ),
990
+ DirectoryHash : types .StringValue ("aaa" ),
991
+ ID : UUIDValue (bUUID ),
992
+ TerraformVariables : []Variable {},
908
993
},
909
994
},
910
995
},
911
996
{
912
997
Name : "UnknownUsesStateInOrder" ,
913
998
planVersions : []TemplateVersion {
914
999
{
915
- Name : types .StringValue ("foo" ),
916
- DirectoryHash : types .StringValue ("aaa" ),
917
- ID : NewUUIDUnknown (),
1000
+ Name : types .StringValue ("foo" ),
1001
+ DirectoryHash : types .StringValue ("aaa" ),
1002
+ ID : NewUUIDUnknown (),
1003
+ TerraformVariables : []Variable {},
918
1004
},
919
1005
{
920
- Name : types .StringUnknown (),
921
- DirectoryHash : types .StringValue ("aaa" ),
922
- ID : NewUUIDUnknown (),
1006
+ Name : types .StringUnknown (),
1007
+ DirectoryHash : types .StringValue ("aaa" ),
1008
+ ID : NewUUIDUnknown (),
1009
+ TerraformVariables : []Variable {},
923
1010
},
924
1011
},
925
1012
configVersions : []TemplateVersion {
@@ -933,55 +1020,152 @@ func TestReconcileVersionIDs(t *testing.T) {
933
1020
inputState : map [string ][]PreviousTemplateVersion {
934
1021
"aaa" : {
935
1022
{
936
- ID : aUUID ,
937
- Name : "qux" ,
1023
+ ID : aUUID ,
1024
+ Name : "qux" ,
1025
+ TFVars : map [string ]string {},
938
1026
},
939
1027
{
940
- ID : bUUID ,
941
- Name : "baz" ,
1028
+ ID : bUUID ,
1029
+ Name : "baz" ,
1030
+ TFVars : map [string ]string {},
942
1031
},
943
1032
},
944
1033
},
945
1034
expectedVersions : []TemplateVersion {
1035
+ {
1036
+ Name : types .StringValue ("foo" ),
1037
+ DirectoryHash : types .StringValue ("aaa" ),
1038
+ ID : UUIDValue (aUUID ),
1039
+ TerraformVariables : []Variable {},
1040
+ },
1041
+ {
1042
+ Name : types .StringValue ("baz" ),
1043
+ DirectoryHash : types .StringValue ("aaa" ),
1044
+ ID : UUIDValue (bUUID ),
1045
+ TerraformVariables : []Variable {},
1046
+ },
1047
+ },
1048
+ },
1049
+ {
1050
+ Name : "NewVersionNewRandomName" ,
1051
+ planVersions : []TemplateVersion {
1052
+ {
1053
+ Name : types .StringValue ("weird_draught12" ),
1054
+ DirectoryHash : types .StringValue ("bbb" ),
1055
+ ID : UUIDValue (aUUID ),
1056
+ TerraformVariables : []Variable {},
1057
+ },
1058
+ },
1059
+ configVersions : []TemplateVersion {
1060
+ {
1061
+ Name : types .StringNull (),
1062
+ },
1063
+ },
1064
+ inputState : map [string ][]PreviousTemplateVersion {
1065
+ "aaa" : {
1066
+ {
1067
+ ID : aUUID ,
1068
+ Name : "weird_draught12" ,
1069
+ TFVars : map [string ]string {},
1070
+ },
1071
+ },
1072
+ },
1073
+ expectedVersions : []TemplateVersion {
1074
+ {
1075
+ Name : types .StringUnknown (),
1076
+ DirectoryHash : types .StringValue ("bbb" ),
1077
+ ID : NewUUIDUnknown (),
1078
+ TerraformVariables : []Variable {},
1079
+ },
1080
+ },
1081
+ },
1082
+ {
1083
+ Name : "IdenticalNewVars" ,
1084
+ planVersions : []TemplateVersion {
946
1085
{
947
1086
Name : types .StringValue ("foo" ),
948
1087
DirectoryHash : types .StringValue ("aaa" ),
949
1088
ID : UUIDValue (aUUID ),
1089
+ TerraformVariables : []Variable {
1090
+ {
1091
+ Name : types .StringValue ("foo" ),
1092
+ Value : types .StringValue ("bar" ),
1093
+ },
1094
+ },
950
1095
},
1096
+ },
1097
+ configVersions : []TemplateVersion {
951
1098
{
952
- Name : types .StringValue ("baz" ),
1099
+ Name : types .StringValue ("foo" ),
1100
+ },
1101
+ },
1102
+ inputState : map [string ][]PreviousTemplateVersion {
1103
+ "aaa" : {
1104
+ {
1105
+ ID : aUUID ,
1106
+ Name : "foo" ,
1107
+ TFVars : map [string ]string {
1108
+ "foo" : "foo" ,
1109
+ },
1110
+ },
1111
+ },
1112
+ },
1113
+ expectedVersions : []TemplateVersion {
1114
+ {
1115
+ Name : types .StringValue ("foo" ),
953
1116
DirectoryHash : types .StringValue ("aaa" ),
954
- ID : UUIDValue (bUUID ),
1117
+ ID : NewUUIDUnknown (),
1118
+ TerraformVariables : []Variable {
1119
+ {
1120
+ Name : types .StringValue ("foo" ),
1121
+ Value : types .StringValue ("bar" ),
1122
+ },
1123
+ },
955
1124
},
956
1125
},
957
1126
},
958
1127
{
959
- Name : "NewVersionNewRandomName " ,
1128
+ Name : "IdenticalSameVars " ,
960
1129
planVersions : []TemplateVersion {
961
1130
{
962
- Name : types .StringValue ("weird_draught12 " ),
963
- DirectoryHash : types .StringValue ("bbb " ),
1131
+ Name : types .StringValue ("foo " ),
1132
+ DirectoryHash : types .StringValue ("aaa " ),
964
1133
ID : UUIDValue (aUUID ),
1134
+ TerraformVariables : []Variable {
1135
+ {
1136
+ Name : types .StringValue ("foo" ),
1137
+ Value : types .StringValue ("bar" ),
1138
+ },
1139
+ },
965
1140
},
966
1141
},
967
1142
configVersions : []TemplateVersion {
968
1143
{
969
- Name : types .StringNull ( ),
1144
+ Name : types .StringValue ( "foo" ),
970
1145
},
971
1146
},
972
1147
inputState : map [string ][]PreviousTemplateVersion {
973
1148
"aaa" : {
974
1149
{
975
1150
ID : aUUID ,
976
- Name : "weird_draught12" ,
1151
+ Name : "foo" ,
1152
+ TFVars : map [string ]string {
1153
+ "foo" : "bar" ,
1154
+ },
977
1155
},
978
1156
},
979
1157
},
980
1158
expectedVersions : []TemplateVersion {
981
1159
{
982
- Name : types .StringUnknown (),
983
- DirectoryHash : types .StringValue ("bbb" ),
984
- ID : NewUUIDUnknown (),
1160
+ Name : types .StringValue ("foo" ),
1161
+ DirectoryHash : types .StringValue ("aaa" ),
1162
+ ID : UUIDValue (aUUID ),
1163
+ TerraformVariables : []Variable {
1164
+ {
1165
+ Name : types .StringValue ("foo" ),
1166
+ Value : types .StringValue ("bar" ),
1167
+ },
1168
+ },
985
1169
},
986
1170
},
987
1171
},
0 commit comments