@@ -21,17 +21,41 @@ import (
2121)
2222
2323var (
24- maxTestName = "acc-" + acctest .RandStringFromCharSet (4 , acctest .CharSetAlpha )
24+ minTestName = "acc-min" + acctest .RandStringFromCharSet (3 , acctest .CharSetAlpha )
25+ maxTestName = "acc-max" + acctest .RandStringFromCharSet (3 , acctest .CharSetAlpha )
2526)
2627
2728var (
29+ //go:embed testdata/resource-min.tf
30+ resourceMin string
31+
2832 //go:embed testdata/resource-max.tf
2933 resourceMax string
3034)
35+
36+ var testConfigVarsMin = config.Variables {
37+ "project_id" : config .StringVariable (testutil .ProjectId ),
38+ "organization_id" : config .StringVariable (testutil .OrganizationId ),
39+ "name" : config .StringVariable (maxTestName ),
40+ "nodepool_availability_zone1" : config .StringVariable ("eu01-m" ),
41+ "nodepool_machine_type" : config .StringVariable ("g1.2" ),
42+ "nodepool_minimum" : config .StringVariable ("1" ),
43+ "nodepool_maximum" : config .StringVariable ("2" ),
44+ "nodepool_name" : config .StringVariable ("np-acc-test" ),
45+ "kubernetes_version_min" : config .StringVariable ("1.31.8" ),
46+ "maintenance_enable_machine_image_version_updates" : config .StringVariable ("true" ),
47+ "maintenance_enable_kubernetes_version_updates" : config .StringVariable ("true" ),
48+ "maintenance_start" : config .StringVariable ("02:00:00+01:00" ),
49+ "maintenance_end" : config .StringVariable ("04:00:00+01:00" ),
50+ "region" : config .StringVariable ("eu01" ),
51+ "dns_zone_name" : config .StringVariable ("acc-" + acctest .RandStringFromCharSet (6 , acctest .CharSetAlpha )),
52+ "dns_name" : config .StringVariable ("acc-" + acctest .RandStringFromCharSet (6 , acctest .CharSetAlpha ) + ".test" ),
53+ }
54+
3155var testConfigVarsMax = config.Variables {
3256 "project_id" : config .StringVariable (testutil .ProjectId ),
3357 "organization_id" : config .StringVariable (testutil .OrganizationId ),
34- "name" : config .StringVariable (maxTestName ),
58+ "name" : config .StringVariable (minTestName ),
3559 "nodepool_availability_zone1" : config .StringVariable ("eu01-m" ),
3660 "nodepool_machine_type" : config .StringVariable ("g1.2" ),
3761 "nodepool_minimum" : config .StringVariable ("1" ),
@@ -68,6 +92,13 @@ var testConfigVarsMax = config.Variables{
6892 "dns_name" : config .StringVariable ("acc-" + acctest .RandStringFromCharSet (6 , acctest .CharSetAlpha ) + ".test" ),
6993}
7094
95+ func configVarsMinUpdated () config.Variables {
96+ updatedConfig := maps .Clone (testConfigVarsMax )
97+ updatedConfig ["kubernetes_version_min" ] = config .StringVariable ("1.31" )
98+
99+ return updatedConfig
100+ }
101+
71102func configVarsMaxUpdated () config.Variables {
72103 updatedConfig := maps .Clone (testConfigVarsMax )
73104 updatedConfig ["kubernetes_version_min" ] = config .StringVariable ("1.31" )
@@ -76,6 +107,121 @@ func configVarsMaxUpdated() config.Variables {
76107
77108 return updatedConfig
78109}
110+ func TestAccSKEMin (t * testing.T ) {
111+ resource .Test (t , resource.TestCase {
112+ ProtoV6ProviderFactories : testutil .TestAccProtoV6ProviderFactories ,
113+ CheckDestroy : testAccCheckSKEDestroy ,
114+ Steps : []resource.TestStep {
115+
116+ // 1) Creation
117+ {
118+ Config : testutil .SKEProviderConfig () + "\n " + resourceMin ,
119+ ConfigVariables : testConfigVarsMin ,
120+ Check : resource .ComposeAggregateTestCheckFunc (
121+ // cluster data
122+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "project_id" , testutil .ConvertConfigVariable (testConfigVarsMin ["project_id" ])),
123+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "name" , testutil .ConvertConfigVariable (testConfigVarsMin ["name" ])),
124+
125+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "node_pools.#" , "1" ),
126+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "node_pools.0.availability_zones.#" , "1" ),
127+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "node_pools.0.availability_zones.0" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_availability_zone1" ])),
128+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "node_pools.0.machine_type" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_machine_type" ])),
129+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "node_pools.0.maximum" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_maximum" ])),
130+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "node_pools.0.minimum" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_minimum" ])),
131+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "node_pools.0.name" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_name" ])),
132+ resource .TestCheckResourceAttrSet ("stackit_ske_cluster.cluster" , "node_pools.0.os_version_used" ),
133+ resource .TestCheckResourceAttrSet ("stackit_ske_cluster.cluster" , "region" ),
134+
135+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "egress_address_ranges.#" , "1" ),
136+ resource .TestCheckResourceAttrSet ("stackit_ske_cluster.cluster" , "egress_address_ranges.0" ),
137+ resource .TestCheckResourceAttrSet ("stackit_ske_cluster.cluster" , "kubernetes_version_used" ),
138+
139+ // Kubeconfig
140+ resource .TestCheckResourceAttrPair (
141+ "stackit_ske_kubeconfig.kubeconfig" , "project_id" ,
142+ "stackit_ske_cluster.cluster" , "project_id" ,
143+ ),
144+ resource .TestCheckResourceAttrPair (
145+ "stackit_ske_kubeconfig.kubeconfig" , "cluster_name" ,
146+ "stackit_ske_cluster.cluster" , "name" ,
147+ ),
148+ ),
149+ },
150+ // 2) Data source
151+ {
152+ Config : resourceMin ,
153+ ConfigVariables : testConfigVarsMin ,
154+ Check : resource .ComposeAggregateTestCheckFunc (
155+
156+ // cluster data
157+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "id" , fmt .Sprintf ("%s,%s,%s" ,
158+ testutil .ConvertConfigVariable (testConfigVarsMin ["project_id" ]),
159+ testutil .Region ,
160+ testutil .ConvertConfigVariable (testConfigVarsMin ["name" ]),
161+ )),
162+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.#" , "1" ),
163+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.availability_zones.#" , "1" ),
164+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.availability_zones.0" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_availability_zone1" ])),
165+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.machine_type" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_machine_type" ])),
166+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.maximum" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_maximum" ])),
167+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.minimum" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_minimum" ])),
168+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.name" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_name" ])),
169+
170+ resource .TestCheckResourceAttrSet ("data.stackit_ske_cluster.cluster" , "kubernetes_version_used" ),
171+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "egress_address_ranges.#" , "1" ),
172+ resource .TestCheckResourceAttrSet ("data.stackit_ske_cluster.cluster" , "egress_address_ranges.0" ),
173+ resource .TestCheckResourceAttrSet ("data.stackit_ske_cluster.cluster" , "kubernetes_version_used" ),
174+ ),
175+ },
176+ // 3) Import cluster
177+ {
178+ ResourceName : "stackit_ske_cluster.cluster" ,
179+ ConfigVariables : testConfigVarsMin ,
180+ ImportStateIdFunc : func (s * terraform.State ) (string , error ) {
181+ r , ok := s .RootModule ().Resources ["stackit_ske_cluster.cluster" ]
182+ if ! ok {
183+ return "" , fmt .Errorf ("couldn't find resource stackit_ske_cluster.cluster" )
184+ }
185+ _ , ok = r .Primary .Attributes ["project_id" ]
186+ if ! ok {
187+ return "" , fmt .Errorf ("couldn't find attribute project_id" )
188+ }
189+ name , ok := r .Primary .Attributes ["name" ]
190+ if ! ok {
191+ return "" , fmt .Errorf ("couldn't find attribute name" )
192+ }
193+ return fmt .Sprintf ("%s,%s,%s" , testutil .ProjectId , testutil .Region , name ), nil
194+ },
195+ ImportState : true ,
196+ ImportStateVerify : true ,
197+ // The fields are not provided in the SKE API when disabled, although set actively.
198+ ImportStateVerifyIgnore : []string {"kubernetes_version_min" , "node_pools.0.os_version_min" , "extensions.argus.%" , "extensions.argus.argus_instance_id" , "extensions.argus.enabled" },
199+ },
200+ // 4) Update kubernetes version, OS version and maintenance end, downgrade of kubernetes version
201+ {
202+ Config : resourceMin ,
203+ ConfigVariables : configVarsMinUpdated (),
204+ Check : resource .ComposeAggregateTestCheckFunc (
205+ // cluster data
206+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.#" , "1" ),
207+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.availability_zones.#" , "1" ),
208+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.availability_zones.0" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_availability_zone1" ])),
209+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.machine_type" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_machine_type" ])),
210+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.maximum" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_maximum" ])),
211+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.minimum" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_minimum" ])),
212+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "node_pools.0.name" , testutil .ConvertConfigVariable (testConfigVarsMin ["nodepool_name" ])),
213+
214+ resource .TestCheckResourceAttrSet ("data.stackit_ske_cluster.cluster" , "kubernetes_version_used" ),
215+ resource .TestCheckResourceAttr ("data.stackit_ske_cluster.cluster" , "egress_address_ranges.#" , "1" ),
216+ resource .TestCheckResourceAttrSet ("data.stackit_ske_cluster.cluster" , "egress_address_ranges.0" ),
217+ resource .TestCheckResourceAttrSet ("data.stackit_ske_cluster.cluster" , "kubernetes_version_used" ),
218+ ),
219+ },
220+ // Deletion is done by the framework implicitly
221+ },
222+ })
223+ }
224+
79225func TestAccSKEMax (t * testing.T ) {
80226 resource .Test (t , resource.TestCase {
81227 ProtoV6ProviderFactories : testutil .TestAccProtoV6ProviderFactories ,
@@ -234,11 +380,11 @@ func TestAccSKEMax(t *testing.T) {
234380 },
235381 // 4) Update kubernetes version, OS version and maintenance end, downgrade of kubernetes version
236382 {
237- Config : resourceMax ,
383+ Config : resourceMax ,
238384 ConfigVariables : configVarsMaxUpdated (),
239- Check : resource .ComposeAggregateTestCheckFunc (
240- // cluster data
241- resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "project_id" , testutil .ConvertConfigVariable (configVarsMaxUpdated ()["project_id" ])),
385+ Check : resource .ComposeAggregateTestCheckFunc (
386+ // cluster data
387+ resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "project_id" , testutil .ConvertConfigVariable (configVarsMaxUpdated ()["project_id" ])),
242388 resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "name" , testutil .ConvertConfigVariable (configVarsMaxUpdated ()["name" ])),
243389
244390 resource .TestCheckResourceAttr ("stackit_ske_cluster.cluster" , "node_pools.#" , "1" ),
0 commit comments