fix: sgrules details fetcher
parent
b30fabdaad
commit
bc017f087c
|
@ -1,11 +1,10 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/cloudskiff/driftctl/pkg/resource"
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
||||||
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
||||||
"github.com/cloudskiff/driftctl/pkg/terraform"
|
"github.com/cloudskiff/driftctl/pkg/terraform"
|
||||||
|
"github.com/hashicorp/terraform/flatmap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VPCSecurityGroupRuleDetailsFetcher struct {
|
type VPCSecurityGroupRuleDetailsFetcher struct {
|
||||||
|
@ -21,43 +20,43 @@ func NewVPCSecurityGroupRuleDetailsFetcher(provider terraform.ResourceReader, de
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *VPCSecurityGroupRuleDetailsFetcher) ReadDetails(res resource.Resource) (resource.Resource, error) {
|
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 {
|
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 {
|
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 {
|
if v := res.Attributes().GetInt("from_port"); v != nil {
|
||||||
attrs["from_port"] = fmt.Sprintf("%d", int(v.(float64)))
|
attrs["from_port"] = *v
|
||||||
}
|
}
|
||||||
if v, ok := res.Attributes().Get("to_port"); ok {
|
if v := res.Attributes().GetInt("to_port"); v != nil {
|
||||||
attrs["to_port"] = fmt.Sprintf("%d", int(v.(float64)))
|
attrs["to_port"] = *v
|
||||||
}
|
}
|
||||||
if v, ok := res.Attributes().Get("security_group_id"); ok {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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{
|
ctyVal, err := r.reader.ReadResource(terraform.ReadResourceArgs{
|
||||||
Ty: aws.AwsSecurityGroupRuleResourceType,
|
Ty: aws.AwsSecurityGroupRuleResourceType,
|
||||||
ID: res.TerraformId(),
|
ID: res.TerraformId(),
|
||||||
Attributes: attrs,
|
Attributes: flatmap.Flatten(attrs),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -25,8 +25,8 @@ type securityGroupRule struct {
|
||||||
Type string
|
Type string
|
||||||
SecurityGroupId string
|
SecurityGroupId string
|
||||||
Protocol string
|
Protocol string
|
||||||
FromPort int
|
FromPort float64
|
||||||
ToPort int
|
ToPort float64
|
||||||
Self bool
|
Self bool
|
||||||
SourceSecurityGroupId string
|
SourceSecurityGroupId string
|
||||||
CidrBlocks []string
|
CidrBlocks []string
|
||||||
|
@ -44,8 +44,8 @@ func (s *securityGroupRule) getAttrs() resource.Attributes {
|
||||||
"type": s.Type,
|
"type": s.Type,
|
||||||
"security_group_id": s.SecurityGroupId,
|
"security_group_id": s.SecurityGroupId,
|
||||||
"protocol": s.Protocol,
|
"protocol": s.Protocol,
|
||||||
"from_port": float64(s.FromPort),
|
"from_port": s.FromPort,
|
||||||
"to_port": float64(s.ToPort),
|
"to_port": s.ToPort,
|
||||||
"self": s.Self,
|
"self": s.Self,
|
||||||
"source_security_group_id": s.SourceSecurityGroupId,
|
"source_security_group_id": s.SourceSecurityGroupId,
|
||||||
"cidr_blocks": toInterfaceSlice(s.CidrBlocks),
|
"cidr_blocks": toInterfaceSlice(s.CidrBlocks),
|
||||||
|
@ -123,8 +123,8 @@ func (e *VPCSecurityGroupRuleEnumerator) addSecurityGroupRule(ruleType string, r
|
||||||
Type: ruleType,
|
Type: ruleType,
|
||||||
SecurityGroupId: aws.StringValue(sg.GroupId),
|
SecurityGroupId: aws.StringValue(sg.GroupId),
|
||||||
Protocol: aws.StringValue(rule.IpProtocol),
|
Protocol: aws.StringValue(rule.IpProtocol),
|
||||||
FromPort: int(aws.Int64Value(rule.FromPort)),
|
FromPort: float64(aws.Int64Value(rule.FromPort)),
|
||||||
ToPort: int(aws.Int64Value(rule.ToPort)),
|
ToPort: float64(aws.Int64Value(rule.ToPort)),
|
||||||
}
|
}
|
||||||
if aws.StringValue(groupPair.GroupId) == aws.StringValue(sg.GroupId) {
|
if aws.StringValue(groupPair.GroupId) == aws.StringValue(sg.GroupId) {
|
||||||
r.Self = true
|
r.Self = true
|
||||||
|
@ -138,8 +138,8 @@ func (e *VPCSecurityGroupRuleEnumerator) addSecurityGroupRule(ruleType string, r
|
||||||
Type: ruleType,
|
Type: ruleType,
|
||||||
SecurityGroupId: aws.StringValue(sg.GroupId),
|
SecurityGroupId: aws.StringValue(sg.GroupId),
|
||||||
Protocol: aws.StringValue(rule.IpProtocol),
|
Protocol: aws.StringValue(rule.IpProtocol),
|
||||||
FromPort: int(aws.Int64Value(rule.FromPort)),
|
FromPort: float64(aws.Int64Value(rule.FromPort)),
|
||||||
ToPort: int(aws.Int64Value(rule.ToPort)),
|
ToPort: float64(aws.Int64Value(rule.ToPort)),
|
||||||
CidrBlocks: []string{aws.StringValue(ipRange.CidrIp)},
|
CidrBlocks: []string{aws.StringValue(ipRange.CidrIp)},
|
||||||
}
|
}
|
||||||
rules = append(rules, r)
|
rules = append(rules, r)
|
||||||
|
@ -149,8 +149,8 @@ func (e *VPCSecurityGroupRuleEnumerator) addSecurityGroupRule(ruleType string, r
|
||||||
Type: ruleType,
|
Type: ruleType,
|
||||||
SecurityGroupId: aws.StringValue(sg.GroupId),
|
SecurityGroupId: aws.StringValue(sg.GroupId),
|
||||||
Protocol: aws.StringValue(rule.IpProtocol),
|
Protocol: aws.StringValue(rule.IpProtocol),
|
||||||
FromPort: int(aws.Int64Value(rule.FromPort)),
|
FromPort: float64(aws.Int64Value(rule.FromPort)),
|
||||||
ToPort: int(aws.Int64Value(rule.ToPort)),
|
ToPort: float64(aws.Int64Value(rule.ToPort)),
|
||||||
Ipv6CidrBlocks: []string{aws.StringValue(ipRange.CidrIpv6)},
|
Ipv6CidrBlocks: []string{aws.StringValue(ipRange.CidrIpv6)},
|
||||||
}
|
}
|
||||||
rules = append(rules, r)
|
rules = append(rules, r)
|
||||||
|
@ -160,8 +160,8 @@ func (e *VPCSecurityGroupRuleEnumerator) addSecurityGroupRule(ruleType string, r
|
||||||
Type: ruleType,
|
Type: ruleType,
|
||||||
SecurityGroupId: aws.StringValue(sg.GroupId),
|
SecurityGroupId: aws.StringValue(sg.GroupId),
|
||||||
Protocol: aws.StringValue(rule.IpProtocol),
|
Protocol: aws.StringValue(rule.IpProtocol),
|
||||||
FromPort: int(aws.Int64Value(rule.FromPort)),
|
FromPort: float64(aws.Int64Value(rule.FromPort)),
|
||||||
ToPort: int(aws.Int64Value(rule.ToPort)),
|
ToPort: float64(aws.Int64Value(rule.ToPort)),
|
||||||
PrefixListIds: []string{aws.StringValue(listId.PrefixListId)},
|
PrefixListIds: []string{aws.StringValue(listId.PrefixListId)},
|
||||||
}
|
}
|
||||||
rules = append(rules, r)
|
rules = append(rules, r)
|
||||||
|
|
Loading…
Reference in New Issue