driftctl/pkg/remote/aws/init.go

138 lines
8.8 KiB
Go
Raw Normal View History

package aws
import (
2020-12-16 12:02:02 +00:00
"github.com/cloudskiff/driftctl/pkg/alerter"
"github.com/cloudskiff/driftctl/pkg/output"
"github.com/cloudskiff/driftctl/pkg/remote/aws/client"
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
"github.com/cloudskiff/driftctl/pkg/remote/cache"
2021-06-11 15:10:06 +00:00
"github.com/cloudskiff/driftctl/pkg/remote/common"
"github.com/cloudskiff/driftctl/pkg/resource"
2021-03-26 08:44:55 +00:00
"github.com/cloudskiff/driftctl/pkg/resource/aws"
"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
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,
factory resource.ResourceFactory,
configDir string) error {
if version == "" {
version = "3.19.0"
}
provider, err := NewAWSTerraformProvider(version, progress, configDir)
if err != nil {
return err
}
err = provider.Init()
if err != nil {
return err
}
2021-05-25 15:08:36 +00:00
repositoryCache := cache.New(100)
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)
route53repository := repository.NewRoute53Repository(provider.session, repositoryCache)
lambdaRepository := repository.NewLambdaRepository(provider.session, repositoryCache)
rdsRepository := repository.NewRDSRepository(provider.session, repositoryCache)
sqsRepository := repository.NewSQSRepository(provider.session, repositoryCache)
snsRepository := repository.NewSNSRepository(provider.session, repositoryCache)
cloudfrontRepository := repository.NewCloudfrontRepository(provider.session, repositoryCache)
dynamoDBRepository := repository.NewDynamoDBRepository(provider.session, repositoryCache)
ecrRepository := repository.NewECRRepository(provider.session, repositoryCache)
kmsRepository := repository.NewKMSRepository(provider.session, repositoryCache)
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)
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-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-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 09:53:26 +00:00
2021-06-30 15:30:12 +00:00
remoteLibrary.AddEnumerator(NewVPCEnumerator(ec2repository, factory))
remoteLibrary.AddDetailsFetcher(aws.AwsVpcResourceType, common.NewGenericDetailsFetcher(aws.AwsVpcResourceType, provider, deserializer))
2021-06-30 16:00:38 +00:00
remoteLibrary.AddEnumerator(NewDefaultVPCEnumerator(ec2repository, factory))
remoteLibrary.AddDetailsFetcher(aws.AwsDefaultVpcResourceType, common.NewGenericDetailsFetcher(aws.AwsDefaultVpcResourceType, provider, deserializer))
2021-06-30 15:30:12 +00:00
2021-06-03 10:39:33 +00:00
supplierLibrary.AddSupplier(NewS3BucketAnalyticSupplier(provider, s3Repository, deserializer))
supplierLibrary.AddSupplier(NewS3BucketPolicySupplier(provider, s3Repository, deserializer))
2021-05-31 15:39:16 +00:00
supplierLibrary.AddSupplier(NewRoute53ZoneSupplier(provider, deserializer, route53repository))
supplierLibrary.AddSupplier(NewRoute53RecordSupplier(provider, deserializer, route53repository))
supplierLibrary.AddSupplier(NewLambdaFunctionSupplier(provider, deserializer, lambdaRepository))
supplierLibrary.AddSupplier(NewDBSubnetGroupSupplier(provider, deserializer, rdsRepository))
supplierLibrary.AddSupplier(NewDBInstanceSupplier(provider, deserializer, rdsRepository))
supplierLibrary.AddSupplier(NewVPCSecurityGroupSupplier(provider, deserializer, ec2repository))
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(NewIamPolicySupplier(provider, deserializer, iamRepository))
supplierLibrary.AddSupplier(NewIamRolePolicySupplier(provider, deserializer, iamRepository))
supplierLibrary.AddSupplier(NewIamRolePolicyAttachmentSupplier(provider, deserializer, iamRepository))
supplierLibrary.AddSupplier(NewVPCSecurityGroupRuleSupplier(provider, deserializer, ec2repository))
supplierLibrary.AddSupplier(NewSubnetSupplier(provider, deserializer, ec2repository))
supplierLibrary.AddSupplier(NewRouteTableSupplier(provider, deserializer, ec2repository))
supplierLibrary.AddSupplier(NewRouteSupplier(provider, deserializer, ec2repository))
supplierLibrary.AddSupplier(NewRouteTableAssociationSupplier(provider, deserializer, ec2repository))
supplierLibrary.AddSupplier(NewNatGatewaySupplier(provider, deserializer, ec2repository))
2021-05-31 15:39:16 +00:00
supplierLibrary.AddSupplier(NewSqsQueueSupplier(provider, deserializer, sqsRepository))
supplierLibrary.AddSupplier(NewSqsQueuePolicySupplier(provider, deserializer, sqsRepository))
supplierLibrary.AddSupplier(NewSNSTopicSupplier(provider, deserializer, snsRepository))
supplierLibrary.AddSupplier(NewSNSTopicPolicySupplier(provider, deserializer, snsRepository))
supplierLibrary.AddSupplier(NewSNSTopicSubscriptionSupplier(provider, alerter, deserializer, snsRepository))
supplierLibrary.AddSupplier(NewDynamoDBTableSupplier(provider, deserializer, dynamoDBRepository))
supplierLibrary.AddSupplier(NewRoute53HealthCheckSupplier(provider, deserializer, route53repository))
supplierLibrary.AddSupplier(NewCloudfrontDistributionSupplier(provider, deserializer, cloudfrontRepository))
supplierLibrary.AddSupplier(NewECRRepositorySupplier(provider, deserializer, ecrRepository))
supplierLibrary.AddSupplier(NewKMSAliasSupplier(provider, deserializer, kmsRepository))
supplierLibrary.AddSupplier(NewLambdaEventSourceMappingSupplier(provider, deserializer, lambdaRepository))
err = resourceSchemaRepository.Init(version, provider.Schema())
if err != nil {
return err
}
2021-03-26 08:44:55 +00:00
aws.InitResourcesMetadata(resourceSchemaRepository)
return nil
}