Skip to content

Commit 89329f7

Browse files
fix(secure-onboarding) Fixing the resource schema during reads (#431)
Fix summary: -------------- Currently the provider reads and returns one of the fields in the resource schema with incorrect structure. This results in unexpected diff during terraform re-apply. - Fixing the interface conversion during reads for the same. - Also updated the acceptance tests accordingly to test this. Testing done: -------------- Validated this using TF Acceptance tests as well as e2e manually.
1 parent 4679633 commit 89329f7

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

sysdig/resource_sysdig_secure_cloud_auth_account.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -452,29 +452,24 @@ func cloudauthAccountFromResourceData(data *schema.ResourceData) *v2.CloudauthAc
452452
This helper function converts feature values from *cloudauth.AccountFeature to resource data schema.
453453
*/
454454

455-
func featureValuesToResourceData(name string, feature *cloudauth.AccountFeature) map[string]interface{} {
455+
func featureValuesToResourceData(feature *cloudauth.AccountFeature) map[string]interface{} {
456456
valuesMap := make(map[string]interface{})
457457

458458
valuesMap["type"] = feature.Type.String()
459459
valuesMap["enabled"] = feature.Enabled
460460
valuesMap["components"] = feature.Components
461461

462-
featureMap := map[string]interface{}{
463-
name: []map[string]interface{}{
464-
valuesMap,
465-
},
466-
}
467-
468-
return featureMap
462+
return valuesMap
469463
}
470464

471465
/*
472-
This helper function converts the features data from *cloudauth.AccountFeatures to resource data schema.
473-
This is needed to set the value in cloudauthAccountToResourceData().
466+
This helper function converts the features data from *cloudauth.AccountFeatures to resource data schema.
467+
This is needed to set the value in cloudauthAccountToResourceData().
474468
*/
475-
476-
func featureToResourceData(features *cloudauth.AccountFeatures) []map[string]interface{} {
477-
featureMap := []map[string]interface{}{}
469+
func featureToResourceData(features *cloudauth.AccountFeatures) []interface{} {
470+
// In the resource data, SchemaFeature field is a nested set[] of sets[] of individual features
471+
// Hence we need to return this uber level set[] to cloudauthAccountToResourceData
472+
featureMap := []interface{}{}
478473

479474
featureFields := map[string]*cloudauth.AccountFeature{
480475
SchemaSecureThreatDetection: features.SecureThreatDetection,
@@ -484,14 +479,23 @@ func featureToResourceData(features *cloudauth.AccountFeatures) []map[string]int
484479
SchemaSecureAgentlessScanning: features.SecureAgentlessScanning,
485480
}
486481

482+
allFeatures := make(map[string]interface{})
483+
featureBlock := make([]map[string]interface{}, 0)
487484
for name, feature := range featureFields {
488485
if feature != nil {
489-
value := featureValuesToResourceData(name, feature)
490-
featureMap = append(featureMap, value)
486+
value := featureValuesToResourceData(feature)
487+
featureBlock = append(featureBlock, value)
488+
489+
allFeatures[name] = featureBlock
491490
}
492491
}
493492

494-
return featureMap
493+
// return featureMap only if there is any features data from *cloudauth.AccountFeatures, else return nil
494+
if len(allFeatures) > 0 {
495+
featureMap = append(featureMap, allFeatures)
496+
return featureMap
497+
}
498+
return nil
495499
}
496500

497501
func cloudauthAccountToResourceData(data *schema.ResourceData, cloudAccount *v2.CloudauthAccountSecure) error {

sysdig/resource_sysdig_secure_cloud_auth_account_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ resource "sysdig_secure_cloud_auth_account" "sample-1" {
103103
enabled = "true"
104104
components = ["COMPONENT_SERVICE_PRINCIPAL/secure-posture"]
105105
}
106+
secure_identity_entitlement {
107+
enabled = true
108+
components = ["COMPONENT_SERVICE_PRINCIPAL/secure-posture"]
109+
}
106110
}
107111
component {
108112
type = "COMPONENT_SERVICE_PRINCIPAL"

sysdig/resource_sysdig_secure_organization_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ resource "sysdig_secure_cloud_auth_account" "sample" {
5353
enabled = "true"
5454
components = ["COMPONENT_SERVICE_PRINCIPAL/secure-posture"]
5555
}
56+
secure_identity_entitlement {
57+
enabled = true
58+
components = ["COMPONENT_SERVICE_PRINCIPAL/secure-posture"]
59+
}
5660
}
5761
component {
5862
type = "COMPONENT_SERVICE_PRINCIPAL"

0 commit comments

Comments
 (0)