From 3e32c9e53d8de04c6b34f801aff41a21d42a2fcd Mon Sep 17 00:00:00 2001 From: Whitney Smith Date: Thu, 5 Oct 2023 19:59:18 +0000 Subject: [PATCH] fix reference to gcp/aws for account mappings --- lacework/account_mapping_helper.go | 17 +++++++---------- ...cework_integration_gcp_agentless_scanning.go | 4 ++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lacework/account_mapping_helper.go b/lacework/account_mapping_helper.go index 32bd9126..9492fd64 100644 --- a/lacework/account_mapping_helper.go +++ b/lacework/account_mapping_helper.go @@ -1,8 +1,6 @@ package lacework import ( - "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -19,14 +17,13 @@ var awsMappingType string = "aws_accounts" var gcpMappingType string = "gcp_projects" func getResourceOrgAccountMappings(d *schema.ResourceData, mappingsType string) *accountMappingsFile { - fmt.Println("MAPPINGS TYPE: ", mappingsType) accountMapFile := new(accountMappingsFile) accMapsInt := d.Get("org_account_mappings").([]interface{}) if len(accMapsInt) != 0 && accMapsInt[0] != nil { accountMappings := accMapsInt[0].(map[string]interface{}) accountMapFile = &accountMappingsFile{ - DefaultLaceworkAccount: accountMappings["default_lacework_account_aws"].(string), + DefaultLaceworkAccount: accountMappings["default_lacework_account"].(string), Mappings: map[string]interface{}{}, } @@ -56,8 +53,8 @@ func flattenOrgAccountMappings(mappingFile *accountMappingsFile, mappingsType st } mappings := map[string]interface{}{ - "default_lacework_account_aws": mappingFile.DefaultLaceworkAccount, - "mapping": flattenMappings(mappingFile.Mappings, mappingsType), + "default_lacework_account": mappingFile.DefaultLaceworkAccount, + "mapping": flattenMappings(mappingFile.Mappings, mappingsType), } orgAccMappings = append(orgAccMappings, mappings) @@ -85,7 +82,7 @@ func flattenMappings(mappings map[string]interface{}, mappingsType string) *sche return awsRes } -func flattenOrgGcpAccountMappings(mappingFile *accountMappingsFile, mappingsType string) []map[string]interface{} { +func flattenOrgGcpAccountMappings(mappingFile *accountMappingsFile) []map[string]interface{} { orgAccMappings := make([]map[string]interface{}, 0, 1) if mappingFile.Empty() { @@ -94,18 +91,18 @@ func flattenOrgGcpAccountMappings(mappingFile *accountMappingsFile, mappingsType mappings := map[string]interface{}{ "default_lacework_account_aws": mappingFile.DefaultLaceworkAccount, - "mapping": flattenGcpMappings(mappingFile.Mappings, mappingsType), + "mapping": flattenGcpMappings(mappingFile.Mappings), } orgAccMappings = append(orgAccMappings, mappings) return orgAccMappings } -func flattenGcpMappings(mappings map[string]interface{}, mappingsType string) *schema.Set { +func flattenGcpMappings(mappings map[string]interface{}) *schema.Set { var ( gcpOrgAccountMappingsSchema = gcpAgentlessScanningIntegrationSchema["org_account_mappings"].Elem.(*schema.Resource) gcpMappingSchema = gcpOrgAccountMappingsSchema.Schema["mapping"].Elem.(*schema.Resource) - gcpAccountsSchema = gcpMappingSchema.Schema[mappingsType].Elem.(*schema.Schema) + gcpAccountsSchema = gcpMappingSchema.Schema["mapping"].Elem.(*schema.Schema) gcpRes = schema.NewSet(schema.HashResource(gcpMappingSchema), []interface{}{}) ) diff --git a/lacework/resource_lacework_integration_gcp_agentless_scanning.go b/lacework/resource_lacework_integration_gcp_agentless_scanning.go index d8e20763..1ccbfb0a 100644 --- a/lacework/resource_lacework_integration_gcp_agentless_scanning.go +++ b/lacework/resource_lacework_integration_gcp_agentless_scanning.go @@ -217,7 +217,7 @@ var gcpAgentlessScanningIntegrationSchema = map[string]*schema.Schema{ Description: "Mapping of GCP projects to Lacework accounts within a Lacework organization.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "default_lacework_account_aws": { + "default_lacework_account": { Type: schema.TypeString, Required: true, Description: "The default Lacework account name where any non-mapped GCP project will appear", @@ -404,7 +404,7 @@ func resourceLaceworkIntegrationGcpAgentlessScanningRead(d *schema.ResourceData, } - err = d.Set("org_account_mappings", flattenOrgGcpAccountMappings(accountMapFile, gcpMappingType)) + err = d.Set("org_account_mappings", flattenOrgGcpAccountMappings(accountMapFile)) if err != nil { return fmt.Errorf("Error flattening organization account mapping: %s", err) }