fix(remote): aws s3 bucket analytic supplier

Add filter on resources based on region
main
sundowndev 2021-03-18 12:10:46 +01:00
parent 038116e7bf
commit 1bebec138d
3 changed files with 15 additions and 115 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
"github.com/cloudskiff/driftctl/pkg/remote/deserializer"
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
tf "github.com/cloudskiff/driftctl/pkg/remote/terraform"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/resource/aws"
awsdeserializer "github.com/cloudskiff/driftctl/pkg/resource/aws/deserializer"
@ -19,6 +20,7 @@ type S3BucketAnalyticSupplier struct {
deserializer deserializer.CTYDeserializer
repository repository.S3Repository
runner *terraform.ParallelResourceReader
providerConfig tf.TerraformProviderConfig
}
func NewS3BucketAnalyticSupplier(provider *AWSTerraformProvider, repository repository.S3Repository) *S3BucketAnalyticSupplier {
@ -27,6 +29,7 @@ func NewS3BucketAnalyticSupplier(provider *AWSTerraformProvider, repository repo
awsdeserializer.NewS3BucketAnalyticDeserializer(),
repository,
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
provider.Config,
}
}
@ -42,7 +45,7 @@ func (s *S3BucketAnalyticSupplier) Resources() ([]resource.Resource, error) {
if err != nil {
return nil, err
}
if region == "" {
if region == "" || region != s.providerConfig.DefaultAlias {
continue
}
if err := s.listBucketAnalyticConfiguration(&bucket, region); err != nil {

View File

@ -11,6 +11,7 @@ import (
"github.com/cloudskiff/driftctl/pkg/remote/aws/client"
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
tf "github.com/cloudskiff/driftctl/pkg/remote/terraform"
"github.com/cloudskiff/driftctl/pkg/resource"
resourceaws "github.com/cloudskiff/driftctl/pkg/resource/aws"
awsdeserializer "github.com/cloudskiff/driftctl/pkg/resource/aws/deserializer"
@ -124,14 +125,14 @@ func TestS3BucketAnalyticSupplier_Resources(t *testing.T) {
"GetBucketLocation",
&s3.Bucket{Name: awssdk.String("bucket-martin-test-drift")},
).Return(
"eu-west-1",
"eu-west-3",
nil,
)
repository.On(
"ListBucketAnalyticsConfigurations",
&s3.Bucket{Name: awssdk.String("bucket-martin-test-drift")},
"eu-west-1",
"eu-west-3",
).Return(
nil,
awserr.NewRequestFailure(nil, 403, ""),
@ -169,6 +170,10 @@ func TestS3BucketAnalyticSupplier_Resources(t *testing.T) {
deserializer,
&mock,
terraform.NewParallelResourceReader(parallel.NewParallelRunner(context.TODO(), 10)),
tf.TerraformProviderConfig{
Name: "test",
DefaultAlias: "eu-west-3",
},
}
got, err := s.Resources()
assert.Equal(t, err, tt.wantErr)

View File

@ -52,113 +52,5 @@
]
}
]
},
{
"bucket": "bucket-martin-test-drift",
"filter": [],
"id": "bucket-martin-test-drift:Analytics_Bucket1",
"name": "Analytics_Bucket1",
"storage_class_analysis": [
{
"data_export": [
{
"destination": [
{
"s3_bucket_destination": [
{
"bucket_account_id": "",
"bucket_arn": "arn:aws:s3:::bucket-martin-test-drift",
"format": "CSV",
"prefix": ""
}
]
}
],
"output_schema_version": "V_1"
}
]
}
]
},
{
"bucket": "bucket-martin-test-drift",
"filter": [],
"id": "bucket-martin-test-drift:Analytics2_Bucket1",
"name": "Analytics2_Bucket1",
"storage_class_analysis": [
{
"data_export": [
{
"destination": [
{
"s3_bucket_destination": [
{
"bucket_account_id": "",
"bucket_arn": "arn:aws:s3:::bucket-martin-test-drift",
"format": "CSV",
"prefix": ""
}
]
}
],
"output_schema_version": "V_1"
}
]
}
]
},
{
"bucket": "bucket-martin-test-drift3",
"filter": [],
"id": "bucket-martin-test-drift3:Analytics2_Bucket3",
"name": "Analytics2_Bucket3",
"storage_class_analysis": [
{
"data_export": [
{
"destination": [
{
"s3_bucket_destination": [
{
"bucket_account_id": "",
"bucket_arn": "arn:aws:s3:::bucket-martin-test-drift3",
"format": "CSV",
"prefix": ""
}
]
}
],
"output_schema_version": "V_1"
}
]
}
]
},
{
"bucket": "bucket-martin-test-drift3",
"filter": [],
"id": "bucket-martin-test-drift3:Analytics_Bucket3",
"name": "Analytics_Bucket3",
"storage_class_analysis": [
{
"data_export": [
{
"destination": [
{
"s3_bucket_destination": [
{
"bucket_account_id": "",
"bucket_arn": "arn:aws:s3:::bucket-martin-test-drift3",
"format": "CSV",
"prefix": ""
}
]
}
],
"output_schema_version": "V_1"
}
]
}
]
}
]