From 2ed311e10d2ba476439c1aa6aaec7725bccb2c03 Mon Sep 17 00:00:00 2001 From: Elie Date: Wed, 17 Mar 2021 16:54:53 +0100 Subject: [PATCH 1/4] Fix race conditions when using multiples runners in a single supplier --- .../aws/cloudfront_distribution_supplier.go | 4 +-- pkg/remote/aws/db_instance_supplier.go | 2 +- pkg/remote/aws/db_subnet_group_supplier.go | 4 +-- pkg/remote/aws/dynamodb_table_supplier.go | 4 +-- pkg/remote/aws/ec2_ami_supplier.go | 4 +-- pkg/remote/aws/ec2_ebs_snapshot_supplier.go | 4 +-- pkg/remote/aws/ec2_ebs_volume_supplier.go | 4 +-- .../aws/ec2_eip_association_supplier.go | 4 +-- pkg/remote/aws/ec2_eip_supplier.go | 4 +-- pkg/remote/aws/ec2_instance_supplier.go | 4 +-- pkg/remote/aws/ec2_key_pair_supplier.go | 4 +-- pkg/remote/aws/ecr_repository_supplier.go | 4 +-- pkg/remote/aws/iam_access_key_supplier.go | 4 +-- pkg/remote/aws/iam_policy_supplier.go | 4 +-- .../iam_role_policy_attachment_supplier.go | 4 +-- pkg/remote/aws/iam_role_policy_supplier.go | 4 +-- pkg/remote/aws/iam_role_supplier.go | 4 +-- .../iam_user_policy_attachment_supplier.go | 4 +-- pkg/remote/aws/iam_user_policy_supplier.go | 4 +-- pkg/remote/aws/iam_user_supplier.go | 4 +-- pkg/remote/aws/internet_gateway_supplier.go | 4 +-- pkg/remote/aws/kms_alias_supplier.go | 4 +-- pkg/remote/aws/kms_key_supplier.go | 4 +-- .../lambda_event_source_mapping_supplier.go | 4 +-- pkg/remote/aws/lambda_function_supplier.go | 4 +-- pkg/remote/aws/nat_gateway_supplier.go | 4 +-- .../aws/route53_health_check_supplier.go | 4 +-- pkg/remote/aws/route53_record_supplier.go | 6 ++-- pkg/remote/aws/route53_zone_supplier.go | 4 +-- pkg/remote/aws/route_supplier.go | 4 +-- .../aws/route_table_association_supplier.go | 6 ++-- pkg/remote/aws/route_table_supplier.go | 32 +++++++++++++------ pkg/remote/aws/s3_bucket_supplier.go | 2 +- pkg/remote/aws/sns_topic_policy_supplier.go | 4 +-- .../aws/sns_topic_subscription_supplier.go | 4 +-- pkg/remote/aws/sns_topic_supplier.go | 4 +-- pkg/remote/aws/sqs_queue_policy_supplier.go | 4 +-- pkg/remote/aws/sqs_queue_supplier.go | 4 +-- pkg/remote/aws/subnet_supplier.go | 13 ++++---- .../aws/vpc_security_group_rule_supplier.go | 12 +++---- pkg/remote/aws/vpc_security_group_supplier.go | 4 +-- pkg/remote/aws/vpc_supplier.go | 13 ++++---- 42 files changed, 119 insertions(+), 103 deletions(-) diff --git a/pkg/remote/aws/cloudfront_distribution_supplier.go b/pkg/remote/aws/cloudfront_distribution_supplier.go index 61670c9e..3a211dfb 100644 --- a/pkg/remote/aws/cloudfront_distribution_supplier.go +++ b/pkg/remote/aws/cloudfront_distribution_supplier.go @@ -29,7 +29,7 @@ func NewCloudfrontDistributionSupplier(provider *AWSTerraformProvider) *Cloudfro } } -func (s CloudfrontDistributionSupplier) Resources() ([]resource.Resource, error) { +func (s *CloudfrontDistributionSupplier) Resources() ([]resource.Resource, error) { distributions, err := s.client.ListAllDistributions() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsCloudfrontDistributionResourceType) @@ -50,7 +50,7 @@ func (s CloudfrontDistributionSupplier) Resources() ([]resource.Resource, error) return s.deserializer.Deserialize(resources) } -func (s CloudfrontDistributionSupplier) readCloudfrontDistribution(distribution cloudfront.DistributionSummary) (cty.Value, error) { +func (s *CloudfrontDistributionSupplier) readCloudfrontDistribution(distribution cloudfront.DistributionSummary) (cty.Value, error) { val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *distribution.Id, Ty: aws.AwsCloudfrontDistributionResourceType, diff --git a/pkg/remote/aws/db_instance_supplier.go b/pkg/remote/aws/db_instance_supplier.go index 2f2bd2d9..1106169d 100644 --- a/pkg/remote/aws/db_instance_supplier.go +++ b/pkg/remote/aws/db_instance_supplier.go @@ -29,7 +29,7 @@ func NewDBInstanceSupplier(provider *AWSTerraformProvider) *DBInstanceSupplier { } } -func (s DBInstanceSupplier) Resources() ([]resource.Resource, error) { +func (s *DBInstanceSupplier) Resources() ([]resource.Resource, error) { resourceList, err := s.client.ListAllDBInstances() diff --git a/pkg/remote/aws/db_subnet_group_supplier.go b/pkg/remote/aws/db_subnet_group_supplier.go index c11cea6a..792bbbe9 100644 --- a/pkg/remote/aws/db_subnet_group_supplier.go +++ b/pkg/remote/aws/db_subnet_group_supplier.go @@ -32,7 +32,7 @@ func NewDBSubnetGroupSupplier(provider *AWSTerraformProvider) *DBSubnetGroupSupp } } -func (s DBSubnetGroupSupplier) Resources() ([]resource.Resource, error) { +func (s *DBSubnetGroupSupplier) Resources() ([]resource.Resource, error) { subnetGroups, err := s.client.ListAllDbSubnetGroups() @@ -53,7 +53,7 @@ func (s DBSubnetGroupSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(ctyValues) } -func (s DBSubnetGroupSupplier) readSubnetGroup(subnetGroup rds.DBSubnetGroup) (cty.Value, error) { +func (s *DBSubnetGroupSupplier) readSubnetGroup(subnetGroup rds.DBSubnetGroup) (cty.Value, error) { val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *subnetGroup.DBSubnetGroupName, Ty: aws.AwsDbSubnetGroupResourceType, diff --git a/pkg/remote/aws/dynamodb_table_supplier.go b/pkg/remote/aws/dynamodb_table_supplier.go index 6999fbb6..046ae1ee 100644 --- a/pkg/remote/aws/dynamodb_table_supplier.go +++ b/pkg/remote/aws/dynamodb_table_supplier.go @@ -29,7 +29,7 @@ func NewDynamoDBTableSupplier(provider *AWSTerraformProvider) *DynamoDBTableSupp } } -func (s DynamoDBTableSupplier) Resources() ([]resource.Resource, error) { +func (s *DynamoDBTableSupplier) Resources() ([]resource.Resource, error) { tables, err := s.repository.ListAllTables() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsDynamodbTableResourceType) @@ -50,7 +50,7 @@ func (s DynamoDBTableSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(retrieve) } -func (s DynamoDBTableSupplier) readTable(tableName *string) (cty.Value, error) { +func (s *DynamoDBTableSupplier) readTable(tableName *string) (cty.Value, error) { val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *tableName, Ty: aws.AwsDynamodbTableResourceType, diff --git a/pkg/remote/aws/ec2_ami_supplier.go b/pkg/remote/aws/ec2_ami_supplier.go index b72215ce..035f2434 100644 --- a/pkg/remote/aws/ec2_ami_supplier.go +++ b/pkg/remote/aws/ec2_ami_supplier.go @@ -31,7 +31,7 @@ func NewEC2AmiSupplier(provider *AWSTerraformProvider) *EC2AmiSupplier { } } -func (s EC2AmiSupplier) Resources() ([]resource.Resource, error) { +func (s *EC2AmiSupplier) Resources() ([]resource.Resource, error) { images, err := s.client.ListAllImages() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsAmiResourceType) @@ -52,7 +52,7 @@ func (s EC2AmiSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s EC2AmiSupplier) readAMI(id string) (cty.Value, error) { +func (s *EC2AmiSupplier) readAMI(id string) (cty.Value, error) { resImage, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: resourceaws.AwsAmiResourceType, ID: id, diff --git a/pkg/remote/aws/ec2_ebs_snapshot_supplier.go b/pkg/remote/aws/ec2_ebs_snapshot_supplier.go index 66184edb..d0b9e01b 100644 --- a/pkg/remote/aws/ec2_ebs_snapshot_supplier.go +++ b/pkg/remote/aws/ec2_ebs_snapshot_supplier.go @@ -32,7 +32,7 @@ func NewEC2EbsSnapshotSupplier(provider *AWSTerraformProvider) *EC2EbsSnapshotSu } } -func (s EC2EbsSnapshotSupplier) Resources() ([]resource.Resource, error) { +func (s *EC2EbsSnapshotSupplier) Resources() ([]resource.Resource, error) { snapshots, err := s.client.ListAllSnapshots() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsEbsSnapshotResourceType) @@ -53,7 +53,7 @@ func (s EC2EbsSnapshotSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s EC2EbsSnapshotSupplier) readEbsSnapshot(snapshot ec2.Snapshot) (cty.Value, error) { +func (s *EC2EbsSnapshotSupplier) readEbsSnapshot(snapshot ec2.Snapshot) (cty.Value, error) { id := aws.StringValue(snapshot.SnapshotId) resSnapshot, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: resourceaws.AwsEbsSnapshotResourceType, diff --git a/pkg/remote/aws/ec2_ebs_volume_supplier.go b/pkg/remote/aws/ec2_ebs_volume_supplier.go index ea83438b..2cc504ca 100644 --- a/pkg/remote/aws/ec2_ebs_volume_supplier.go +++ b/pkg/remote/aws/ec2_ebs_volume_supplier.go @@ -32,7 +32,7 @@ func NewEC2EbsVolumeSupplier(provider *AWSTerraformProvider) *EC2EbsVolumeSuppli } } -func (s EC2EbsVolumeSupplier) Resources() ([]resource.Resource, error) { +func (s *EC2EbsVolumeSupplier) Resources() ([]resource.Resource, error) { volumes, err := s.client.ListAllVolumes() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsEbsVolumeResourceType) @@ -53,7 +53,7 @@ func (s EC2EbsVolumeSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s EC2EbsVolumeSupplier) readEbsVolume(volume ec2.Volume) (cty.Value, error) { +func (s *EC2EbsVolumeSupplier) readEbsVolume(volume ec2.Volume) (cty.Value, error) { id := aws.StringValue(volume.VolumeId) resVolume, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: resourceaws.AwsEbsVolumeResourceType, diff --git a/pkg/remote/aws/ec2_eip_association_supplier.go b/pkg/remote/aws/ec2_eip_association_supplier.go index 854ef4d2..bf1499c3 100644 --- a/pkg/remote/aws/ec2_eip_association_supplier.go +++ b/pkg/remote/aws/ec2_eip_association_supplier.go @@ -29,7 +29,7 @@ func NewEC2EipAssociationSupplier(provider *AWSTerraformProvider) *EC2EipAssocia terraform.NewParallelResourceReader(provider.Runner().SubRunner())} } -func (s EC2EipAssociationSupplier) Resources() ([]resource.Resource, error) { +func (s *EC2EipAssociationSupplier) Resources() ([]resource.Resource, error) { associationIds, err := s.client.ListAllAddressesAssociation() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsEipAssociationResourceType) @@ -50,7 +50,7 @@ func (s EC2EipAssociationSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s EC2EipAssociationSupplier) readEIPAssociation(assocId string) (cty.Value, error) { +func (s *EC2EipAssociationSupplier) readEIPAssociation(assocId string) (cty.Value, error) { resAssoc, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: resourceaws.AwsEipAssociationResourceType, ID: assocId, diff --git a/pkg/remote/aws/ec2_eip_supplier.go b/pkg/remote/aws/ec2_eip_supplier.go index 84e9e23e..472f7638 100644 --- a/pkg/remote/aws/ec2_eip_supplier.go +++ b/pkg/remote/aws/ec2_eip_supplier.go @@ -32,7 +32,7 @@ func NewEC2EipSupplier(provider *AWSTerraformProvider) *EC2EipSupplier { } } -func (s EC2EipSupplier) Resources() ([]resource.Resource, error) { +func (s *EC2EipSupplier) Resources() ([]resource.Resource, error) { addresses, err := s.client.ListAllAddresses() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsEipResourceType) @@ -53,7 +53,7 @@ func (s EC2EipSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s EC2EipSupplier) readEIP(address ec2.Address) (cty.Value, error) { +func (s *EC2EipSupplier) readEIP(address ec2.Address) (cty.Value, error) { id := aws.StringValue(address.AllocationId) resAddress, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: resourceaws.AwsEipResourceType, diff --git a/pkg/remote/aws/ec2_instance_supplier.go b/pkg/remote/aws/ec2_instance_supplier.go index c7eadc11..f2215199 100644 --- a/pkg/remote/aws/ec2_instance_supplier.go +++ b/pkg/remote/aws/ec2_instance_supplier.go @@ -31,7 +31,7 @@ func NewEC2InstanceSupplier(provider *AWSTerraformProvider) *EC2InstanceSupplier } } -func (s EC2InstanceSupplier) Resources() ([]resource.Resource, error) { +func (s *EC2InstanceSupplier) Resources() ([]resource.Resource, error) { instances, err := s.client.ListAllInstances() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsInstanceResourceType) @@ -53,7 +53,7 @@ func (s EC2InstanceSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s EC2InstanceSupplier) readInstance(id string) (cty.Value, error) { +func (s *EC2InstanceSupplier) readInstance(id string) (cty.Value, error) { resInstance, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: resourceaws.AwsInstanceResourceType, ID: id, diff --git a/pkg/remote/aws/ec2_key_pair_supplier.go b/pkg/remote/aws/ec2_key_pair_supplier.go index e8af5488..4662d137 100644 --- a/pkg/remote/aws/ec2_key_pair_supplier.go +++ b/pkg/remote/aws/ec2_key_pair_supplier.go @@ -31,7 +31,7 @@ func NewEC2KeyPairSupplier(provider *AWSTerraformProvider) *EC2KeyPairSupplier { } } -func (s EC2KeyPairSupplier) Resources() ([]resource.Resource, error) { +func (s *EC2KeyPairSupplier) Resources() ([]resource.Resource, error) { keyPairs, err := s.client.ListAllKeyPairs() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsKeyPairResourceType) @@ -52,7 +52,7 @@ func (s EC2KeyPairSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s EC2KeyPairSupplier) readKeyPair(name string) (cty.Value, error) { +func (s *EC2KeyPairSupplier) readKeyPair(name string) (cty.Value, error) { resKp, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: resourceaws.AwsKeyPairResourceType, ID: name, diff --git a/pkg/remote/aws/ecr_repository_supplier.go b/pkg/remote/aws/ecr_repository_supplier.go index 72501f1f..531d590b 100644 --- a/pkg/remote/aws/ecr_repository_supplier.go +++ b/pkg/remote/aws/ecr_repository_supplier.go @@ -30,7 +30,7 @@ func NewECRRepositorySupplier(provider *AWSTerraformProvider) *ECRRepositorySupp } } -func (r ECRRepositorySupplier) Resources() ([]resource.Resource, error) { +func (r *ECRRepositorySupplier) Resources() ([]resource.Resource, error) { repositories, err := r.client.ListAllRepositories() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsEcrRepositoryResourceType) @@ -51,7 +51,7 @@ func (r ECRRepositorySupplier) Resources() ([]resource.Resource, error) { return r.deserializer.Deserialize(retrieve) } -func (r ECRRepositorySupplier) readRepository(repository *ecr.Repository) (cty.Value, error) { +func (r *ECRRepositorySupplier) readRepository(repository *ecr.Repository) (cty.Value, error) { val, err := r.reader.ReadResource(terraform.ReadResourceArgs{ ID: *repository.RepositoryName, Ty: aws.AwsEcrRepositoryResourceType, diff --git a/pkg/remote/aws/iam_access_key_supplier.go b/pkg/remote/aws/iam_access_key_supplier.go index bcad5881..73e8a9f4 100644 --- a/pkg/remote/aws/iam_access_key_supplier.go +++ b/pkg/remote/aws/iam_access_key_supplier.go @@ -31,7 +31,7 @@ func NewIamAccessKeySupplier(provider *AWSTerraformProvider) *IamAccessKeySuppli } } -func (s IamAccessKeySupplier) Resources() ([]resource.Resource, error) { +func (s *IamAccessKeySupplier) Resources() ([]resource.Resource, error) { keys, err := listIamAccessKeys(s.client) if err != nil { return nil, err @@ -52,7 +52,7 @@ func (s IamAccessKeySupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s IamAccessKeySupplier) readRes(key *iam.AccessKeyMetadata) (cty.Value, error) { +func (s *IamAccessKeySupplier) readRes(key *iam.AccessKeyMetadata) (cty.Value, error) { res, err := s.reader.ReadResource( terraform.ReadResourceArgs{ Ty: resourceaws.AwsIamAccessKeyResourceType, diff --git a/pkg/remote/aws/iam_policy_supplier.go b/pkg/remote/aws/iam_policy_supplier.go index 063dc25f..b266f221 100644 --- a/pkg/remote/aws/iam_policy_supplier.go +++ b/pkg/remote/aws/iam_policy_supplier.go @@ -32,7 +32,7 @@ func NewIamPolicySupplier(provider *AWSTerraformProvider) *IamPolicySupplier { } } -func (s IamPolicySupplier) Resources() ([]resource.Resource, error) { +func (s *IamPolicySupplier) Resources() ([]resource.Resource, error) { policies, err := listIamPolicies(s.client) if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsIamPolicyResourceType) @@ -53,7 +53,7 @@ func (s IamPolicySupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s IamPolicySupplier) readRes(resource *iam.Policy) (cty.Value, error) { +func (s *IamPolicySupplier) readRes(resource *iam.Policy) (cty.Value, error) { res, err := s.reader.ReadResource( terraform.ReadResourceArgs{ Ty: resourceaws.AwsIamPolicyResourceType, diff --git a/pkg/remote/aws/iam_role_policy_attachment_supplier.go b/pkg/remote/aws/iam_role_policy_attachment_supplier.go index c4907189..6a5347cc 100644 --- a/pkg/remote/aws/iam_role_policy_attachment_supplier.go +++ b/pkg/remote/aws/iam_role_policy_attachment_supplier.go @@ -31,7 +31,7 @@ func NewIamRolePolicyAttachmentSupplier(provider *AWSTerraformProvider) *IamRole } } -func (s IamRolePolicyAttachmentSupplier) Resources() ([]resource.Resource, error) { +func (s *IamRolePolicyAttachmentSupplier) Resources() ([]resource.Resource, error) { roles, err := listIamRoles(s.client, resourceaws.AwsIamRolePolicyAttachmentResourceType) if err != nil { return nil, err @@ -66,7 +66,7 @@ func (s IamRolePolicyAttachmentSupplier) Resources() ([]resource.Resource, error return s.deserializer.Deserialize(results) } -func (s IamRolePolicyAttachmentSupplier) readRes(attachedPol attachedRolePolicy) (cty.Value, error) { +func (s *IamRolePolicyAttachmentSupplier) readRes(attachedPol attachedRolePolicy) (cty.Value, error) { res, err := s.reader.ReadResource( terraform.ReadResourceArgs{ Ty: resourceaws.AwsIamRolePolicyAttachmentResourceType, diff --git a/pkg/remote/aws/iam_role_policy_supplier.go b/pkg/remote/aws/iam_role_policy_supplier.go index 58c9019e..054ded9f 100644 --- a/pkg/remote/aws/iam_role_policy_supplier.go +++ b/pkg/remote/aws/iam_role_policy_supplier.go @@ -33,7 +33,7 @@ func NewIamRolePolicySupplier(provider *AWSTerraformProvider) *IamRolePolicySupp } } -func (s IamRolePolicySupplier) Resources() ([]resource.Resource, error) { +func (s *IamRolePolicySupplier) Resources() ([]resource.Resource, error) { policies, err := listIamRolePolicies(s.client, resourceaws.AwsIamRolePolicyResourceType) if err != nil { return nil, err @@ -52,7 +52,7 @@ func (s IamRolePolicySupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s IamRolePolicySupplier) readRes(name string) (cty.Value, error) { +func (s *IamRolePolicySupplier) readRes(name string) (cty.Value, error) { res, err := s.reader.ReadResource( terraform.ReadResourceArgs{ Ty: resourceaws.AwsIamRolePolicyResourceType, diff --git a/pkg/remote/aws/iam_role_supplier.go b/pkg/remote/aws/iam_role_supplier.go index 92b4dc97..d3f5f252 100644 --- a/pkg/remote/aws/iam_role_supplier.go +++ b/pkg/remote/aws/iam_role_supplier.go @@ -45,7 +45,7 @@ func awsIamRoleShouldBeIgnored(roleName string) bool { return ok } -func (s IamRoleSupplier) Resources() ([]resource.Resource, error) { +func (s *IamRoleSupplier) Resources() ([]resource.Resource, error) { roles, err := listIamRoles(s.client, resourceaws.AwsIamRoleResourceType) if err != nil { return nil, err @@ -69,7 +69,7 @@ func (s IamRoleSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s IamRoleSupplier) readRes(resource *iam.Role) (cty.Value, error) { +func (s *IamRoleSupplier) readRes(resource *iam.Role) (cty.Value, error) { res, err := s.reader.ReadResource( terraform.ReadResourceArgs{ Ty: resourceaws.AwsIamRoleResourceType, diff --git a/pkg/remote/aws/iam_user_policy_attachment_supplier.go b/pkg/remote/aws/iam_user_policy_attachment_supplier.go index e687543a..e881811b 100644 --- a/pkg/remote/aws/iam_user_policy_attachment_supplier.go +++ b/pkg/remote/aws/iam_user_policy_attachment_supplier.go @@ -31,7 +31,7 @@ func NewIamUserPolicyAttachmentSupplier(provider *AWSTerraformProvider) *IamUser } } -func (s IamUserPolicyAttachmentSupplier) Resources() ([]resource.Resource, error) { +func (s *IamUserPolicyAttachmentSupplier) Resources() ([]resource.Resource, error) { users, err := listIamUsers(s.client, resourceaws.AwsIamUserPolicyAttachmentResourceType) if err != nil { return nil, err @@ -63,7 +63,7 @@ func (s IamUserPolicyAttachmentSupplier) Resources() ([]resource.Resource, error return s.deserializer.Deserialize(results) } -func (s IamUserPolicyAttachmentSupplier) readRes(attachedPol attachedUserPolicy) (cty.Value, error) { +func (s *IamUserPolicyAttachmentSupplier) readRes(attachedPol attachedUserPolicy) (cty.Value, error) { res, err := s.reader.ReadResource( terraform.ReadResourceArgs{ Ty: resourceaws.AwsIamUserPolicyAttachmentResourceType, diff --git a/pkg/remote/aws/iam_user_policy_supplier.go b/pkg/remote/aws/iam_user_policy_supplier.go index 261d98e9..75984066 100644 --- a/pkg/remote/aws/iam_user_policy_supplier.go +++ b/pkg/remote/aws/iam_user_policy_supplier.go @@ -33,7 +33,7 @@ func NewIamUserPolicySupplier(provider *AWSTerraformProvider) *IamUserPolicySupp } } -func (s IamUserPolicySupplier) Resources() ([]resource.Resource, error) { +func (s *IamUserPolicySupplier) Resources() ([]resource.Resource, error) { users, err := listIamUsers(s.client, resourceaws.AwsIamUserPolicyResourceType) if err != nil { return nil, err @@ -66,7 +66,7 @@ func (s IamUserPolicySupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s IamUserPolicySupplier) readRes(policyName string) (cty.Value, error) { +func (s *IamUserPolicySupplier) readRes(policyName string) (cty.Value, error) { res, err := s.reader.ReadResource( terraform.ReadResourceArgs{ Ty: resourceaws.AwsIamUserPolicyResourceType, diff --git a/pkg/remote/aws/iam_user_supplier.go b/pkg/remote/aws/iam_user_supplier.go index f7df0d8b..6e9e03d1 100644 --- a/pkg/remote/aws/iam_user_supplier.go +++ b/pkg/remote/aws/iam_user_supplier.go @@ -31,7 +31,7 @@ func NewIamUserSupplier(provider *AWSTerraformProvider) *IamUserSupplier { } } -func (s IamUserSupplier) Resources() ([]resource.Resource, error) { +func (s *IamUserSupplier) Resources() ([]resource.Resource, error) { users, err := listIamUsers(s.client, resourceaws.AwsIamUserResourceType) if err != nil { return nil, err @@ -52,7 +52,7 @@ func (s IamUserSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s IamUserSupplier) readRes(user *iam.User) (cty.Value, error) { +func (s *IamUserSupplier) readRes(user *iam.User) (cty.Value, error) { res, err := s.reader.ReadResource( terraform.ReadResourceArgs{ Ty: resourceaws.AwsIamUserResourceType, diff --git a/pkg/remote/aws/internet_gateway_supplier.go b/pkg/remote/aws/internet_gateway_supplier.go index df68ef54..a4f5391d 100644 --- a/pkg/remote/aws/internet_gateway_supplier.go +++ b/pkg/remote/aws/internet_gateway_supplier.go @@ -29,7 +29,7 @@ func NewInternetGatewaySupplier(provider *AWSTerraformProvider) *InternetGateway } } -func (s InternetGatewaySupplier) Resources() ([]resource.Resource, error) { +func (s *InternetGatewaySupplier) Resources() ([]resource.Resource, error) { internetGateways, err := listInternetGateways(s.client) if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsInternetGatewayResourceType) @@ -50,7 +50,7 @@ func (s InternetGatewaySupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(resources) } -func (s InternetGatewaySupplier) readInternetGateway(internetGateway ec2.InternetGateway) (cty.Value, error) { +func (s *InternetGatewaySupplier) readInternetGateway(internetGateway ec2.InternetGateway) (cty.Value, error) { var Ty resource.ResourceType = aws.AwsInternetGatewayResourceType val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: Ty, diff --git a/pkg/remote/aws/kms_alias_supplier.go b/pkg/remote/aws/kms_alias_supplier.go index d07612c6..e030aa00 100644 --- a/pkg/remote/aws/kms_alias_supplier.go +++ b/pkg/remote/aws/kms_alias_supplier.go @@ -30,7 +30,7 @@ func NewKMSAliasSupplier(provider *AWSTerraformProvider) *KMSAliasSupplier { } } -func (s KMSAliasSupplier) Resources() ([]resource.Resource, error) { +func (s *KMSAliasSupplier) Resources() ([]resource.Resource, error) { aliases, err := s.client.ListAllAliases() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsKmsAliasResourceType) @@ -51,7 +51,7 @@ func (s KMSAliasSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(retrieve) } -func (s KMSAliasSupplier) readAlias(alias *kms.AliasListEntry) (cty.Value, error) { +func (s *KMSAliasSupplier) readAlias(alias *kms.AliasListEntry) (cty.Value, error) { val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *alias.AliasName, Ty: aws.AwsKmsAliasResourceType, diff --git a/pkg/remote/aws/kms_key_supplier.go b/pkg/remote/aws/kms_key_supplier.go index 2010d6fe..914593de 100644 --- a/pkg/remote/aws/kms_key_supplier.go +++ b/pkg/remote/aws/kms_key_supplier.go @@ -30,7 +30,7 @@ func NewKMSKeySupplier(provider *AWSTerraformProvider) *KMSKeySupplier { } } -func (s KMSKeySupplier) Resources() ([]resource.Resource, error) { +func (s *KMSKeySupplier) Resources() ([]resource.Resource, error) { keys, err := s.client.ListAllKeys() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsKmsKeyResourceType) @@ -51,7 +51,7 @@ func (s KMSKeySupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(retrieve) } -func (s KMSKeySupplier) readKey(key *kms.KeyListEntry) (cty.Value, error) { +func (s *KMSKeySupplier) readKey(key *kms.KeyListEntry) (cty.Value, error) { val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *key.KeyId, Ty: aws.AwsKmsKeyResourceType, diff --git a/pkg/remote/aws/lambda_event_source_mapping_supplier.go b/pkg/remote/aws/lambda_event_source_mapping_supplier.go index bed3c307..a9b592b3 100644 --- a/pkg/remote/aws/lambda_event_source_mapping_supplier.go +++ b/pkg/remote/aws/lambda_event_source_mapping_supplier.go @@ -29,7 +29,7 @@ func NewLambdaEventSourceMappingSupplier(provider *AWSTerraformProvider) *Lambda } } -func (s LambdaEventSourceMappingSupplier) Resources() ([]resource.Resource, error) { +func (s *LambdaEventSourceMappingSupplier) Resources() ([]resource.Resource, error) { functions, err := s.client.ListAllLambdaEventSourceMappings() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsLambdaEventSourceMappingResourceType) @@ -49,7 +49,7 @@ func (s LambdaEventSourceMappingSupplier) Resources() ([]resource.Resource, erro return s.deserializer.Deserialize(results) } -func (s LambdaEventSourceMappingSupplier) readLambdaEventSourceMapping(sourceMappingConfig lambda.EventSourceMappingConfiguration) (cty.Value, error) { +func (s *LambdaEventSourceMappingSupplier) readLambdaEventSourceMapping(sourceMappingConfig lambda.EventSourceMappingConfiguration) (cty.Value, error) { resFunction, err := s.reader.ReadResource( terraform.ReadResourceArgs{ Ty: resourceaws.AwsLambdaEventSourceMappingResourceType, diff --git a/pkg/remote/aws/lambda_function_supplier.go b/pkg/remote/aws/lambda_function_supplier.go index c0bdffdb..d6832dc7 100644 --- a/pkg/remote/aws/lambda_function_supplier.go +++ b/pkg/remote/aws/lambda_function_supplier.go @@ -29,7 +29,7 @@ func NewLambdaFunctionSupplier(provider *AWSTerraformProvider) *LambdaFunctionSu } } -func (s LambdaFunctionSupplier) Resources() ([]resource.Resource, error) { +func (s *LambdaFunctionSupplier) Resources() ([]resource.Resource, error) { functions, err := s.client.ListAllLambdaFunctions() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsLambdaFunctionResourceType) @@ -50,7 +50,7 @@ func (s LambdaFunctionSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s LambdaFunctionSupplier) readLambda(function lambda.FunctionConfiguration) (cty.Value, error) { +func (s *LambdaFunctionSupplier) readLambda(function lambda.FunctionConfiguration) (cty.Value, error) { name := *function.FunctionName resFunction, err := s.reader.ReadResource( terraform.ReadResourceArgs{ diff --git a/pkg/remote/aws/nat_gateway_supplier.go b/pkg/remote/aws/nat_gateway_supplier.go index e7538d3b..16dd7704 100644 --- a/pkg/remote/aws/nat_gateway_supplier.go +++ b/pkg/remote/aws/nat_gateway_supplier.go @@ -29,7 +29,7 @@ func NewNatGatewaySupplier(provider *AWSTerraformProvider) *NatGatewaySupplier { } } -func (s NatGatewaySupplier) Resources() ([]resource.Resource, error) { +func (s *NatGatewaySupplier) Resources() ([]resource.Resource, error) { retrievedNatGateways, err := listNatGateways(s.client) if err != nil { @@ -58,7 +58,7 @@ func (s NatGatewaySupplier) Resources() ([]resource.Resource, error) { return resources, nil } -func (s NatGatewaySupplier) readNatGateway(gateway ec2.NatGateway) (cty.Value, error) { +func (s *NatGatewaySupplier) readNatGateway(gateway ec2.NatGateway) (cty.Value, error) { var Ty resource.ResourceType = aws.AwsNatGatewayResourceType val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *gateway.NatGatewayId, diff --git a/pkg/remote/aws/route53_health_check_supplier.go b/pkg/remote/aws/route53_health_check_supplier.go index 83e3ef41..38ab2761 100644 --- a/pkg/remote/aws/route53_health_check_supplier.go +++ b/pkg/remote/aws/route53_health_check_supplier.go @@ -30,7 +30,7 @@ func NewRoute53HealthCheckSupplier(provider *AWSTerraformProvider) *Route53Healt } } -func (s Route53HealthCheckSupplier) Resources() ([]resource.Resource, error) { +func (s *Route53HealthCheckSupplier) Resources() ([]resource.Resource, error) { healthChecks, err := s.client.ListAllHealthChecks() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsRoute53HealthCheckResourceType) @@ -51,7 +51,7 @@ func (s Route53HealthCheckSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(retrieve) } -func (s Route53HealthCheckSupplier) readHealthCheck(healthCheck *route53.HealthCheck) (cty.Value, error) { +func (s *Route53HealthCheckSupplier) readHealthCheck(healthCheck *route53.HealthCheck) (cty.Value, error) { val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *healthCheck.Id, Ty: aws.AwsRoute53HealthCheckResourceType, diff --git a/pkg/remote/aws/route53_record_supplier.go b/pkg/remote/aws/route53_record_supplier.go index 58e8527d..24384224 100644 --- a/pkg/remote/aws/route53_record_supplier.go +++ b/pkg/remote/aws/route53_record_supplier.go @@ -32,7 +32,7 @@ func NewRoute53RecordSupplier(provider *AWSTerraformProvider) *Route53RecordSupp terraform.NewParallelResourceReader(provider.Runner().SubRunner())} } -func (s Route53RecordSupplier) Resources() ([]resource.Resource, error) { +func (s *Route53RecordSupplier) Resources() ([]resource.Resource, error) { zones, err := s.listZones() if err != nil { @@ -52,7 +52,7 @@ func (s Route53RecordSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s Route53RecordSupplier) listZones() ([][2]string, error) { +func (s *Route53RecordSupplier) listZones() ([][2]string, error) { results := make([][2]string, 0) zones, err := s.client.ListAllZones() if err != nil { @@ -66,7 +66,7 @@ func (s Route53RecordSupplier) listZones() ([][2]string, error) { return results, nil } -func (s Route53RecordSupplier) listRecordsForZone(zoneId string, zoneName string) error { +func (s *Route53RecordSupplier) listRecordsForZone(zoneId string, zoneName string) error { records, err := s.client.ListRecordsForZone(zoneId) diff --git a/pkg/remote/aws/route53_zone_supplier.go b/pkg/remote/aws/route53_zone_supplier.go index 00658429..a06e99c8 100644 --- a/pkg/remote/aws/route53_zone_supplier.go +++ b/pkg/remote/aws/route53_zone_supplier.go @@ -34,7 +34,7 @@ func NewRoute53ZoneSupplier(provider *AWSTerraformProvider) *Route53ZoneSupplier } } -func (s Route53ZoneSupplier) Resources() ([]resource.Resource, error) { +func (s *Route53ZoneSupplier) Resources() ([]resource.Resource, error) { zones, err := s.client.ListAllZones() if err != nil { @@ -55,7 +55,7 @@ func (s Route53ZoneSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s Route53ZoneSupplier) readZone(hostedZone route53.HostedZone) (cty.Value, error) { +func (s *Route53ZoneSupplier) readZone(hostedZone route53.HostedZone) (cty.Value, error) { name := *hostedZone.Name zone, err := s.reader.ReadResource(terraform.ReadResourceArgs{ diff --git a/pkg/remote/aws/route_supplier.go b/pkg/remote/aws/route_supplier.go index 6405890d..ee742009 100644 --- a/pkg/remote/aws/route_supplier.go +++ b/pkg/remote/aws/route_supplier.go @@ -29,7 +29,7 @@ func NewRouteSupplier(provider *AWSTerraformProvider) *RouteSupplier { } } -func (s RouteSupplier) Resources() ([]resource.Resource, error) { +func (s *RouteSupplier) Resources() ([]resource.Resource, error) { routeTables, err := listRouteTables(s.client, aws.AwsRouteResourceType) if err != nil { @@ -59,7 +59,7 @@ func (s RouteSupplier) Resources() ([]resource.Resource, error) { return deserializedRoutes, nil } -func (s RouteSupplier) readRoute(tableId string, route ec2.Route) (cty.Value, error) { +func (s *RouteSupplier) readRoute(tableId string, route ec2.Route) (cty.Value, error) { var Ty resource.ResourceType = aws.AwsRouteResourceType attributes := map[string]interface{}{ diff --git a/pkg/remote/aws/route_table_association_supplier.go b/pkg/remote/aws/route_table_association_supplier.go index 32e148d5..d9efd058 100644 --- a/pkg/remote/aws/route_table_association_supplier.go +++ b/pkg/remote/aws/route_table_association_supplier.go @@ -29,7 +29,7 @@ func NewRouteTableAssociationSupplier(provider *AWSTerraformProvider) *RouteTabl } } -func (s RouteTableAssociationSupplier) Resources() ([]resource.Resource, error) { +func (s *RouteTableAssociationSupplier) Resources() ([]resource.Resource, error) { tables, err := listRouteTables(s.client, aws.AwsRouteTableAssociationResourceType) if err != nil { @@ -64,7 +64,7 @@ func (s RouteTableAssociationSupplier) Resources() ([]resource.Resource, error) return deserializedRouteTableAssociations, nil } -func (s RouteTableAssociationSupplier) readRouteTableAssociation(assoc ec2.RouteTableAssociation) (cty.Value, error) { +func (s *RouteTableAssociationSupplier) readRouteTableAssociation(assoc ec2.RouteTableAssociation) (cty.Value, error) { var Ty resource.ResourceType = aws.AwsRouteTableAssociationResourceType attributes := map[string]interface{}{ "route_table_id": *assoc.RouteTableId, @@ -83,7 +83,7 @@ func (s RouteTableAssociationSupplier) readRouteTableAssociation(assoc ec2.Route return *val, nil } -func (s RouteTableAssociationSupplier) shouldBeIgnored(assoc *ec2.RouteTableAssociation) bool { +func (s *RouteTableAssociationSupplier) shouldBeIgnored(assoc *ec2.RouteTableAssociation) bool { // Ignore when nothing is associated if assoc.GatewayId == nil && assoc.SubnetId == nil { diff --git a/pkg/remote/aws/route_table_supplier.go b/pkg/remote/aws/route_table_supplier.go index 9427cc25..86c633c2 100644 --- a/pkg/remote/aws/route_table_supplier.go +++ b/pkg/remote/aws/route_table_supplier.go @@ -37,14 +37,17 @@ func NewRouteTableSupplier(provider *AWSTerraformProvider) *RouteTableSupplier { } } -func (s RouteTableSupplier) Resources() ([]resource.Resource, error) { +func (s *RouteTableSupplier) Resources() ([]resource.Resource, error) { - retrievedRouteTables, err := listRouteTables(s.client, aws.AwsRouteTableResourceType) + results, err := listRouteTables(s.client, aws.AwsRouteTableResourceType) if err != nil { return nil, err } - for _, routeTable := range retrievedRouteTables { + retrievedDefaultRouteTables := []*ec2.RouteTable{} + retrievedRouteTables := []*ec2.RouteTable{} + + for _, routeTable := range results { res := *routeTable var isMain bool for _, assoc := range res.Associations { @@ -54,13 +57,16 @@ func (s RouteTableSupplier) Resources() ([]resource.Resource, error) { } } if isMain { - s.defaultRouteTableRunner.Run(func() (cty.Value, error) { - return s.readRouteTable(res, true) - }) + retrievedDefaultRouteTables = append(retrievedDefaultRouteTables, &res) continue } - s.routeTableRunner.Run(func() (cty.Value, error) { - return s.readRouteTable(res, false) + retrievedRouteTables = append(retrievedRouteTables, &res) + } + + for _, routeTable := range retrievedDefaultRouteTables { + res := *routeTable + s.defaultRouteTableRunner.Run(func() (cty.Value, error) { + return s.readRouteTable(res, true) }) } @@ -69,6 +75,14 @@ func (s RouteTableSupplier) Resources() ([]resource.Resource, error) { if err != nil { return nil, err } + + for _, routeTable := range retrievedRouteTables { + res := *routeTable + s.routeTableRunner.Run(func() (cty.Value, error) { + return s.readRouteTable(res, false) + }) + } + routeTableResources, err := s.routeTableRunner.Wait() if err != nil { return nil, err @@ -91,7 +105,7 @@ func (s RouteTableSupplier) Resources() ([]resource.Resource, error) { return resources, nil } -func (s RouteTableSupplier) readRouteTable(routeTable ec2.RouteTable, isMain bool) (cty.Value, error) { +func (s *RouteTableSupplier) readRouteTable(routeTable ec2.RouteTable, isMain bool) (cty.Value, error) { var Ty resource.ResourceType = aws.AwsRouteTableResourceType attributes := map[string]interface{}{} if isMain { diff --git a/pkg/remote/aws/s3_bucket_supplier.go b/pkg/remote/aws/s3_bucket_supplier.go index 4b78612f..34c07855 100644 --- a/pkg/remote/aws/s3_bucket_supplier.go +++ b/pkg/remote/aws/s3_bucket_supplier.go @@ -28,7 +28,7 @@ func NewS3BucketSupplier(provider *AWSTerraformProvider, repository repository.S } } -func (s S3BucketSupplier) Resources() ([]resource.Resource, error) { +func (s *S3BucketSupplier) Resources() ([]resource.Resource, error) { buckets, err := s.repository.ListAllBuckets() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsS3BucketResourceType) diff --git a/pkg/remote/aws/sns_topic_policy_supplier.go b/pkg/remote/aws/sns_topic_policy_supplier.go index 0813eaea..5babe3d1 100644 --- a/pkg/remote/aws/sns_topic_policy_supplier.go +++ b/pkg/remote/aws/sns_topic_policy_supplier.go @@ -30,7 +30,7 @@ func NewSNSTopicPolicySupplier(provider *AWSTerraformProvider) *SNSTopicPolicySu } } -func (s SNSTopicPolicySupplier) Resources() ([]resource.Resource, error) { +func (s *SNSTopicPolicySupplier) Resources() ([]resource.Resource, error) { topics, err := s.client.ListAllTopics() if err != nil { return nil, remoteerror.NewResourceEnumerationErrorWithType(err, aws.AwsSnsTopicPolicyResourceType, aws.AwsSnsTopicResourceType) @@ -51,7 +51,7 @@ func (s SNSTopicPolicySupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(retrieve) } -func (s SNSTopicPolicySupplier) readTopicPolicy(topic sns.Topic) (cty.Value, error) { +func (s *SNSTopicPolicySupplier) readTopicPolicy(topic sns.Topic) (cty.Value, error) { val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *topic.TopicArn, Ty: aws.AwsSnsTopicPolicyResourceType, diff --git a/pkg/remote/aws/sns_topic_subscription_supplier.go b/pkg/remote/aws/sns_topic_subscription_supplier.go index 6c2ec8e9..2eb05e9e 100644 --- a/pkg/remote/aws/sns_topic_subscription_supplier.go +++ b/pkg/remote/aws/sns_topic_subscription_supplier.go @@ -30,7 +30,7 @@ func NewSNSTopicSubscriptionSupplier(provider *AWSTerraformProvider) *SNSTopicSu } } -func (s SNSTopicSubscriptionSupplier) Resources() ([]resource.Resource, error) { +func (s *SNSTopicSubscriptionSupplier) Resources() ([]resource.Resource, error) { subscriptions, err := s.client.ListAllSubscriptions() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsSnsTopicSubscriptionResourceType) @@ -50,7 +50,7 @@ func (s SNSTopicSubscriptionSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(retrieve) } -func (s SNSTopicSubscriptionSupplier) readTopicSubscription(subscription *sns.Subscription) (cty.Value, error) { +func (s *SNSTopicSubscriptionSupplier) readTopicSubscription(subscription *sns.Subscription) (cty.Value, error) { val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *subscription.SubscriptionArn, Ty: aws.AwsSnsTopicSubscriptionResourceType, diff --git a/pkg/remote/aws/sns_topic_supplier.go b/pkg/remote/aws/sns_topic_supplier.go index 73159d42..d21e3e14 100644 --- a/pkg/remote/aws/sns_topic_supplier.go +++ b/pkg/remote/aws/sns_topic_supplier.go @@ -30,7 +30,7 @@ func NewSNSTopicSupplier(provider *AWSTerraformProvider) *SNSTopicSupplier { } } -func (s SNSTopicSupplier) Resources() ([]resource.Resource, error) { +func (s *SNSTopicSupplier) Resources() ([]resource.Resource, error) { topics, err := s.client.ListAllTopics() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsSnsTopicResourceType) @@ -51,7 +51,7 @@ func (s SNSTopicSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(retrieve) } -func (s SNSTopicSupplier) readTopic(topic sns.Topic) (cty.Value, error) { +func (s *SNSTopicSupplier) readTopic(topic sns.Topic) (cty.Value, error) { val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *topic.TopicArn, Ty: aws.AwsSnsTopicResourceType, diff --git a/pkg/remote/aws/sqs_queue_policy_supplier.go b/pkg/remote/aws/sqs_queue_policy_supplier.go index 79529f32..4a864265 100644 --- a/pkg/remote/aws/sqs_queue_policy_supplier.go +++ b/pkg/remote/aws/sqs_queue_policy_supplier.go @@ -28,7 +28,7 @@ func NewSqsQueuePolicySupplier(provider *AWSTerraformProvider) *SqsQueuePolicySu } } -func (s SqsQueuePolicySupplier) Resources() ([]resource.Resource, error) { +func (s *SqsQueuePolicySupplier) Resources() ([]resource.Resource, error) { queues, err := s.client.ListAllQueues() if err != nil { return nil, remoteerror.NewResourceEnumerationErrorWithType(err, aws.AwsSqsQueuePolicyResourceType, aws.AwsSqsQueueResourceType) @@ -49,7 +49,7 @@ func (s SqsQueuePolicySupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(resources) } -func (s SqsQueuePolicySupplier) readSqsQueuePolicy(queueURL string) (cty.Value, error) { +func (s *SqsQueuePolicySupplier) readSqsQueuePolicy(queueURL string) (cty.Value, error) { var Ty resource.ResourceType = aws.AwsSqsQueuePolicyResourceType val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: Ty, diff --git a/pkg/remote/aws/sqs_queue_supplier.go b/pkg/remote/aws/sqs_queue_supplier.go index 1823586b..ca4bf592 100644 --- a/pkg/remote/aws/sqs_queue_supplier.go +++ b/pkg/remote/aws/sqs_queue_supplier.go @@ -28,7 +28,7 @@ func NewSqsQueueSupplier(provider *AWSTerraformProvider) *SqsQueueSupplier { } } -func (s SqsQueueSupplier) Resources() ([]resource.Resource, error) { +func (s *SqsQueueSupplier) Resources() ([]resource.Resource, error) { queues, err := s.client.ListAllQueues() if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsSqsQueueResourceType) @@ -49,7 +49,7 @@ func (s SqsQueueSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(resources) } -func (s SqsQueueSupplier) readSqsQueue(queueURL string) (cty.Value, error) { +func (s *SqsQueueSupplier) readSqsQueue(queueURL string) (cty.Value, error) { var Ty resource.ResourceType = aws.AwsSqsQueueResourceType val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ Ty: Ty, diff --git a/pkg/remote/aws/subnet_supplier.go b/pkg/remote/aws/subnet_supplier.go index 83bfcbdb..7115fc4d 100644 --- a/pkg/remote/aws/subnet_supplier.go +++ b/pkg/remote/aws/subnet_supplier.go @@ -36,7 +36,7 @@ func NewSubnetSupplier(provider *AWSTerraformProvider) *SubnetSupplier { } } -func (s SubnetSupplier) Resources() ([]resource.Resource, error) { +func (s *SubnetSupplier) Resources() ([]resource.Resource, error) { input := ec2.DescribeSubnetsInput{} var subnets []*ec2.Subnet var defaultSubnets []*ec2.Subnet @@ -64,6 +64,11 @@ func (s SubnetSupplier) Resources() ([]resource.Resource, error) { }) } + subnetResources, err := s.subnetRunner.Wait() + if err != nil { + return nil, err + } + for _, item := range defaultSubnets { res := *item s.defaultSubnetRunner.Run(func() (cty.Value, error) { @@ -76,10 +81,6 @@ func (s SubnetSupplier) Resources() ([]resource.Resource, error) { if err != nil { return nil, err } - subnetResources, err := s.subnetRunner.Wait() - if err != nil { - return nil, err - } // Deserialize deserializedDefaultSubnets, err := s.defaultSubnetDeserializer.Deserialize(defaultSubnetResources) @@ -98,7 +99,7 @@ func (s SubnetSupplier) Resources() ([]resource.Resource, error) { return resources, nil } -func (s SubnetSupplier) readSubnet(subnet ec2.Subnet) (cty.Value, error) { +func (s *SubnetSupplier) readSubnet(subnet ec2.Subnet) (cty.Value, error) { var Ty resource.ResourceType = aws.AwsSubnetResourceType if subnet.DefaultForAz != nil && *subnet.DefaultForAz { Ty = aws.AwsDefaultSubnetResourceType diff --git a/pkg/remote/aws/vpc_security_group_rule_supplier.go b/pkg/remote/aws/vpc_security_group_rule_supplier.go index 431f210a..33a2c435 100644 --- a/pkg/remote/aws/vpc_security_group_rule_supplier.go +++ b/pkg/remote/aws/vpc_security_group_rule_supplier.go @@ -38,7 +38,7 @@ func NewVPCSecurityGroupRuleSupplier(provider *AWSTerraformProvider) *VPCSecurit } } -func (s VPCSecurityGroupRuleSupplier) Resources() ([]resource.Resource, error) { +func (s *VPCSecurityGroupRuleSupplier) Resources() ([]resource.Resource, error) { securityGroups, defaultSecurityGroups, err := listSecurityGroups(s.client) if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsSecurityGroupRuleResourceType) @@ -63,7 +63,7 @@ func (s VPCSecurityGroupRuleSupplier) Resources() ([]resource.Resource, error) { return s.deserializer.Deserialize(results) } -func (s VPCSecurityGroupRuleSupplier) readSecurityGroupRule(securityGroupRule resourceaws.AwsSecurityGroupRule) (cty.Value, error) { +func (s *VPCSecurityGroupRuleSupplier) readSecurityGroupRule(securityGroupRule resourceaws.AwsSecurityGroupRule) (cty.Value, error) { id := securityGroupRule.Id f := func(v *[]string) []string { if v != nil { @@ -94,7 +94,7 @@ func (s VPCSecurityGroupRuleSupplier) readSecurityGroupRule(securityGroupRule re return *resSgRule, nil } -func (s VPCSecurityGroupRuleSupplier) listSecurityGroupsRules(securityGroups []*ec2.SecurityGroup) []resourceaws.AwsSecurityGroupRule { +func (s *VPCSecurityGroupRuleSupplier) listSecurityGroupsRules(securityGroups []*ec2.SecurityGroup) []resourceaws.AwsSecurityGroupRule { var securityGroupsRules []resourceaws.AwsSecurityGroupRule for _, sg := range securityGroups { for _, rule := range sg.IpPermissions { @@ -109,7 +109,7 @@ func (s VPCSecurityGroupRuleSupplier) listSecurityGroupsRules(securityGroups []* // addSecurityGroupRule will iterate through each "Source" as per Aws definition and create a // rule with custom attributes -func (s VPCSecurityGroupRuleSupplier) addSecurityGroupRule(ruleType string, rule *ec2.IpPermission, sg *ec2.SecurityGroup) []resourceaws.AwsSecurityGroupRule { +func (s *VPCSecurityGroupRuleSupplier) addSecurityGroupRule(ruleType string, rule *ec2.IpPermission, sg *ec2.SecurityGroup) []resourceaws.AwsSecurityGroupRule { var rules []resourceaws.AwsSecurityGroupRule for _, groupPair := range rule.UserIdGroupPairs { r := resourceaws.AwsSecurityGroupRule{ @@ -179,7 +179,7 @@ func (s VPCSecurityGroupRuleSupplier) addSecurityGroupRule(ruleType string, rule return rules } -func (s VPCSecurityGroupRuleSupplier) isDefaultIngress(rule *resourceaws.AwsSecurityGroupRule) bool { +func (s *VPCSecurityGroupRuleSupplier) isDefaultIngress(rule *resourceaws.AwsSecurityGroupRule) bool { return rule.Type != nil && *rule.Type == sgRuleTypeIngress && rule.FromPort != nil && @@ -196,7 +196,7 @@ func (s VPCSecurityGroupRuleSupplier) isDefaultIngress(rule *resourceaws.AwsSecu *rule.Self } -func (s VPCSecurityGroupRuleSupplier) isDefaultEgress(rule *resourceaws.AwsSecurityGroupRule) bool { +func (s *VPCSecurityGroupRuleSupplier) isDefaultEgress(rule *resourceaws.AwsSecurityGroupRule) bool { return rule.Type != nil && *rule.Type == sgRuleTypeEgress && rule.FromPort != nil && diff --git a/pkg/remote/aws/vpc_security_group_supplier.go b/pkg/remote/aws/vpc_security_group_supplier.go index 457276e2..4ec2092e 100644 --- a/pkg/remote/aws/vpc_security_group_supplier.go +++ b/pkg/remote/aws/vpc_security_group_supplier.go @@ -36,7 +36,7 @@ func NewVPCSecurityGroupSupplier(provider *AWSTerraformProvider) *VPCSecurityGro } } -func (s VPCSecurityGroupSupplier) Resources() ([]resource.Resource, error) { +func (s *VPCSecurityGroupSupplier) Resources() ([]resource.Resource, error) { securityGroups, defaultSecurityGroups, err := listSecurityGroups(s.client) if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsSecurityGroupResourceType) @@ -81,7 +81,7 @@ func (s VPCSecurityGroupSupplier) Resources() ([]resource.Resource, error) { return resources, nil } -func (s VPCSecurityGroupSupplier) readSecurityGroup(securityGroup ec2.SecurityGroup) (cty.Value, error) { +func (s *VPCSecurityGroupSupplier) readSecurityGroup(securityGroup ec2.SecurityGroup) (cty.Value, error) { var Ty resource.ResourceType = resourceaws.AwsSecurityGroupResourceType if isDefaultSecurityGroup(securityGroup) { Ty = resourceaws.AwsDefaultSecurityGroupResourceType diff --git a/pkg/remote/aws/vpc_supplier.go b/pkg/remote/aws/vpc_supplier.go index 046ab771..f3b121f3 100644 --- a/pkg/remote/aws/vpc_supplier.go +++ b/pkg/remote/aws/vpc_supplier.go @@ -36,7 +36,7 @@ func NewVPCSupplier(provider *AWSTerraformProvider) *VPCSupplier { } } -func (s VPCSupplier) Resources() ([]resource.Resource, error) { +func (s *VPCSupplier) Resources() ([]resource.Resource, error) { input := ec2.DescribeVpcsInput{} var VPCs []*ec2.Vpc var defaultVPCs []*ec2.Vpc @@ -64,6 +64,11 @@ func (s VPCSupplier) Resources() ([]resource.Resource, error) { }) } + VPCResources, err := s.vpcRunner.Wait() + if err != nil { + return nil, err + } + for _, item := range defaultVPCs { res := *item s.defaultVPCRunner.Run(func() (cty.Value, error) { @@ -76,10 +81,6 @@ func (s VPCSupplier) Resources() ([]resource.Resource, error) { if err != nil { return nil, err } - VPCResources, err := s.vpcRunner.Wait() - if err != nil { - return nil, err - } // Deserialize deserializedDefaultVPCs, err := s.defaultVPCDeserializer.Deserialize(defaultVPCResources) @@ -98,7 +99,7 @@ func (s VPCSupplier) Resources() ([]resource.Resource, error) { return resources, nil } -func (s VPCSupplier) readVPC(vpc ec2.Vpc) (cty.Value, error) { +func (s *VPCSupplier) readVPC(vpc ec2.Vpc) (cty.Value, error) { var Ty resource.ResourceType = aws.AwsVpcResourceType if vpc.IsDefault != nil && *vpc.IsDefault { Ty = aws.AwsDefaultVpcResourceType From 53103f667ce68c201a6c56394dbbd563c3b68fbb Mon Sep 17 00:00:00 2001 From: Martin Guibert Date: Wed, 17 Mar 2021 14:33:45 +0100 Subject: [PATCH 2/4] when sns subscitpion is pending prevent crash and show an alert --- pkg/remote/aws/init.go | 2 +- .../aws/sns_topic_subscription_supplier.go | 39 ++++++++++++++++--- .../sns_topic_subscription_supplier_test.go | 28 ++++++++++++- .../sns_topic_subscription_deserializer.go | 1 + 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/pkg/remote/aws/init.go b/pkg/remote/aws/init.go index 21102c21..a57c0d4a 100644 --- a/pkg/remote/aws/init.go +++ b/pkg/remote/aws/init.go @@ -68,7 +68,7 @@ func Init(alerter *alerter.Alerter, providerLibrary *terraform.ProviderLibrary, supplierLibrary.AddSupplier(NewSqsQueuePolicySupplier(provider)) supplierLibrary.AddSupplier(NewSNSTopicSupplier(provider)) supplierLibrary.AddSupplier(NewSNSTopicPolicySupplier(provider)) - supplierLibrary.AddSupplier(NewSNSTopicSubscriptionSupplier(provider)) + supplierLibrary.AddSupplier(NewSNSTopicSubscriptionSupplier(provider, alerter)) supplierLibrary.AddSupplier(NewDynamoDBTableSupplier(provider)) supplierLibrary.AddSupplier(NewRoute53HealthCheckSupplier(provider)) supplierLibrary.AddSupplier(NewCloudfrontDistributionSupplier(provider)) diff --git a/pkg/remote/aws/sns_topic_subscription_supplier.go b/pkg/remote/aws/sns_topic_subscription_supplier.go index 2eb05e9e..b42d73b8 100644 --- a/pkg/remote/aws/sns_topic_subscription_supplier.go +++ b/pkg/remote/aws/sns_topic_subscription_supplier.go @@ -1,12 +1,17 @@ package aws import ( + "fmt" + + awssdk "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/sns" - "github.com/cloudskiff/driftctl/pkg/remote/aws/repository" - remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" "github.com/sirupsen/logrus" "github.com/zclconf/go-cty/cty" + "github.com/cloudskiff/driftctl/pkg/alerter" + "github.com/cloudskiff/driftctl/pkg/remote/aws/repository" + remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" + "github.com/cloudskiff/driftctl/pkg/remote/deserializer" "github.com/cloudskiff/driftctl/pkg/resource" "github.com/cloudskiff/driftctl/pkg/resource/aws" @@ -14,19 +19,35 @@ import ( "github.com/cloudskiff/driftctl/pkg/terraform" ) +type pendingTopicAlert struct { + endpoint *string +} + +func (p *pendingTopicAlert) Message() string { + return fmt.Sprintf("%s with pending confirmation status for endpoint \"%s\" will be ignored", + aws.AwsSnsTopicSubscriptionResourceType, + awssdk.StringValue(p.endpoint)) +} + +func (p *pendingTopicAlert) ShouldIgnoreResource() bool { + return false +} + type SNSTopicSubscriptionSupplier struct { reader terraform.ResourceReader deserializer deserializer.CTYDeserializer client repository.SNSRepository runner *terraform.ParallelResourceReader + alerter alerter.AlerterInterface } -func NewSNSTopicSubscriptionSupplier(provider *AWSTerraformProvider) *SNSTopicSubscriptionSupplier { +func NewSNSTopicSubscriptionSupplier(provider *AWSTerraformProvider, a alerter.AlerterInterface) *SNSTopicSubscriptionSupplier { return &SNSTopicSubscriptionSupplier{ provider, awsdeserializer.NewSNSTopicSubscriptionDeserializer(), repository.NewSNSClient(provider.session), terraform.NewParallelResourceReader(provider.Runner().SubRunner()), + a, } } @@ -38,7 +59,7 @@ func (s *SNSTopicSubscriptionSupplier) Resources() ([]resource.Resource, error) for _, subscription := range subscriptions { subscription := subscription s.runner.Run(func() (cty.Value, error) { - return s.readTopicSubscription(subscription) + return s.readTopicSubscription(subscription, s.alerter) }) } @@ -50,7 +71,15 @@ func (s *SNSTopicSubscriptionSupplier) Resources() ([]resource.Resource, error) return s.deserializer.Deserialize(retrieve) } -func (s *SNSTopicSubscriptionSupplier) readTopicSubscription(subscription *sns.Subscription) (cty.Value, error) { +func (s *SNSTopicSubscriptionSupplier) readTopicSubscription(subscription *sns.Subscription, alertr alerter.AlerterInterface) (cty.Value, error) { + if subscription.SubscriptionArn != nil && *subscription.SubscriptionArn == "PendingConfirmation" { + alertr.SendAlert( + fmt.Sprintf("%s.%s", aws.AwsSnsTopicSubscriptionResourceType, *subscription.SubscriptionArn), + &pendingTopicAlert{subscription.Endpoint}, + ) + return cty.NilVal, nil + } + val, err := s.reader.ReadResource(terraform.ReadResourceArgs{ ID: *subscription.SubscriptionArn, Ty: aws.AwsSnsTopicSubscriptionResourceType, diff --git a/pkg/remote/aws/sns_topic_subscription_supplier_test.go b/pkg/remote/aws/sns_topic_subscription_supplier_test.go index 8f0a9159..5d751488 100644 --- a/pkg/remote/aws/sns_topic_subscription_supplier_test.go +++ b/pkg/remote/aws/sns_topic_subscription_supplier_test.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go/service/sns" + "github.com/cloudskiff/driftctl/pkg/alerter" remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" resourceaws "github.com/cloudskiff/driftctl/pkg/resource/aws" @@ -35,6 +36,7 @@ func TestSNSTopicSubscriptionSupplier_Resources(t *testing.T) { test string dirName string mocks func(client *mocks.SNSRepository) + alerts alerter.Alerts err error }{ { @@ -56,6 +58,23 @@ func TestSNSTopicSubscriptionSupplier_Resources(t *testing.T) { }, err: nil, }, + { + test: "Multiple SNSTopic Subscription with one pending", + dirName: "sns_topic_subscription_multiple", + mocks: func(client *mocks.SNSRepository) { + client.On("ListAllSubscriptions").Return([]*sns.Subscription{ + {SubscriptionArn: aws.String("PendingConfirmation"), Endpoint: aws.String("TEST")}, + {SubscriptionArn: aws.String("arn:aws:sns:us-east-1:526954929923:user-updates-topic2:c0f794c5-a009-4db4-9147-4c55959787fa")}, + {SubscriptionArn: aws.String("arn:aws:sns:us-east-1:526954929923:user-updates-topic:b6e66147-2b31-4486-8d4b-2a2272264c8e")}, + }, nil) + }, + alerts: map[string][]alerter.Alert{ + "aws_sns_topic_subscription.PendingConfirmation": []alerter.Alert{ + &pendingTopicAlert{aws.String("TEST")}, + }, + }, + err: nil, + }, { test: "cannot list SNSTopic subscription", dirName: "sns_topic_subscription_list", @@ -72,14 +91,16 @@ func TestSNSTopicSubscriptionSupplier_Resources(t *testing.T) { supplierLibrary := resource.NewSupplierLibrary() if shouldUpdate { + a := alerter.NewAlerter() provider, err := InitTestAwsProvider(providerLibrary) if err != nil { t.Fatal(err) } - supplierLibrary.AddSupplier(NewSNSTopicSubscriptionSupplier(provider)) + supplierLibrary.AddSupplier(NewSNSTopicSubscriptionSupplier(provider, a)) } t.Run(c.test, func(tt *testing.T) { + a := alerter.NewAlerter() fakeClient := mocks.SNSRepository{} c.mocks(&fakeClient) provider := mocks2.NewMockedGoldenTFProvider(c.dirName, providerLibrary.Provider(terraform.AWS), shouldUpdate) @@ -89,10 +110,15 @@ func TestSNSTopicSubscriptionSupplier_Resources(t *testing.T) { topicSubscriptionDeserializer, &fakeClient, terraform.NewParallelResourceReader(parallel.NewParallelRunner(context.TODO(), 10)), + a, } got, err := s.Resources() assert.Equal(tt, c.err, err) + if c.alerts == nil { + c.alerts = map[string][]alerter.Alert{} + } + assert.Equal(tt, c.alerts, a.Retrieve()) mock.AssertExpectationsForObjects(tt) test.CtyTestDiff(got, c.dirName, provider, topicSubscriptionDeserializer, shouldUpdate, tt) }) diff --git a/pkg/resource/aws/deserializer/sns_topic_subscription_deserializer.go b/pkg/resource/aws/deserializer/sns_topic_subscription_deserializer.go index 51bd6949..c3f20095 100644 --- a/pkg/resource/aws/deserializer/sns_topic_subscription_deserializer.go +++ b/pkg/resource/aws/deserializer/sns_topic_subscription_deserializer.go @@ -23,6 +23,7 @@ func (s SNSTopicSubscriptionDeserializer) Deserialize(subscriptionsList []cty.Va subscriptions := make([]resource.Resource, 0) for _, value := range subscriptionsList { + value := value subscription, err := decodeSNSTopicSubscription(value) if err != nil { From 28f1a7e5107ce9c489332fbe1ccc0fea4918cd5a Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 18 Mar 2021 09:22:53 +0000 Subject: [PATCH 3/4] docs: update CONTRIBUTORS.md [skip ci] --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4c4c60fe..c8581035 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -21,6 +21,7 @@ Thank you to all the people who have already contributed to driftctl.
Herby Gillot

🔧
Toussaint Louis

💻 📖
Peter Sedgewick

📖 +
Raphaël

💻 From a33510e942ab8437f4c7fd77b78544fbc1080578 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 18 Mar 2021 09:22:54 +0000 Subject: [PATCH 4/4] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index fb72adea..de11a73a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -146,6 +146,15 @@ "contributions": [ "doc" ] + }, + { + "login": "sundowndev", + "name": "Raphaël", + "avatar_url": "https://avatars.githubusercontent.com/u/16480203?v=4", + "profile": "https://crvx.fr/", + "contributions": [ + "code" + ] } ] }