2021-06-11 15:10:06 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
2021-07-28 14:30:22 +00:00
|
|
|
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
|
2021-06-11 15:10:06 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
type S3BucketDetailsFetcher struct {
|
|
|
|
reader terraform.ResourceReader
|
|
|
|
deserializer *resource.Deserializer
|
|
|
|
}
|
|
|
|
|
2021-06-28 09:00:59 +00:00
|
|
|
func NewS3BucketDetailsFetcher(provider terraform.ResourceReader, deserializer *resource.Deserializer) *S3BucketDetailsFetcher {
|
2021-06-11 15:10:06 +00:00
|
|
|
return &S3BucketDetailsFetcher{
|
|
|
|
reader: provider,
|
|
|
|
deserializer: deserializer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *S3BucketDetailsFetcher) ReadDetails(res resource.Resource) (resource.Resource, error) {
|
|
|
|
ctyVal, err := r.reader.ReadResource(terraform.ReadResourceArgs{
|
|
|
|
Ty: aws.AwsS3BucketResourceType,
|
|
|
|
ID: res.TerraformId(),
|
|
|
|
Attributes: map[string]string{
|
|
|
|
"alias": *res.Attributes().GetString("region"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
2021-08-03 10:34:36 +00:00
|
|
|
return nil, remoteerror.NewResourceScanningError(err, res.TerraformType(), res.TerraformId())
|
2021-06-11 15:10:06 +00:00
|
|
|
}
|
|
|
|
deserializedRes, err := r.deserializer.DeserializeOne(aws.AwsS3BucketResourceType, *ctyVal)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return deserializedRes, nil
|
|
|
|
}
|