Skip to content

Commit 1feea97

Browse files
Posture deployment resource addition to terraform (#9356) (#17085)
* add posture deployment resource * fix lint errors * Add unit tests * fix create test * make etag output only field * fix update test * add_project_number * change target resource description * add posture support * modify update test * fix update test * address review comments * fix spacing * modify posture fields * modify posture name description * fix the commented year * fix fields description * add reference * add failure message field * modify resource description * add example value of project number * fix posture update issue * fix lint issues * fix custom constraint diff * address review comments * fix spacing * fix tests * fix test location field * remove annotations * fix name description * remove annotation for revisionIdCustomizeDiff --------- [upstream:3588330a4feda5100cc4a585f7fef25c68a739a8] Signed-off-by: Modular Magician <[email protected]>
1 parent 17b403b commit 1feea97

10 files changed

+1120
-87
lines changed

.changelog/9356.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_securityposture_posture_deployment`
3+
```

google/provider/provider_mmv1_resources.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
380380
}
381381

382382
// Resources
383-
// Generated resources: 369
383+
// Generated resources: 370
384384
// Generated IAM resources: 222
385-
// Total generated resources: 591
385+
// Total generated resources: 592
386386
var generatedResources = map[string]*schema.Resource{
387387
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
388388
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -898,6 +898,7 @@ var generatedResources = map[string]*schema.Resource{
898898
"google_scc_source_iam_member": tpgiamresource.ResourceIamMember(securitycenter.SecurityCenterSourceIamSchema, securitycenter.SecurityCenterSourceIamUpdaterProducer, securitycenter.SecurityCenterSourceIdParseFunc),
899899
"google_scc_source_iam_policy": tpgiamresource.ResourceIamPolicy(securitycenter.SecurityCenterSourceIamSchema, securitycenter.SecurityCenterSourceIamUpdaterProducer, securitycenter.SecurityCenterSourceIdParseFunc),
900900
"google_securityposture_posture": securityposture.ResourceSecurityposturePosture(),
901+
"google_securityposture_posture_deployment": securityposture.ResourceSecurityposturePostureDeployment(),
901902
"google_endpoints_service_iam_binding": tpgiamresource.ResourceIamBinding(servicemanagement.ServiceManagementServiceIamSchema, servicemanagement.ServiceManagementServiceIamUpdaterProducer, servicemanagement.ServiceManagementServiceIdParseFunc),
902903
"google_endpoints_service_iam_member": tpgiamresource.ResourceIamMember(servicemanagement.ServiceManagementServiceIamSchema, servicemanagement.ServiceManagementServiceIamUpdaterProducer, servicemanagement.ServiceManagementServiceIdParseFunc),
903904
"google_endpoints_service_iam_policy": tpgiamresource.ResourceIamPolicy(servicemanagement.ServiceManagementServiceIamSchema, servicemanagement.ServiceManagementServiceIamUpdaterProducer, servicemanagement.ServiceManagementServiceIdParseFunc),

google/services/securityposture/resource_securityposture_posture.go

+2-72
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535

3636
// Compute revision_id for changes in posture fields.
3737
func revisionIdCustomizeDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
38-
if d.HasChanges("annotations", "description", "state", "policy_sets") {
38+
if d.HasChanges("description", "state", "policy_sets") {
3939
err := d.SetNewComputed("revision_id")
4040
if err != nil {
4141
return fmt.Errorf("Error re-setting revision_id: %s", err)
@@ -63,7 +63,6 @@ func ResourceSecurityposturePosture() *schema.Resource {
6363

6464
CustomizeDiff: customdiff.All(
6565
revisionIdCustomizeDiff,
66-
tpgresource.SetAnnotationsDiff,
6766
),
6867

6968
Schema: map[string]*schema.Schema{
@@ -92,17 +91,6 @@ func ResourceSecurityposturePosture() *schema.Resource {
9291
Description: `State of the posture. Update to state field should not be triggered along with
9392
with other field updates. Possible values: ["DEPRECATED", "DRAFT", "ACTIVE"]`,
9493
},
95-
"annotations": {
96-
Type: schema.TypeMap,
97-
Optional: true,
98-
Description: `Annotations is a key value map stored with a resource that
99-
may be set by external tools to store and retrieve arbitrary metadata.
100-
101-
102-
**Note**: This field is non-authoritative, and will only manage the annotations present in your configuration.
103-
Please refer to the field 'effective_annotations' for all of the annotations present on the resource.`,
104-
Elem: &schema.Schema{Type: schema.TypeString},
105-
},
10694
"description": {
10795
Type: schema.TypeString,
10896
Optional: true,
@@ -133,7 +121,7 @@ Please refer to the field 'effective_annotations' for all of the annotations pre
133121
"constraint": {
134122
Type: schema.TypeList,
135123
Required: true,
136-
Description: `Policy constraint definition.It can have the definition of one of following constraints: orgPolicyConstraint OrgPolicyConstraintCustom securityHealthAnalyticsModule securityHealthAnalyticsCustomModule`,
124+
Description: `Policy constraint definition.It can have the definition of one of following constraints: orgPolicyConstraint orgPolicyConstraintCustom securityHealthAnalyticsModule securityHealthAnalyticsCustomModule`,
137125
MaxItems: 1,
138126
Elem: &schema.Resource{
139127
Schema: map[string]*schema.Schema{
@@ -615,12 +603,6 @@ returned by this custom module.`,
615603
Computed: true,
616604
Description: `Time the Posture was created in UTC.`,
617605
},
618-
"effective_annotations": {
619-
Type: schema.TypeMap,
620-
Computed: true,
621-
Description: `All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services.`,
622-
Elem: &schema.Schema{Type: schema.TypeString},
623-
},
624606
"etag": {
625607
Type: schema.TypeString,
626608
Computed: true,
@@ -683,12 +665,6 @@ func resourceSecurityposturePostureCreate(d *schema.ResourceData, meta interface
683665
} else if v, ok := d.GetOkExists("policy_sets"); !tpgresource.IsEmptyValue(reflect.ValueOf(policySetsProp)) && (ok || !reflect.DeepEqual(v, policySetsProp)) {
684666
obj["policySets"] = policySetsProp
685667
}
686-
annotationsProp, err := expandSecurityposturePostureEffectiveAnnotations(d.Get("effective_annotations"), d, config)
687-
if err != nil {
688-
return err
689-
} else if v, ok := d.GetOkExists("effective_annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(annotationsProp)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
690-
obj["annotations"] = annotationsProp
691-
}
692668

693669
url, err := tpgresource.ReplaceVars(d, config, "{{SecuritypostureBasePath}}{{parent}}/locations/{{location}}/postures?postureId={{posture_id}}")
694670
if err != nil {
@@ -789,18 +765,12 @@ func resourceSecurityposturePostureRead(d *schema.ResourceData, meta interface{}
789765
if err := d.Set("etag", flattenSecurityposturePostureEtag(res["etag"], d, config)); err != nil {
790766
return fmt.Errorf("Error reading Posture: %s", err)
791767
}
792-
if err := d.Set("annotations", flattenSecurityposturePostureAnnotations(res["annotations"], d, config)); err != nil {
793-
return fmt.Errorf("Error reading Posture: %s", err)
794-
}
795768
if err := d.Set("reconciling", flattenSecurityposturePostureReconciling(res["reconciling"], d, config)); err != nil {
796769
return fmt.Errorf("Error reading Posture: %s", err)
797770
}
798771
if err := d.Set("policy_sets", flattenSecurityposturePosturePolicySets(res["policySets"], d, config)); err != nil {
799772
return fmt.Errorf("Error reading Posture: %s", err)
800773
}
801-
if err := d.Set("effective_annotations", flattenSecurityposturePostureEffectiveAnnotations(res["annotations"], d, config)); err != nil {
802-
return fmt.Errorf("Error reading Posture: %s", err)
803-
}
804774

805775
return nil
806776
}
@@ -839,12 +809,6 @@ func resourceSecurityposturePostureUpdate(d *schema.ResourceData, meta interface
839809
} else if v, ok := d.GetOkExists("policy_sets"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, policySetsProp)) {
840810
obj["policySets"] = policySetsProp
841811
}
842-
annotationsProp, err := expandSecurityposturePostureEffectiveAnnotations(d.Get("effective_annotations"), d, config)
843-
if err != nil {
844-
return err
845-
} else if v, ok := d.GetOkExists("effective_annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, annotationsProp)) {
846-
obj["annotations"] = annotationsProp
847-
}
848812

849813
url, err := tpgresource.ReplaceVars(d, config, "{{SecuritypostureBasePath}}{{parent}}/locations/{{location}}/postures/{{posture_id}}?revisionId={{revision_id}}")
850814
if err != nil {
@@ -869,10 +833,6 @@ func resourceSecurityposturePostureUpdate(d *schema.ResourceData, meta interface
869833
if d.HasChange("policy_sets") {
870834
updateMask = append(updateMask, "policySets")
871835
}
872-
873-
if d.HasChange("effective_annotations") {
874-
updateMask = append(updateMask, "annotations")
875-
}
876836
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
877837
// won't set it
878838
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -1008,21 +968,6 @@ func flattenSecurityposturePostureEtag(v interface{}, d *schema.ResourceData, co
1008968
return v
1009969
}
1010970

1011-
func flattenSecurityposturePostureAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1012-
if v == nil {
1013-
return v
1014-
}
1015-
1016-
transformed := make(map[string]interface{})
1017-
if l, ok := d.GetOkExists("annotations"); ok {
1018-
for k := range l.(map[string]interface{}) {
1019-
transformed[k] = v.(map[string]interface{})[k]
1020-
}
1021-
}
1022-
1023-
return transformed
1024-
}
1025-
1026971
func flattenSecurityposturePostureReconciling(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1027972
return v
1028973
}
@@ -1621,10 +1566,6 @@ func flattenSecurityposturePosturePolicySetsPoliciesConstraintSecurityHealthAnal
16211566
return v
16221567
}
16231568

1624-
func flattenSecurityposturePostureEffectiveAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1625-
return v
1626-
}
1627-
16281569
func expandSecurityposturePostureState(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
16291570
return v, nil
16301571
}
@@ -2596,14 +2537,3 @@ func expandSecurityposturePosturePolicySetsPoliciesConstraintSecurityHealthAnaly
25962537
func expandSecurityposturePosturePolicySetsPoliciesConstraintSecurityHealthAnalyticsCustomModuleConfigRecommendation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
25972538
return v, nil
25982539
}
2599-
2600-
func expandSecurityposturePostureEffectiveAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
2601-
if v == nil {
2602-
return map[string]string{}, nil
2603-
}
2604-
m := make(map[string]string)
2605-
for k, val := range v.(map[string]interface{}) {
2606-
m[k] = val.(string)
2607-
}
2608-
return m, nil
2609-
}

0 commit comments

Comments
 (0)