From bc017f087c51bdaa785fc3690417b3fc8346ae29 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Mon, 19 Jul 2021 17:55:59 +0200 Subject: [PATCH] fix: sgrules details fetcher --- ...vpc_security_group_rule_details_fetcher.go | 31 +++++++++---------- .../aws/vpc_security_group_rule_enumerator.go | 24 +++++++------- ...3c2851705a-false-0-egress.res.golden.json} | 0 ...8e32f25530-false-0-egress.res.golden.json} | 0 ...e32f25530-false-0-ingress.res.golden.json} | 0 ...e32f25530-false-0-ingress.res.golden.json} | 0 ...8e32f25530-false-0-egress.res.golden.json} | 0 ...3c2851705a-false-0-egress.res.golden.json} | 0 ...851705a-false-443-ingress.res.golden.json} | 0 ...e32f25530-false-0-ingress.res.golden.json} | 0 ...3c3c2851705a-false-egress.res.golden.json} | 0 11 files changed, 27 insertions(+), 28 deletions(-) rename pkg/remote/test/vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-1175318309-[0.0.0.0_0]-0--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json => aws_security_group_rule-sgrule-1175318309-1-0.0.0.0_0-0--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json} (100%) rename pkg/remote/test/vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-1707973622-[0.0.0.0_0]-0--1-sg-0254c038e32f25530-false-0-egress.res.golden.json => aws_security_group_rule-sgrule-1707973622-1-0.0.0.0_0-0--1-sg-0254c038e32f25530-false-0-egress.res.golden.json} (100%) rename pkg/remote/test/vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-2165103420-[5.6.7.0_24]-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json => aws_security_group_rule-sgrule-2165103420-1-5.6.7.0_24-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json} (100%) rename pkg/remote/test/vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-2582518759-[1.2.0.0_16]-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json => aws_security_group_rule-sgrule-2582518759-1-1.2.0.0_16-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json} (100%) rename pkg/remote/test/vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-2821752134-0-[___0]--1-sg-0254c038e32f25530-false-0-egress.res.golden.json => aws_security_group_rule-sgrule-2821752134-0-1-___0--1-sg-0254c038e32f25530-false-0-egress.res.golden.json} (100%) rename pkg/remote/test/vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-350400929-0-[___0]--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json => aws_security_group_rule-sgrule-350400929-0-1-___0--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json} (100%) rename pkg/remote/test/vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-453320892-[0.0.0.0_0]-443-tcp-sg-0cc8b3c3c2851705a-false-443-ingress.res.golden.json => aws_security_group_rule-sgrule-453320892-1-0.0.0.0_0-443-tcp-sg-0cc8b3c3c2851705a-false-443-ingress.res.golden.json} (100%) rename pkg/remote/test/vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-674800228-0-[___0]--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json => aws_security_group_rule-sgrule-674800228-0-1-___0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json} (100%) rename pkg/remote/test/vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-850043874-[0.0.0.0_0]-5-sg-0cc8b3c3c2851705a-false-egress.res.golden.json => aws_security_group_rule-sgrule-850043874-1-0.0.0.0_0-5-sg-0cc8b3c3c2851705a-false-egress.res.golden.json} (100%) diff --git a/pkg/remote/aws/vpc_security_group_rule_details_fetcher.go b/pkg/remote/aws/vpc_security_group_rule_details_fetcher.go index dbb238f5..3167a0c2 100644 --- a/pkg/remote/aws/vpc_security_group_rule_details_fetcher.go +++ b/pkg/remote/aws/vpc_security_group_rule_details_fetcher.go @@ -1,11 +1,10 @@ package aws import ( - "fmt" - "github.com/cloudskiff/driftctl/pkg/resource" "github.com/cloudskiff/driftctl/pkg/resource/aws" "github.com/cloudskiff/driftctl/pkg/terraform" + "github.com/hashicorp/terraform/flatmap" ) type VPCSecurityGroupRuleDetailsFetcher struct { @@ -21,43 +20,43 @@ func NewVPCSecurityGroupRuleDetailsFetcher(provider terraform.ResourceReader, de } func (r *VPCSecurityGroupRuleDetailsFetcher) ReadDetails(res resource.Resource) (resource.Resource, error) { - attrs := make(map[string]string) + attrs := make(map[string]interface{}) if v, ok := res.Attributes().Get("type"); ok { - attrs["type"] = fmt.Sprintf("%s", v) + attrs["type"] = v } if v, ok := res.Attributes().Get("protocol"); ok { - attrs["protocol"] = fmt.Sprintf("%s", v) + attrs["protocol"] = v } - if v, ok := res.Attributes().Get("from_port"); ok { - attrs["from_port"] = fmt.Sprintf("%d", int(v.(float64))) + if v := res.Attributes().GetInt("from_port"); v != nil { + attrs["from_port"] = *v } - if v, ok := res.Attributes().Get("to_port"); ok { - attrs["to_port"] = fmt.Sprintf("%d", int(v.(float64))) + if v := res.Attributes().GetInt("to_port"); v != nil { + attrs["to_port"] = *v } if v, ok := res.Attributes().Get("security_group_id"); ok { - attrs["security_group_id"] = fmt.Sprintf("%s", v) + attrs["security_group_id"] = v } if v, ok := res.Attributes().Get("self"); ok { - attrs["self"] = fmt.Sprintf("%t", v) + attrs["self"] = v } if v, ok := res.Attributes().Get("cidr_blocks"); ok { - attrs["cidr_blocks"] = fmt.Sprintf("%s", v) + attrs["cidr_blocks"] = v } if v, ok := res.Attributes().Get("ipv6_cidr_blocks"); ok { - attrs["ipv6_cidr_blocks"] = fmt.Sprintf("%s", v) + attrs["ipv6_cidr_blocks"] = v } if v, ok := res.Attributes().Get("prefix_list_ids"); ok { - attrs["prefix_list_ids"] = fmt.Sprintf("%s", v) + attrs["prefix_list_ids"] = v } if v, ok := res.Attributes().Get("source_security_group_id"); ok { - attrs["source_security_group_id"] = fmt.Sprintf("%s", v) + attrs["source_security_group_id"] = v } ctyVal, err := r.reader.ReadResource(terraform.ReadResourceArgs{ Ty: aws.AwsSecurityGroupRuleResourceType, ID: res.TerraformId(), - Attributes: attrs, + Attributes: flatmap.Flatten(attrs), }) if err != nil { return nil, err diff --git a/pkg/remote/aws/vpc_security_group_rule_enumerator.go b/pkg/remote/aws/vpc_security_group_rule_enumerator.go index d37b8381..973dd9af 100644 --- a/pkg/remote/aws/vpc_security_group_rule_enumerator.go +++ b/pkg/remote/aws/vpc_security_group_rule_enumerator.go @@ -25,8 +25,8 @@ type securityGroupRule struct { Type string SecurityGroupId string Protocol string - FromPort int - ToPort int + FromPort float64 + ToPort float64 Self bool SourceSecurityGroupId string CidrBlocks []string @@ -44,8 +44,8 @@ func (s *securityGroupRule) getAttrs() resource.Attributes { "type": s.Type, "security_group_id": s.SecurityGroupId, "protocol": s.Protocol, - "from_port": float64(s.FromPort), - "to_port": float64(s.ToPort), + "from_port": s.FromPort, + "to_port": s.ToPort, "self": s.Self, "source_security_group_id": s.SourceSecurityGroupId, "cidr_blocks": toInterfaceSlice(s.CidrBlocks), @@ -123,8 +123,8 @@ func (e *VPCSecurityGroupRuleEnumerator) addSecurityGroupRule(ruleType string, r Type: ruleType, SecurityGroupId: aws.StringValue(sg.GroupId), Protocol: aws.StringValue(rule.IpProtocol), - FromPort: int(aws.Int64Value(rule.FromPort)), - ToPort: int(aws.Int64Value(rule.ToPort)), + FromPort: float64(aws.Int64Value(rule.FromPort)), + ToPort: float64(aws.Int64Value(rule.ToPort)), } if aws.StringValue(groupPair.GroupId) == aws.StringValue(sg.GroupId) { r.Self = true @@ -138,8 +138,8 @@ func (e *VPCSecurityGroupRuleEnumerator) addSecurityGroupRule(ruleType string, r Type: ruleType, SecurityGroupId: aws.StringValue(sg.GroupId), Protocol: aws.StringValue(rule.IpProtocol), - FromPort: int(aws.Int64Value(rule.FromPort)), - ToPort: int(aws.Int64Value(rule.ToPort)), + FromPort: float64(aws.Int64Value(rule.FromPort)), + ToPort: float64(aws.Int64Value(rule.ToPort)), CidrBlocks: []string{aws.StringValue(ipRange.CidrIp)}, } rules = append(rules, r) @@ -149,8 +149,8 @@ func (e *VPCSecurityGroupRuleEnumerator) addSecurityGroupRule(ruleType string, r Type: ruleType, SecurityGroupId: aws.StringValue(sg.GroupId), Protocol: aws.StringValue(rule.IpProtocol), - FromPort: int(aws.Int64Value(rule.FromPort)), - ToPort: int(aws.Int64Value(rule.ToPort)), + FromPort: float64(aws.Int64Value(rule.FromPort)), + ToPort: float64(aws.Int64Value(rule.ToPort)), Ipv6CidrBlocks: []string{aws.StringValue(ipRange.CidrIpv6)}, } rules = append(rules, r) @@ -160,8 +160,8 @@ func (e *VPCSecurityGroupRuleEnumerator) addSecurityGroupRule(ruleType string, r Type: ruleType, SecurityGroupId: aws.StringValue(sg.GroupId), Protocol: aws.StringValue(rule.IpProtocol), - FromPort: int(aws.Int64Value(rule.FromPort)), - ToPort: int(aws.Int64Value(rule.ToPort)), + FromPort: float64(aws.Int64Value(rule.FromPort)), + ToPort: float64(aws.Int64Value(rule.ToPort)), PrefixListIds: []string{aws.StringValue(listId.PrefixListId)}, } rules = append(rules, r) diff --git a/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1175318309-[0.0.0.0_0]-0--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json b/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1175318309-1-0.0.0.0_0-0--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json similarity index 100% rename from pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1175318309-[0.0.0.0_0]-0--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json rename to pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1175318309-1-0.0.0.0_0-0--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json diff --git a/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1707973622-[0.0.0.0_0]-0--1-sg-0254c038e32f25530-false-0-egress.res.golden.json b/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1707973622-1-0.0.0.0_0-0--1-sg-0254c038e32f25530-false-0-egress.res.golden.json similarity index 100% rename from pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1707973622-[0.0.0.0_0]-0--1-sg-0254c038e32f25530-false-0-egress.res.golden.json rename to pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1707973622-1-0.0.0.0_0-0--1-sg-0254c038e32f25530-false-0-egress.res.golden.json diff --git a/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2165103420-[5.6.7.0_24]-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json b/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2165103420-1-5.6.7.0_24-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json similarity index 100% rename from pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2165103420-[5.6.7.0_24]-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json rename to pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2165103420-1-5.6.7.0_24-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json diff --git a/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2582518759-[1.2.0.0_16]-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json b/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2582518759-1-1.2.0.0_16-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json similarity index 100% rename from pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2582518759-[1.2.0.0_16]-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json rename to pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2582518759-1-1.2.0.0_16-0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json diff --git a/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2821752134-0-[___0]--1-sg-0254c038e32f25530-false-0-egress.res.golden.json b/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2821752134-0-1-___0--1-sg-0254c038e32f25530-false-0-egress.res.golden.json similarity index 100% rename from pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2821752134-0-[___0]--1-sg-0254c038e32f25530-false-0-egress.res.golden.json rename to pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2821752134-0-1-___0--1-sg-0254c038e32f25530-false-0-egress.res.golden.json diff --git a/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-350400929-0-[___0]--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json b/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-350400929-0-1-___0--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json similarity index 100% rename from pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-350400929-0-[___0]--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json rename to pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-350400929-0-1-___0--1-sg-0cc8b3c3c2851705a-false-0-egress.res.golden.json diff --git a/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-453320892-[0.0.0.0_0]-443-tcp-sg-0cc8b3c3c2851705a-false-443-ingress.res.golden.json b/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-453320892-1-0.0.0.0_0-443-tcp-sg-0cc8b3c3c2851705a-false-443-ingress.res.golden.json similarity index 100% rename from pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-453320892-[0.0.0.0_0]-443-tcp-sg-0cc8b3c3c2851705a-false-443-ingress.res.golden.json rename to pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-453320892-1-0.0.0.0_0-443-tcp-sg-0cc8b3c3c2851705a-false-443-ingress.res.golden.json diff --git a/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-674800228-0-[___0]--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json b/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-674800228-0-1-___0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json similarity index 100% rename from pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-674800228-0-[___0]--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json rename to pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-674800228-0-1-___0--1-sg-0254c038e32f25530-false-0-ingress.res.golden.json diff --git a/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-850043874-[0.0.0.0_0]-5-sg-0cc8b3c3c2851705a-false-egress.res.golden.json b/pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-850043874-1-0.0.0.0_0-5-sg-0cc8b3c3c2851705a-false-egress.res.golden.json similarity index 100% rename from pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-850043874-[0.0.0.0_0]-5-sg-0cc8b3c3c2851705a-false-egress.res.golden.json rename to pkg/remote/test/vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-850043874-1-0.0.0.0_0-5-sg-0cc8b3c3c2851705a-false-egress.res.golden.json