driftctl/pkg/remote/aws/vpc_security_group_rule_det...

72 lines
2.1 KiB
Go
Raw Normal View History

package aws
import (
2021-07-15 15:36:34 +00:00
"fmt"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/resource/aws"
"github.com/cloudskiff/driftctl/pkg/terraform"
)
type VPCSecurityGroupRuleDetailsFetcher struct {
reader terraform.ResourceReader
deserializer *resource.Deserializer
}
func NewVPCSecurityGroupRuleDetailsFetcher(provider terraform.ResourceReader, deserializer *resource.Deserializer) *VPCSecurityGroupRuleDetailsFetcher {
return &VPCSecurityGroupRuleDetailsFetcher{
reader: provider,
deserializer: deserializer,
}
}
func (r *VPCSecurityGroupRuleDetailsFetcher) ReadDetails(res resource.Resource) (resource.Resource, error) {
2021-07-15 15:36:34 +00:00
attrs := make(map[string]string)
if v, ok := res.Attributes().Get("type"); ok {
2021-07-15 15:36:34 +00:00
attrs["type"] = fmt.Sprintf("%s", v)
}
if v, ok := res.Attributes().Get("protocol"); ok {
2021-07-15 15:36:34 +00:00
attrs["protocol"] = fmt.Sprintf("%s", v)
}
if v, ok := res.Attributes().Get("from_port"); ok {
2021-07-15 15:36:34 +00:00
attrs["from_port"] = fmt.Sprintf("%d", int(v.(float64)))
}
if v, ok := res.Attributes().Get("to_port"); ok {
2021-07-15 15:36:34 +00:00
attrs["to_port"] = fmt.Sprintf("%d", int(v.(float64)))
}
if v, ok := res.Attributes().Get("security_group_id"); ok {
2021-07-15 15:36:34 +00:00
attrs["security_group_id"] = fmt.Sprintf("%s", v)
}
if v, ok := res.Attributes().Get("self"); ok {
2021-07-15 15:36:34 +00:00
attrs["self"] = fmt.Sprintf("%t", v)
}
if v, ok := res.Attributes().Get("cidr_blocks"); ok {
2021-07-15 15:36:34 +00:00
attrs["cidr_blocks"] = fmt.Sprintf("%s", v)
}
if v, ok := res.Attributes().Get("ipv6_cidr_blocks"); ok {
2021-07-15 15:36:34 +00:00
attrs["ipv6_cidr_blocks"] = fmt.Sprintf("%s", v)
}
if v, ok := res.Attributes().Get("prefix_list_ids"); ok {
2021-07-15 15:36:34 +00:00
attrs["prefix_list_ids"] = fmt.Sprintf("%s", v)
}
if v, ok := res.Attributes().Get("source_security_group_id"); ok {
2021-07-15 15:36:34 +00:00
attrs["source_security_group_id"] = fmt.Sprintf("%s", v)
}
ctyVal, err := r.reader.ReadResource(terraform.ReadResourceArgs{
Ty: aws.AwsSecurityGroupRuleResourceType,
ID: res.TerraformId(),
2021-07-15 15:36:34 +00:00
Attributes: attrs,
})
if err != nil {
return nil, err
}
deserializedRes, err := r.deserializer.DeserializeOne(aws.AwsSecurityGroupRuleResourceType, *ctyVal)
if err != nil {
return nil, err
}
return deserializedRes, nil
}