From ab94124bab70c435d64ffbda72a648e1d75cc6ad Mon Sep 17 00:00:00 2001 From: Elie CHARRA Date: Thu, 28 Jul 2022 10:30:30 +0200 Subject: [PATCH] fix: fix aws_security_group_rules tests --- .../remote/aws/vpc_security_group_rule_enumerator.go | 4 ++-- enumeration/remote/common/details_fetcher.go | 10 ++++++++++ ...-0cc8b3c3c2851705a-false--0-egress.res.golden.json} | 0 ...-0254c038e32f25530-false--0-egress.res.golden.json} | 0 ...0254c038e32f25530-false--0-ingress.res.golden.json} | 0 ...0254c038e32f25530-false--0-ingress.res.golden.json} | 0 ...-0254c038e32f25530-false--0-egress.res.golden.json} | 0 ...-0cc8b3c3c2851705a-false--0-egress.res.golden.json} | 0 ...30-false-sg-9e0204ff-65535-ingress.res.golden.json} | 0 ...4c038e32f25530-true--65535-ingress.res.golden.json} | 0 ...c8b3c3c2851705a-false--443-ingress.res.golden.json} | 0 ...0254c038e32f25530-false--0-ingress.res.golden.json} | 0 ...-0cc8b3c3c2851705a-false--0-egress.res.golden.json} | 0 enumeration/resource/aws/aws_security_group_rule.go | 8 ++++---- 14 files changed, 16 insertions(+), 6 deletions(-) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-1175318309--1-sg-0cc8b3c3c2851705a--egress.res.golden.json => aws_security_group_rule-sgrule-1175318309-1-0.0.0.0_0-0-0-0--1-sg-0cc8b3c3c2851705a-false--0-egress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-1707973622--1-sg-0254c038e32f25530--egress.res.golden.json => aws_security_group_rule-sgrule-1707973622-1-0.0.0.0_0-0-0-0--1-sg-0254c038e32f25530-false--0-egress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-2165103420--1-sg-0254c038e32f25530--ingress.res.golden.json => aws_security_group_rule-sgrule-2165103420-1-5.6.7.0_24-0-0-0--1-sg-0254c038e32f25530-false--0-ingress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-2582518759--1-sg-0254c038e32f25530--ingress.res.golden.json => aws_security_group_rule-sgrule-2582518759-1-1.2.0.0_16-0-0-0--1-sg-0254c038e32f25530-false--0-ingress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-2821752134--1-sg-0254c038e32f25530--egress.res.golden.json => aws_security_group_rule-sgrule-2821752134-0-0-1-___0-0--1-sg-0254c038e32f25530-false--0-egress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-350400929--1-sg-0cc8b3c3c2851705a--egress.res.golden.json => aws_security_group_rule-sgrule-350400929-0-0-1-___0-0--1-sg-0cc8b3c3c2851705a-false--0-egress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-3587309474-tcp-sg-0254c038e32f25530-sg-9e0204ff-ingress.res.golden.json => aws_security_group_rule-sgrule-3587309474-0-0-0-0-tcp-sg-0254c038e32f25530-false-sg-9e0204ff-65535-ingress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-3970541193-tcp-sg-0254c038e32f25530--ingress.res.golden.json => aws_security_group_rule-sgrule-3970541193-0-0-0-0-tcp-sg-0254c038e32f25530-true--65535-ingress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-453320892-tcp-sg-0cc8b3c3c2851705a--ingress.res.golden.json => aws_security_group_rule-sgrule-453320892-1-0.0.0.0_0-443-0-0-tcp-sg-0cc8b3c3c2851705a-false--443-ingress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-674800228--1-sg-0254c038e32f25530--ingress.res.golden.json => aws_security_group_rule-sgrule-674800228-0-0-1-___0-0--1-sg-0254c038e32f25530-false--0-ingress.res.golden.json} (100%) rename enumeration/remote/test/aws_vpc_security_group_rule_multiple/{aws_security_group_rule-sgrule-850043874-5-sg-0cc8b3c3c2851705a--egress.res.golden.json => aws_security_group_rule-sgrule-850043874-1-0.0.0.0_0-0-0-0-5-sg-0cc8b3c3c2851705a-false--0-egress.res.golden.json} (100%) diff --git a/enumeration/remote/aws/vpc_security_group_rule_enumerator.go b/enumeration/remote/aws/vpc_security_group_rule_enumerator.go index aacc2f74..5bcdc323 100644 --- a/enumeration/remote/aws/vpc_security_group_rule_enumerator.go +++ b/enumeration/remote/aws/vpc_security_group_rule_enumerator.go @@ -43,8 +43,8 @@ func (s *securityGroupRule) getAttrs() resource.Attributes { "type": s.Type, "security_group_id": s.SecurityGroupId, "protocol": s.Protocol, - "from_port": s.FromPort, - "to_port": s.ToPort, + "from_port": int(s.FromPort), + "to_port": int(s.ToPort), "self": s.Self, "source_security_group_id": s.SourceSecurityGroupId, "cidr_blocks": toInterfaceSlice(s.CidrBlocks), diff --git a/enumeration/remote/common/details_fetcher.go b/enumeration/remote/common/details_fetcher.go index abc78b59..312a2585 100644 --- a/enumeration/remote/common/details_fetcher.go +++ b/enumeration/remote/common/details_fetcher.go @@ -3,6 +3,7 @@ package common import ( "strconv" + "github.com/hashicorp/terraform/flatmap" "github.com/sirupsen/logrus" remoteerror "github.com/snyk/driftctl/enumeration/remote/error" "github.com/snyk/driftctl/enumeration/resource" @@ -34,12 +35,21 @@ func (f *GenericDetailsFetcher) ReadDetails(res *resource.Resource) (*resource.R if b, ok := v.(bool); ok { attributes[k] = strconv.FormatBool(b) } + if i, ok := v.(int); ok { + attributes[k] = strconv.Itoa(i) + } if i64, ok := v.(int64); ok { attributes[k] = strconv.FormatInt(i64, 10) } if str, ok := v.(string); ok { attributes[k] = str } + if sliceOfInterface, ok := v.([]interface{}); ok { + m := flatmap.Flatten(map[string]interface{}{k: sliceOfInterface}) + for k2, v2 := range m { + attributes[k2] = v2 + } + } } } ctyVal, err := f.reader.ReadResource(terraform.ReadResourceArgs{ diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1175318309--1-sg-0cc8b3c3c2851705a--egress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1175318309-1-0.0.0.0_0-0-0-0--1-sg-0cc8b3c3c2851705a-false--0-egress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1175318309--1-sg-0cc8b3c3c2851705a--egress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1175318309-1-0.0.0.0_0-0-0-0--1-sg-0cc8b3c3c2851705a-false--0-egress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1707973622--1-sg-0254c038e32f25530--egress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1707973622-1-0.0.0.0_0-0-0-0--1-sg-0254c038e32f25530-false--0-egress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1707973622--1-sg-0254c038e32f25530--egress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-1707973622-1-0.0.0.0_0-0-0-0--1-sg-0254c038e32f25530-false--0-egress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2165103420--1-sg-0254c038e32f25530--ingress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2165103420-1-5.6.7.0_24-0-0-0--1-sg-0254c038e32f25530-false--0-ingress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2165103420--1-sg-0254c038e32f25530--ingress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2165103420-1-5.6.7.0_24-0-0-0--1-sg-0254c038e32f25530-false--0-ingress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2582518759--1-sg-0254c038e32f25530--ingress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2582518759-1-1.2.0.0_16-0-0-0--1-sg-0254c038e32f25530-false--0-ingress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2582518759--1-sg-0254c038e32f25530--ingress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2582518759-1-1.2.0.0_16-0-0-0--1-sg-0254c038e32f25530-false--0-ingress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2821752134--1-sg-0254c038e32f25530--egress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2821752134-0-0-1-___0-0--1-sg-0254c038e32f25530-false--0-egress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2821752134--1-sg-0254c038e32f25530--egress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-2821752134-0-0-1-___0-0--1-sg-0254c038e32f25530-false--0-egress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-350400929--1-sg-0cc8b3c3c2851705a--egress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-350400929-0-0-1-___0-0--1-sg-0cc8b3c3c2851705a-false--0-egress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-350400929--1-sg-0cc8b3c3c2851705a--egress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-350400929-0-0-1-___0-0--1-sg-0cc8b3c3c2851705a-false--0-egress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-3587309474-tcp-sg-0254c038e32f25530-sg-9e0204ff-ingress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-3587309474-0-0-0-0-tcp-sg-0254c038e32f25530-false-sg-9e0204ff-65535-ingress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-3587309474-tcp-sg-0254c038e32f25530-sg-9e0204ff-ingress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-3587309474-0-0-0-0-tcp-sg-0254c038e32f25530-false-sg-9e0204ff-65535-ingress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-3970541193-tcp-sg-0254c038e32f25530--ingress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-3970541193-0-0-0-0-tcp-sg-0254c038e32f25530-true--65535-ingress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-3970541193-tcp-sg-0254c038e32f25530--ingress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-3970541193-0-0-0-0-tcp-sg-0254c038e32f25530-true--65535-ingress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-453320892-tcp-sg-0cc8b3c3c2851705a--ingress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-453320892-1-0.0.0.0_0-443-0-0-tcp-sg-0cc8b3c3c2851705a-false--443-ingress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-453320892-tcp-sg-0cc8b3c3c2851705a--ingress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-453320892-1-0.0.0.0_0-443-0-0-tcp-sg-0cc8b3c3c2851705a-false--443-ingress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-674800228--1-sg-0254c038e32f25530--ingress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-674800228-0-0-1-___0-0--1-sg-0254c038e32f25530-false--0-ingress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-674800228--1-sg-0254c038e32f25530--ingress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-674800228-0-0-1-___0-0--1-sg-0254c038e32f25530-false--0-ingress.res.golden.json diff --git a/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-850043874-5-sg-0cc8b3c3c2851705a--egress.res.golden.json b/enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-850043874-1-0.0.0.0_0-0-0-0-5-sg-0cc8b3c3c2851705a-false--0-egress.res.golden.json similarity index 100% rename from enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-850043874-5-sg-0cc8b3c3c2851705a--egress.res.golden.json rename to enumeration/remote/test/aws_vpc_security_group_rule_multiple/aws_security_group_rule-sgrule-850043874-1-0.0.0.0_0-0-0-0-5-sg-0cc8b3c3c2851705a-false--0-egress.res.golden.json diff --git a/enumeration/resource/aws/aws_security_group_rule.go b/enumeration/resource/aws/aws_security_group_rule.go index 96efcbdc..a65c54d8 100644 --- a/enumeration/resource/aws/aws_security_group_rule.go +++ b/enumeration/resource/aws/aws_security_group_rule.go @@ -13,11 +13,11 @@ const AwsSecurityGroupRuleResourceType = "aws_security_group_rule" func CreateSecurityGroupRuleIdHash(attrs *resource.Attributes) string { var buf bytes.Buffer buf.WriteString(fmt.Sprintf("%s-", *attrs.GetString("security_group_id"))) - if attrs.GetInt("from_port") != nil && *attrs.GetInt("from_port") > 0 { - buf.WriteString(fmt.Sprintf("%d-", *attrs.GetInt("from_port"))) + if (*attrs)["from_port"] != nil && (*attrs)["from_port"].(int) > 0 { + buf.WriteString(fmt.Sprintf("%d-", (*attrs)["from_port"].(int))) } - if attrs.GetInt("to_port") != nil && *attrs.GetInt("to_port") > 0 { - buf.WriteString(fmt.Sprintf("%d-", *attrs.GetInt("to_port"))) + if (*attrs)["to_port"] != nil && (*attrs)["to_port"].(int) > 0 { + buf.WriteString(fmt.Sprintf("%d-", (*attrs)["to_port"].(int))) } buf.WriteString(fmt.Sprintf("%s-", *attrs.GetString("protocol"))) buf.WriteString(fmt.Sprintf("%s-", *attrs.GetString("type")))