Skip to content

Commit 16529c5

Browse files
feat(onboarding): Add validation support for GCP CDR onboarding (#490)
* feat(onboarding): Add validation support for GCP CDR onboarding Change summary: ----------------- 1. Support for GCP CDR validation during onboarding using WIF. Mainly fixed the case for metadata population when WIF is passed. 2. Added GCP CDR tests 3. Modified the structure and organization of acceptance test suite for sysdig_secure_cloud_auth_account resource. Testing done: --------------- Validated the acceptance tests against staging. * Remove unnecessary log * Update acc test * Fix comment
1 parent ea4be98 commit 16529c5

File tree

2 files changed

+252
-176
lines changed

2 files changed

+252
-176
lines changed

sysdig/resource_sysdig_secure_cloud_auth_account.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -387,25 +387,26 @@ func constructAccountComponents(data *schema.ResourceData) []*cloudauth.AccountC
387387
if data.Get(SchemaCloudProviderType).(string) == cloudauth.Provider_PROVIDER_GCP.String() {
388388
spGcp := &internalServicePrincipalMetadata{}
389389
err = json.Unmarshal([]byte(value.(string)), spGcp)
390+
// special handling if GCP service principal key is present, decode and unmarshal it before populating all the metadata
391+
var spGcpKey *cloudauth.ServicePrincipalMetadata_GCP_Key
390392
if len(spGcp.Gcp.Key) > 0 {
391393
var spGcpKeyBytes []byte
392394
spGcpKeyBytes, err = base64.StdEncoding.DecodeString(spGcp.Gcp.Key)
393395
if err != nil {
394396
diag.FromErr(err)
395397
}
396-
spGcpKey := &cloudauth.ServicePrincipalMetadata_GCP_Key{}
397-
err = json.Unmarshal(spGcpKeyBytes, spGcpKey)
398-
component.Metadata = &cloudauth.AccountComponent_ServicePrincipalMetadata{
399-
ServicePrincipalMetadata: &cloudauth.ServicePrincipalMetadata{
400-
Provider: &cloudauth.ServicePrincipalMetadata_Gcp{
401-
Gcp: &cloudauth.ServicePrincipalMetadata_GCP{
402-
Key: spGcpKey,
403-
WorkloadIdentityFederation: spGcp.Gcp.WorkloadIdentityFederation,
404-
Email: spGcp.Gcp.Email,
405-
},
398+
err = json.Unmarshal(spGcpKeyBytes, &spGcpKey)
399+
}
400+
component.Metadata = &cloudauth.AccountComponent_ServicePrincipalMetadata{
401+
ServicePrincipalMetadata: &cloudauth.ServicePrincipalMetadata{
402+
Provider: &cloudauth.ServicePrincipalMetadata_Gcp{
403+
Gcp: &cloudauth.ServicePrincipalMetadata_GCP{
404+
Key: spGcpKey,
405+
WorkloadIdentityFederation: spGcp.Gcp.WorkloadIdentityFederation,
406+
Email: spGcp.Gcp.Email,
406407
},
407408
},
408-
}
409+
},
409410
}
410411
}
411412
case SchemaWebhookDatasourceMetadata:

0 commit comments

Comments
 (0)