@@ -20,19 +20,22 @@ import (
2020
2121// Instance resource data
2222var instanceResource = map [string ]string {
23- "project_id" : testutil .ProjectId ,
24- "name" : fmt .Sprintf ("tf-acc-%s" , acctest .RandStringFromCharSet (7 , acctest .CharSetAlphaNum )),
25- "acl" : "192.168.0.0/16" ,
26- "flavor_cpu" : "2" ,
27- "flavor_ram" : "4" ,
28- "flavor_description" : "Small, Compute optimized" ,
29- "replicas" : "1" ,
30- "storage_class" : "premium-perf2-mongodb" ,
31- "storage_size" : "10" ,
32- "version" : "5.0" ,
33- "version_updated" : "6.0" ,
34- "options_type" : "Single" ,
35- "flavor_id" : "2.4" ,
23+ "project_id" : testutil .ProjectId ,
24+ "name" : fmt .Sprintf ("tf-acc-%s" , acctest .RandStringFromCharSet (7 , acctest .CharSetAlphaNum )),
25+ "acl" : "192.168.0.0/16" ,
26+ "flavor_cpu" : "2" ,
27+ "flavor_ram" : "4" ,
28+ "flavor_description" : "Small, Compute optimized" ,
29+ "replicas" : "1" ,
30+ "storage_class" : "premium-perf2-mongodb" ,
31+ "storage_size" : "10" ,
32+ "version" : "5.0" ,
33+ "version_updated" : "6.0" ,
34+ "options_type" : "Single" ,
35+ "flavor_id" : "2.4" ,
36+ "backup_schedule" : "00 6 * * *" ,
37+ "backup_schedule_updated" : "00 12 * * *" ,
38+ "backup_schedule_read" : "0 6 * * *" ,
3639}
3740
3841// User resource data
@@ -43,7 +46,7 @@ var userResource = map[string]string{
4346 "project_id" : instanceResource ["project_id" ],
4447}
4548
46- func configResources (version string ) string {
49+ func configResources (version , backupSchedule string ) string {
4750 return fmt .Sprintf (`
4851 %s
4952
@@ -64,6 +67,7 @@ func configResources(version string) string {
6467 options = {
6568 type = "%s"
6669 }
70+ backup_schedule = "%s"
6771 }
6872
6973 resource "stackit_mongodbflex_user" "user" {
@@ -85,6 +89,7 @@ func configResources(version string) string {
8589 instanceResource ["storage_size" ],
8690 version ,
8791 instanceResource ["options_type" ],
92+ backupSchedule ,
8893 userResource ["username" ],
8994 userResource ["role" ],
9095 userResource ["database" ],
@@ -98,7 +103,7 @@ func TestAccMongoDBFlexFlexResource(t *testing.T) {
98103 Steps : []resource.TestStep {
99104 // Creation
100105 {
101- Config : configResources (instanceResource ["version" ]),
106+ Config : configResources (instanceResource ["version" ], instanceResource [ "backup_schedule" ] ),
102107 Check : resource .ComposeAggregateTestCheckFunc (
103108 // Instance
104109 resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "project_id" , instanceResource ["project_id" ]),
@@ -115,6 +120,7 @@ func TestAccMongoDBFlexFlexResource(t *testing.T) {
115120 resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "storage.size" , instanceResource ["storage_size" ]),
116121 resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "version" , instanceResource ["version" ]),
117122 resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "options.type" , instanceResource ["options_type" ]),
123+ resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "backup_schedule" , instanceResource ["backup_schedule" ]),
118124
119125 // User
120126 resource .TestCheckResourceAttrPair (
@@ -147,7 +153,7 @@ func TestAccMongoDBFlexFlexResource(t *testing.T) {
147153 user_id = stackit_mongodbflex_user.user.user_id
148154 }
149155 ` ,
150- configResources (instanceResource ["version" ]),
156+ configResources (instanceResource ["version" ], instanceResource [ "backup_schedule" ] ),
151157 ),
152158 Check : resource .ComposeAggregateTestCheckFunc (
153159 // Instance data
@@ -174,6 +180,7 @@ func TestAccMongoDBFlexFlexResource(t *testing.T) {
174180 resource .TestCheckResourceAttr ("data.stackit_mongodbflex_instance.instance" , "flavor.ram" , instanceResource ["flavor_ram" ]),
175181 resource .TestCheckResourceAttr ("data.stackit_mongodbflex_instance.instance" , "replicas" , instanceResource ["replicas" ]),
176182 resource .TestCheckResourceAttr ("data.stackit_mongodbflex_instance.instance" , "options.type" , instanceResource ["options_type" ]),
183+ resource .TestCheckResourceAttr ("data.stackit_mongodbflex_instance.instance" , "backup_schedule" , instanceResource ["backup_schedule_read" ]),
177184
178185 // User data
179186 resource .TestCheckResourceAttr ("data.stackit_mongodbflex_user.user" , "project_id" , userResource ["project_id" ]),
@@ -201,8 +208,18 @@ func TestAccMongoDBFlexFlexResource(t *testing.T) {
201208
202209 return fmt .Sprintf ("%s,%s" , testutil .ProjectId , instanceId ), nil
203210 },
204- ImportState : true ,
205- ImportStateVerify : true ,
211+ ImportState : true ,
212+ ImportStateVerify : true ,
213+ ImportStateVerifyIgnore : []string {"backup_schedule" },
214+ ImportStateCheck : func (s []* terraform.InstanceState ) error {
215+ if len (s ) != 1 {
216+ return fmt .Errorf ("expected 1 state, got %d" , len (s ))
217+ }
218+ if s [0 ].Attributes ["backup_schedule" ] != instanceResource ["backup_schedule_read" ] {
219+ return fmt .Errorf ("expected backup_schedule %s, got %s" , instanceResource ["backup_schedule_read" ], s [0 ].Attributes ["backup_schedule" ])
220+ }
221+ return nil
222+ },
206223 },
207224 {
208225 ResourceName : "stackit_mongodbflex_user.user" ,
@@ -228,7 +245,7 @@ func TestAccMongoDBFlexFlexResource(t *testing.T) {
228245 },
229246 // Update
230247 {
231- Config : configResources (instanceResource ["version_updated" ]),
248+ Config : configResources (instanceResource ["version_updated" ], instanceResource [ "backup_schedule_updated" ] ),
232249 Check : resource .ComposeAggregateTestCheckFunc (
233250 // Instance data
234251 resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "project_id" , instanceResource ["project_id" ]),
@@ -245,6 +262,7 @@ func TestAccMongoDBFlexFlexResource(t *testing.T) {
245262 resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "storage.size" , instanceResource ["storage_size" ]),
246263 resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "version" , instanceResource ["version_updated" ]),
247264 resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "options.type" , instanceResource ["options_type" ]),
265+ resource .TestCheckResourceAttr ("stackit_mongodbflex_instance.instance" , "backup_schedule" , instanceResource ["backup_schedule_updated" ]),
248266 ),
249267 },
250268 // Deletion is done by the framework implicitly
0 commit comments