2020-12-09 15:31:34 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
2020-12-16 12:02:02 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/alerter"
|
2021-03-15 17:30:18 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/output"
|
2021-02-16 17:42:46 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/aws/client"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
|
2021-05-25 14:45:59 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/cache"
|
2021-06-11 15:10:06 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/common"
|
2020-12-09 15:31:34 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
2021-03-26 08:44:55 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
2020-12-09 15:31:34 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
const RemoteAWSTerraform = "aws+tf"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize remote (configure credentials, launch tf providers and start gRPC clients)
|
|
|
|
* Required to use Scanner
|
|
|
|
*/
|
2021-05-21 14:09:45 +00:00
|
|
|
|
2021-06-03 09:43:15 +00:00
|
|
|
func Init(version string, alerter *alerter.Alerter,
|
2021-05-21 14:09:45 +00:00
|
|
|
providerLibrary *terraform.ProviderLibrary,
|
|
|
|
supplierLibrary *resource.SupplierLibrary,
|
2021-06-11 15:10:06 +00:00
|
|
|
remoteLibrary *common.RemoteLibrary,
|
2021-05-21 14:09:45 +00:00
|
|
|
progress output.Progress,
|
|
|
|
resourceSchemaRepository *resource.SchemaRepository,
|
2021-06-12 14:17:23 +00:00
|
|
|
factory resource.ResourceFactory,
|
|
|
|
configDir string) error {
|
|
|
|
|
2021-06-09 15:28:40 +00:00
|
|
|
if version == "" {
|
|
|
|
version = "3.19.0"
|
|
|
|
}
|
2021-06-14 16:25:35 +00:00
|
|
|
provider, err := NewAWSTerraformProvider(version, progress, configDir)
|
2021-02-09 13:56:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = provider.Init()
|
2020-12-09 15:31:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:08:36 +00:00
|
|
|
repositoryCache := cache.New(100)
|
2021-05-25 14:45:59 +00:00
|
|
|
|
2021-06-04 10:22:17 +00:00
|
|
|
s3Repository := repository.NewS3Repository(client.NewAWSClientFactory(provider.session), repositoryCache)
|
2021-05-31 15:39:16 +00:00
|
|
|
ec2repository := repository.NewEC2Repository(provider.session, repositoryCache)
|
2021-06-04 10:06:36 +00:00
|
|
|
route53repository := repository.NewRoute53Repository(provider.session, repositoryCache)
|
2021-06-04 14:16:35 +00:00
|
|
|
lambdaRepository := repository.NewLambdaRepository(provider.session, repositoryCache)
|
2021-06-04 14:01:06 +00:00
|
|
|
rdsRepository := repository.NewRDSRepository(provider.session, repositoryCache)
|
2021-06-28 16:21:12 +00:00
|
|
|
sqsRepository := repository.NewSQSRepository(provider.session, repositoryCache)
|
|
|
|
snsRepository := repository.NewSNSRepository(provider.session, repositoryCache)
|
|
|
|
cloudfrontRepository := repository.NewCloudfrontRepository(provider.session, repositoryCache)
|
2021-06-04 15:24:10 +00:00
|
|
|
dynamoDBRepository := repository.NewDynamoDBRepository(provider.session, repositoryCache)
|
2021-06-04 16:25:06 +00:00
|
|
|
ecrRepository := repository.NewECRRepository(provider.session, repositoryCache)
|
2021-06-04 16:17:42 +00:00
|
|
|
kmsRepository := repository.NewKMSRepository(provider.session, repositoryCache)
|
2021-06-08 09:40:04 +00:00
|
|
|
iamRepository := repository.NewIAMRepository(provider.session, repositoryCache)
|
2021-05-31 15:39:16 +00:00
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
deserializer := resource.NewDeserializer(factory)
|
2021-01-22 17:06:17 +00:00
|
|
|
providerLibrary.AddProvider(terraform.AWS, provider)
|
|
|
|
|
2021-06-11 15:10:06 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewS3BucketEnumerator(s3Repository, factory, provider.Config))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsS3BucketResourceType, NewS3BucketDetailsFetcher(provider, deserializer))
|
2021-06-29 12:29:28 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewS3BucketInventoryEnumerator(s3Repository, factory, provider.Config))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsS3BucketInventoryResourceType, NewS3BucketInventoryDetailsFetcher(provider, deserializer))
|
2021-06-30 09:38:22 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewS3BucketNotificationEnumerator(s3Repository, factory, provider.Config))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsS3BucketNotificationResourceType, NewS3BucketNotificationDetailsFetcher(provider, deserializer))
|
2021-06-29 14:08:30 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewS3BucketMetricsEnumerator(s3Repository, factory, provider.Config))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsS3BucketMetricResourceType, NewS3BucketMetricsDetailsFetcher(provider, deserializer))
|
2021-07-05 15:27:47 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewS3BucketPolicyEnumerator(s3Repository, factory, provider.Config))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsS3BucketPolicyResourceType, NewS3BucketPolicyDetailsFetcher(provider, deserializer))
|
2021-07-06 13:00:41 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewS3BucketAnalyticEnumerator(s3Repository, factory, provider.Config))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsS3BucketAnalyticsConfigurationResourceType, NewS3BucketAnalyticDetailsFetcher(provider, deserializer))
|
2021-06-29 12:29:28 +00:00
|
|
|
|
2021-07-05 08:30:42 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2EbsVolumeEnumerator(ec2repository, factory))
|
2021-07-01 15:11:25 +00:00
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsEbsVolumeResourceType, common.NewGenericDetailsFetcher(aws.AwsEbsVolumeResourceType, provider, deserializer))
|
2021-07-05 08:30:42 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2EbsSnapshotEnumerator(ec2repository, factory))
|
2021-07-01 15:11:25 +00:00
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsEbsSnapshotResourceType, common.NewGenericDetailsFetcher(aws.AwsEbsSnapshotResourceType, provider, deserializer))
|
2021-07-05 08:30:42 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2EipEnumerator(ec2repository, factory))
|
2021-07-01 15:11:25 +00:00
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsEipResourceType, common.NewGenericDetailsFetcher(aws.AwsEipResourceType, provider, deserializer))
|
2021-07-05 08:30:42 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2AmiEnumerator(ec2repository, factory))
|
2021-07-01 08:52:30 +00:00
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsAmiResourceType, common.NewGenericDetailsFetcher(aws.AwsAmiResourceType, provider, deserializer))
|
2021-07-05 08:30:42 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2KeyPairEnumerator(ec2repository, factory))
|
2021-07-01 09:37:10 +00:00
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsKeyPairResourceType, common.NewGenericDetailsFetcher(aws.AwsKeyPairResourceType, provider, deserializer))
|
2021-07-05 08:30:42 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2EipAssociationEnumerator(ec2repository, factory))
|
2021-07-01 11:34:14 +00:00
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsEipAssociationResourceType, common.NewGenericDetailsFetcher(aws.AwsEipAssociationResourceType, provider, deserializer))
|
2021-07-05 08:30:42 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2InstanceEnumerator(ec2repository, factory))
|
2021-07-01 12:11:18 +00:00
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsInstanceResourceType, NewEC2InstanceDetailsFetcher(provider, deserializer))
|
2021-07-01 14:01:46 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2InternetGatewayEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsInternetGatewayResourceType, common.NewGenericDetailsFetcher(aws.AwsInternetGatewayResourceType, provider, deserializer))
|
2021-07-05 11:15:25 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewVPCEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsVpcResourceType, common.NewGenericDetailsFetcher(aws.AwsVpcResourceType, provider, deserializer))
|
|
|
|
remoteLibrary.AddEnumerator(NewDefaultVPCEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsDefaultVpcResourceType, common.NewGenericDetailsFetcher(aws.AwsDefaultVpcResourceType, provider, deserializer))
|
2021-07-05 10:31:11 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2RouteTableEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsRouteTableResourceType, common.NewGenericDetailsFetcher(aws.AwsRouteTableResourceType, provider, deserializer))
|
|
|
|
remoteLibrary.AddEnumerator(NewEC2DefaultRouteTableEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsDefaultRouteTableResourceType, NewEC2DefaultRouteTableDetailsFetcher(provider, deserializer))
|
2021-07-05 11:15:25 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2RouteTableAssociationEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsRouteTableAssociationResourceType, NewEC2RouteTableAssociationDetailsFetcher(provider, deserializer))
|
2021-07-02 13:47:42 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2SubnetEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsSubnetResourceType, common.NewGenericDetailsFetcher(aws.AwsSubnetResourceType, provider, deserializer))
|
|
|
|
remoteLibrary.AddEnumerator(NewEC2DefaultSubnetEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsDefaultSubnetResourceType, common.NewGenericDetailsFetcher(aws.AwsDefaultSubnetResourceType, provider, deserializer))
|
2021-07-07 14:53:19 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewVPCSecurityGroupEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsSecurityGroupResourceType, common.NewGenericDetailsFetcher(aws.AwsSecurityGroupResourceType, provider, deserializer))
|
|
|
|
remoteLibrary.AddEnumerator(NewVPCDefaultSecurityGroupEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsDefaultSecurityGroupResourceType, common.NewGenericDetailsFetcher(aws.AwsDefaultSecurityGroupResourceType, provider, deserializer))
|
2021-07-06 14:24:54 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewEC2NatGatewayEnumerator(ec2repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsNatGatewayResourceType, common.NewGenericDetailsFetcher(aws.AwsNatGatewayResourceType, provider, deserializer))
|
2021-07-01 09:53:26 +00:00
|
|
|
|
2021-07-01 14:45:46 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewKMSKeyEnumerator(kmsRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsKmsKeyResourceType, common.NewGenericDetailsFetcher(aws.AwsKmsKeyResourceType, provider, deserializer))
|
2021-07-01 15:03:40 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewKMSAliasEnumerator(kmsRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsKmsAliasResourceType, common.NewGenericDetailsFetcher(aws.AwsKmsAliasResourceType, provider, deserializer))
|
2021-07-01 09:53:26 +00:00
|
|
|
|
2021-07-05 10:07:11 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewRoute53HealthCheckEnumerator(route53repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsRoute53HealthCheckResourceType, common.NewGenericDetailsFetcher(aws.AwsRoute53HealthCheckResourceType, provider, deserializer))
|
2021-07-05 15:27:47 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewRoute53ZoneEnumerator(route53repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsRoute53ZoneResourceType, common.NewGenericDetailsFetcher(aws.AwsRoute53ZoneResourceType, provider, deserializer))
|
2021-07-06 09:23:52 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewRoute53RecordEnumerator(route53repository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsRoute53RecordResourceType, common.NewGenericDetailsFetcher(aws.AwsRoute53RecordResourceType, provider, deserializer))
|
2021-07-05 10:07:11 +00:00
|
|
|
|
2021-07-07 14:53:19 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewCloudfrontDistributionEnumerator(cloudfrontRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsCloudfrontDistributionResourceType, common.NewGenericDetailsFetcher(aws.AwsCloudfrontDistributionResourceType, provider, deserializer))
|
2021-07-05 16:43:11 +00:00
|
|
|
|
2021-07-07 15:08:17 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewRDSDBInstanceEnumerator(rdsRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsDbInstanceResourceType, common.NewGenericDetailsFetcher(aws.AwsDbInstanceResourceType, provider, deserializer))
|
2021-07-07 15:22:13 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewRDSDBSubnetGroupEnumerator(rdsRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsDbSubnetGroupResourceType, common.NewGenericDetailsFetcher(aws.AwsDbSubnetGroupResourceType, provider, deserializer))
|
2021-07-07 15:08:17 +00:00
|
|
|
|
2021-07-08 14:13:51 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewSQSQueueEnumerator(sqsRepository, factory))
|
2021-07-07 18:38:03 +00:00
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsSqsQueueResourceType, common.NewGenericDetailsFetcher(aws.AwsSqsQueueResourceType, provider, deserializer))
|
2021-07-07 20:42:21 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewSQSQueuePolicyEnumerator(sqsRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsSqsQueuePolicyResourceType, common.NewGenericDetailsFetcher(aws.AwsSqsQueuePolicyResourceType, provider, deserializer))
|
2021-07-07 18:38:03 +00:00
|
|
|
|
2021-07-06 09:31:01 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewSNSTopicEnumerator(snsRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsSnsTopicResourceType, NewSNSTopicDetailsFetcher(provider, deserializer))
|
2021-07-06 16:46:38 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewSNSTopicPolicyEnumerator(snsRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsSnsTopicPolicyResourceType, NewSNSTopicPolicyDetailsFetcher(provider, deserializer))
|
2021-07-07 17:23:43 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewSNSTopicSubscriptionEnumerator(snsRepository, factory, alerter))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsSnsTopicSubscriptionResourceType, NewSNSTopicSubscriptionDetailsFetcher(provider, deserializer))
|
2021-07-06 09:31:01 +00:00
|
|
|
|
2021-07-08 13:59:34 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewDynamoDBTableEnumerator(dynamoDBRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsDynamodbTableResourceType, NewDynamoDBTableDetailsFetcher(provider, deserializer))
|
|
|
|
|
2021-07-08 14:05:23 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewIamPolicyEnumerator(iamRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsIamPolicyResourceType, common.NewGenericDetailsFetcher(aws.AwsIamPolicyResourceType, provider, deserializer))
|
|
|
|
|
2021-07-08 17:14:23 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewLambdaFunctionEnumerator(lambdaRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsLambdaFunctionResourceType, NewLambdaFunctionDetailsFetcher(provider, deserializer))
|
2021-07-08 17:27:38 +00:00
|
|
|
remoteLibrary.AddEnumerator(NewLambdaEventSourceMappingEnumerator(lambdaRepository, factory))
|
|
|
|
remoteLibrary.AddDetailsFetcher(aws.AwsLambdaEventSourceMappingResourceType, common.NewGenericDetailsFetcher(aws.AwsLambdaEventSourceMappingResourceType, provider, deserializer))
|
2021-07-08 17:14:23 +00:00
|
|
|
|
2021-06-07 13:02:12 +00:00
|
|
|
supplierLibrary.AddSupplier(NewIamUserSupplier(provider, deserializer, iamRepository))
|
|
|
|
supplierLibrary.AddSupplier(NewIamUserPolicySupplier(provider, deserializer, iamRepository))
|
|
|
|
supplierLibrary.AddSupplier(NewIamUserPolicyAttachmentSupplier(provider, deserializer, iamRepository))
|
|
|
|
supplierLibrary.AddSupplier(NewIamAccessKeySupplier(provider, deserializer, iamRepository))
|
|
|
|
supplierLibrary.AddSupplier(NewIamRoleSupplier(provider, deserializer, iamRepository))
|
|
|
|
supplierLibrary.AddSupplier(NewIamRolePolicySupplier(provider, deserializer, iamRepository))
|
|
|
|
supplierLibrary.AddSupplier(NewIamRolePolicyAttachmentSupplier(provider, deserializer, iamRepository))
|
2021-06-07 09:04:46 +00:00
|
|
|
supplierLibrary.AddSupplier(NewVPCSecurityGroupRuleSupplier(provider, deserializer, ec2repository))
|
|
|
|
supplierLibrary.AddSupplier(NewRouteSupplier(provider, deserializer, ec2repository))
|
2021-05-31 15:39:16 +00:00
|
|
|
supplierLibrary.AddSupplier(NewECRRepositorySupplier(provider, deserializer, ecrRepository))
|
2020-12-09 15:31:34 +00:00
|
|
|
|
2021-06-09 15:28:40 +00:00
|
|
|
err = resourceSchemaRepository.Init(version, provider.Schema())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-03-26 08:44:55 +00:00
|
|
|
aws.InitResourcesMetadata(resourceSchemaRepository)
|
|
|
|
|
2020-12-09 15:31:34 +00:00
|
|
|
return nil
|
|
|
|
}
|