Skip to content

Commit 995e614

Browse files
authored
feat: Supports GCP for mongodbatlas_cloud_provider_access_authorization resource (#3639)
* gcp for authorization resource * cloud provider * gcp is computed * remove max items * set gcp * remove gcp from if in update * add missing azure attribute in docs * explain gcp update
1 parent b31e7c2 commit 995e614

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

.changelog/3639.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/mongodbatlas_cloud_provider_access_authorization: Supports GCP cloud provider
3+
```

docs/resources/cloud_provider_access.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,18 @@ resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" {
135135
Conditional
136136
* `aws`
137137
* `iam_assumed_role_arn` - (Required) ARN of the IAM Role that Atlas assumes when accessing resources in your AWS account. This value is required after the creation (register of the role) as part of [Set Up Unified AWS Access](https://docs.atlas.mongodb.com/security/set-up-unified-aws-access/#set-up-unified-aws-access).
138-
138+
* `azure`
139+
* `atlas_azure_app_id` - (Required) Azure Active Directory Application ID of Atlas.
140+
* `service_principal_id` - (Required) UUID string that identifies the Azure Service Principal.
141+
* `tenant_id` - (Required) UUID String that identifies the Azure Active Directory Tenant ID.
139142

140143
## Attributes Reference
141144

142145
* `id` - Unique identifier used by terraform for internal management.
143146
* `authorized_date` - Date on which this role was authorized.
144147
* `feature_usages` - Atlas features this AWS IAM role is linked to.
148+
* `gcp`
149+
* `service_account_for_atlas` - Email address for the Google Service Account created by Atlas.
145150

146151

147152

internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ func ResourceAuthorization() *schema.Resource {
7070
},
7171
},
7272
},
73+
"gcp": {
74+
Type: schema.TypeList,
75+
Computed: true,
76+
Elem: &schema.Resource{
77+
Schema: map[string]*schema.Schema{
78+
"service_account_for_atlas": {
79+
Type: schema.TypeString,
80+
Computed: true,
81+
},
82+
},
83+
},
84+
},
7385
"feature_usages": {
7486
Type: schema.TypeList,
7587
Elem: featureUsagesSchema(),
@@ -168,6 +180,10 @@ func resourceCloudProviderAccessAuthorizationUpdate(ctx context.Context, d *sche
168180
}
169181

170182
if d.HasChange("aws") || d.HasChange("azure") {
183+
// Re-authorize the role with updated AWS or Azure configuration.
184+
// GCP authorization only requires a role ID and has no additional configuration to update.
185+
// Therefore, "updating" a GCP role would effectively be creating a new authorization,
186+
// which should be handled by creating a new resource rather than updating an existing one.
171187
return authorizeRole(ctx, conn, d, projectID, targetRole)
172188
}
173189

@@ -186,6 +202,7 @@ func roleToSchemaAuthorization(role *admin.CloudProviderAccessRole) map[string]a
186202
"iam_assumed_role_arn": role.GetIamAssumedRoleArn(),
187203
}},
188204
"authorized_date": conversion.TimeToString(role.GetAuthorizedDate()),
205+
"gcp": []any{map[string]any{}},
189206
}
190207

191208
if role.ProviderName == "AZURE" {
@@ -197,6 +214,15 @@ func roleToSchemaAuthorization(role *admin.CloudProviderAccessRole) map[string]a
197214
"tenant_id": role.GetTenantId(),
198215
}},
199216
"authorized_date": conversion.TimeToString(role.GetAuthorizedDate()),
217+
"gcp": []any{map[string]any{}},
218+
}
219+
}
220+
if role.ProviderName == "GCP" {
221+
out = map[string]any{
222+
"role_id": role.GetRoleId(),
223+
"gcp": []any{map[string]any{
224+
"service_account_for_atlas": role.GetGcpServiceAccountForAtlas(),
225+
}},
200226
}
201227
}
202228

@@ -281,6 +307,7 @@ func authorizeRole(ctx context.Context, client *admin.APIClient, d *schema.Resou
281307
req.SetServicePrincipalId(targetRole.GetServicePrincipalId())
282308
roleID = targetRole.GetId()
283309
}
310+
// No specific GCP config is needed, only providerName and roleID are needed
284311

285312
var role *admin.CloudProviderAccessRole
286313
var err error

0 commit comments

Comments
 (0)