2021-07-08 10:47:03 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
2021-07-28 14:30:22 +00:00
|
|
|
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
|
2021-07-08 10:47:03 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/terraform"
|
2021-07-19 15:55:59 +00:00
|
|
|
"github.com/hashicorp/terraform/flatmap"
|
2021-07-08 10:47:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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-19 15:55:59 +00:00
|
|
|
attrs := make(map[string]interface{})
|
2021-07-08 10:47:03 +00:00
|
|
|
|
|
|
|
if v, ok := res.Attributes().Get("type"); ok {
|
2021-07-19 15:55:59 +00:00
|
|
|
attrs["type"] = v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
|
|
|
if v, ok := res.Attributes().Get("protocol"); ok {
|
2021-07-19 15:55:59 +00:00
|
|
|
attrs["protocol"] = v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
2021-07-19 15:55:59 +00:00
|
|
|
if v := res.Attributes().GetInt("from_port"); v != nil {
|
|
|
|
attrs["from_port"] = *v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
2021-07-19 15:55:59 +00:00
|
|
|
if v := res.Attributes().GetInt("to_port"); v != nil {
|
|
|
|
attrs["to_port"] = *v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
|
|
|
if v, ok := res.Attributes().Get("security_group_id"); ok {
|
2021-07-19 15:55:59 +00:00
|
|
|
attrs["security_group_id"] = v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
|
|
|
if v, ok := res.Attributes().Get("self"); ok {
|
2021-07-19 15:55:59 +00:00
|
|
|
attrs["self"] = v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
|
|
|
if v, ok := res.Attributes().Get("cidr_blocks"); ok {
|
2021-07-19 15:55:59 +00:00
|
|
|
attrs["cidr_blocks"] = v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
|
|
|
if v, ok := res.Attributes().Get("ipv6_cidr_blocks"); ok {
|
2021-07-19 15:55:59 +00:00
|
|
|
attrs["ipv6_cidr_blocks"] = v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
|
|
|
if v, ok := res.Attributes().Get("prefix_list_ids"); ok {
|
2021-07-19 15:55:59 +00:00
|
|
|
attrs["prefix_list_ids"] = v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
|
|
|
if v, ok := res.Attributes().Get("source_security_group_id"); ok {
|
2021-07-19 15:55:59 +00:00
|
|
|
attrs["source_security_group_id"] = v
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctyVal, err := r.reader.ReadResource(terraform.ReadResourceArgs{
|
|
|
|
Ty: aws.AwsSecurityGroupRuleResourceType,
|
|
|
|
ID: res.TerraformId(),
|
2021-07-19 15:55:59 +00:00
|
|
|
Attributes: flatmap.Flatten(attrs),
|
2021-07-08 10:47:03 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-08-03 10:34:36 +00:00
|
|
|
return nil, remoteerror.NewResourceScanningError(err, res.TerraformType(), res.TerraformId())
|
2021-07-08 10:47:03 +00:00
|
|
|
}
|
|
|
|
deserializedRes, err := r.deserializer.DeserializeOne(aws.AwsSecurityGroupRuleResourceType, *ctyVal)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return deserializedRes, nil
|
|
|
|
}
|