Skip to content

Commit

Permalink
fix reference to gcp/aws for account mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
wl-smith committed Oct 5, 2023
1 parent a1eb19e commit 3e32c9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
17 changes: 7 additions & 10 deletions lacework/account_mapping_helper.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package lacework

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand All @@ -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{}{},
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand All @@ -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{}{})
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 3e32c9e

Please sign in to comment.