Skip to content

Commit 3099c5d

Browse files
authored
Add support for schema migration (#717)
1 parent 3f4615e commit 3099c5d

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

mongodbatlas/data_source_mongodbatlas_cloud_provider_access.go

+15
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,18 @@ func featureToSchema(feature *matlas.FeatureUsage) map[string]interface{} {
144144
"feature_id": feature.FeatureID,
145145
}
146146
}
147+
148+
func featureUsagesSchemaV0() *schema.Resource {
149+
return &schema.Resource{
150+
Schema: map[string]*schema.Schema{
151+
"feature_type": {
152+
Type: schema.TypeString,
153+
Computed: true,
154+
},
155+
"feature_id": {
156+
Type: schema.TypeString,
157+
Computed: true,
158+
},
159+
},
160+
}
161+
}

mongodbatlas/resource_mongodbatlas_cloud_provider_access.go

+58
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ func resourceMongoDBAtlasCloudProviderAccess() *schema.Resource {
6868
Computed: true,
6969
},
7070
},
71+
SchemaVersion: 1,
72+
StateUpgraders: []schema.StateUpgrader{
73+
{
74+
Type: resourceMongoDBAtlasCloudProviderAccessV0().CoreConfigSchema().ImpliedType(),
75+
Upgrade: resourceMongoDBAtlasCloudProviderAccessStateUpgradeV0,
76+
Version: 0,
77+
},
78+
},
7179
}
7280
}
7381

@@ -248,3 +256,53 @@ func splitCloudProviderAccessID(id string) (projectID, providerName, roleID stri
248256

249257
return
250258
}
259+
260+
func resourceMongoDBAtlasCloudProviderAccessV0() *schema.Resource {
261+
return &schema.Resource{
262+
Schema: map[string]*schema.Schema{
263+
"project_id": {
264+
Type: schema.TypeString,
265+
Required: true,
266+
},
267+
"provider_name": {
268+
Type: schema.TypeString,
269+
Required: true,
270+
ValidateFunc: validation.StringInSlice([]string{"AWS"}, false),
271+
},
272+
"atlas_aws_account_arn": {
273+
Type: schema.TypeString,
274+
Computed: true,
275+
},
276+
"atlas_assumed_role_external_id": {
277+
Type: schema.TypeString,
278+
Computed: true,
279+
},
280+
"authorized_date": {
281+
Type: schema.TypeString,
282+
Computed: true,
283+
},
284+
"created_date": {
285+
Type: schema.TypeString,
286+
Computed: true,
287+
},
288+
"iam_assumed_role_arn": {
289+
Type: schema.TypeString,
290+
Optional: true,
291+
},
292+
"role_id": {
293+
Type: schema.TypeString,
294+
Computed: true,
295+
},
296+
"feature_usages": {
297+
Type: schema.TypeList,
298+
Elem: featureUsagesSchemaV0(),
299+
Computed: true,
300+
},
301+
},
302+
}
303+
}
304+
305+
func resourceMongoDBAtlasCloudProviderAccessStateUpgradeV0(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
306+
rawState["feature_usages"] = []interface{}{map[string]interface{}{}}
307+
return rawState, nil
308+
}

0 commit comments

Comments
 (0)