fix: sgrules details fetcher
parent
b30fabdaad
commit
bc017f087c
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue