From e6557938e2a362f5aaeeee4f59596849581d628b Mon Sep 17 00:00:00 2001 From: Elie Date: Fri, 17 Sep 2021 17:16:06 +0200 Subject: [PATCH] Add deep mode flag on resource schema --- pkg/analyser/analyzer.go | 5 ++++ pkg/resource/aws/aws_ami.go | 1 + pkg/resource/aws/aws_cloudformation_stack.go | 1 + .../aws/aws_cloudfront_distribution.go | 1 + pkg/resource/aws/aws_db_instance.go | 1 + pkg/resource/aws/aws_db_subnet_group.go | 1 + pkg/resource/aws/aws_default_route_table.go | 1 + .../aws/aws_default_security_group.go | 1 + pkg/resource/aws/aws_default_subnet.go | 1 + pkg/resource/aws/aws_default_vpc.go | 6 +++++ pkg/resource/aws/aws_dynamodb_table.go | 2 ++ pkg/resource/aws/aws_ebs_snapshot.go | 1 + pkg/resource/aws/aws_ebs_volume.go | 1 + pkg/resource/aws/aws_ecr_repository.go | 1 + pkg/resource/aws/aws_eip.go | 1 + pkg/resource/aws/aws_eip_association.go | 6 +++++ pkg/resource/aws/aws_iam_access_key.go | 1 + pkg/resource/aws/aws_iam_policy.go | 1 + pkg/resource/aws/aws_iam_policy_attachment.go | 1 + pkg/resource/aws/aws_iam_role.go | 1 + pkg/resource/aws/aws_iam_role_policy.go | 1 + .../aws/aws_iam_role_policy_attachment.go | 1 + pkg/resource/aws/aws_iam_user.go | 1 + pkg/resource/aws/aws_iam_user_policy.go | 1 + .../aws/aws_iam_user_policy_attachment.go | 1 + pkg/resource/aws/aws_instance.go | 1 + pkg/resource/aws/aws_internet_gateway.go | 8 ++++++ pkg/resource/aws/aws_key_pair.go | 1 + pkg/resource/aws/aws_kms_alias.go | 1 + pkg/resource/aws/aws_kms_key.go | 1 + .../aws/aws_lambda_event_source_mapping.go | 1 + pkg/resource/aws/aws_lambda_function.go | 1 + pkg/resource/aws/aws_nat_gateway.go | 6 +++++ pkg/resource/aws/aws_rds_cluster.go | 1 + pkg/resource/aws/aws_route.go | 1 + pkg/resource/aws/aws_route53_health_check.go | 1 + pkg/resource/aws/aws_route53_record.go | 1 + pkg/resource/aws/aws_route53_zone.go | 1 + pkg/resource/aws/aws_route_table.go | 6 +++++ .../aws/aws_route_table_association.go | 1 + pkg/resource/aws/aws_s3_bucket.go | 1 + pkg/resource/aws/aws_s3_bucket_inventory.go | 1 + pkg/resource/aws/aws_s3_bucket_metric.go | 1 + .../aws/aws_s3_bucket_notification.go | 1 + pkg/resource/aws/aws_s3_bucket_policy.go | 1 + pkg/resource/aws/aws_security_group.go | 1 + pkg/resource/aws/aws_security_group_rule.go | 1 + pkg/resource/aws/aws_sns_topic.go | 1 + pkg/resource/aws/aws_sns_topic_policy.go | 1 + .../aws/aws_sns_topic_subscription.go | 1 + pkg/resource/aws/aws_sqs_queue.go | 8 ++++++ pkg/resource/aws/aws_sqs_queue_policy.go | 1 + pkg/resource/aws/aws_subnet.go | 1 + pkg/resource/aws/aws_vpc.go | 6 +++++ pkg/resource/aws/metadatas.go | 7 +++++ .../github/github_branch_protection.go | 1 + pkg/resource/github/github_membership.go | 1 + pkg/resource/github/github_repository.go | 1 + pkg/resource/github/github_team.go | 1 + pkg/resource/github/github_team_membership.go | 1 + .../google/google_compute_firewall.go | 1 + pkg/resource/google/google_storage_bucket.go | 1 + pkg/resource/schemas.go | 27 +++++++++++++++++++ 63 files changed, 139 insertions(+) diff --git a/pkg/analyser/analyzer.go b/pkg/analyser/analyzer.go index cb99fc70..7134550f 100644 --- a/pkg/analyser/analyzer.go +++ b/pkg/analyser/analyzer.go @@ -85,6 +85,11 @@ func (a Analyzer) Analyze(remoteResources, resourcesFromState []*resource.Resour continue } + // Stop if the resource is not compatible with deep mode + if stateRes.Schema() != nil && !stateRes.Schema().Flags.HasFlag(resource.FlagDeepMode) { + continue + } + var delta diff.Changelog delta, _ = diff.Diff(stateRes.Attributes(), remoteRes.Attributes()) diff --git a/pkg/resource/aws/aws_ami.go b/pkg/resource/aws/aws_ami.go index 97ddf500..bb06ff67 100644 --- a/pkg/resource/aws/aws_ami.go +++ b/pkg/resource/aws/aws_ami.go @@ -11,4 +11,5 @@ func initAwsAmiMetaData(resourceSchemaRepository resource.SchemaRepositoryInterf val := res.Attrs val.SafeDelete([]string{"timeouts"}) }) + resourceSchemaRepository.SetFlags(AwsAmiResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_cloudformation_stack.go b/pkg/resource/aws/aws_cloudformation_stack.go index de9baea2..e82741b0 100644 --- a/pkg/resource/aws/aws_cloudformation_stack.go +++ b/pkg/resource/aws/aws_cloudformation_stack.go @@ -22,4 +22,5 @@ func initAwsCloudformationStackMetaData(resourceSchemaRepository resource.Schema val := res.Attrs val.SafeDelete([]string{"timeouts"}) }) + resourceSchemaRepository.SetFlags(AwsCloudformationStackResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_cloudfront_distribution.go b/pkg/resource/aws/aws_cloudfront_distribution.go index 3a38870b..74eda03a 100644 --- a/pkg/resource/aws/aws_cloudfront_distribution.go +++ b/pkg/resource/aws/aws_cloudfront_distribution.go @@ -15,4 +15,5 @@ func initAwsCloudfrontDistributionMetaData(resourceSchemaRepository resource.Sch val.SafeDelete([]string{"status"}) val.SafeDelete([]string{"wait_for_deployment"}) }) + resourceSchemaRepository.SetFlags(AwsCloudfrontDistributionResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_db_instance.go b/pkg/resource/aws/aws_db_instance.go index 9fcaa4e0..c16eaa41 100644 --- a/pkg/resource/aws/aws_db_instance.go +++ b/pkg/resource/aws/aws_db_instance.go @@ -20,4 +20,5 @@ func initAwsDbInstanceMetaData(resourceSchemaRepository resource.SchemaRepositor val.SafeDelete([]string{"apply_immediately"}) val.DeleteIfDefault("CharacterSetName") }) + resourceSchemaRepository.SetFlags(AwsDbInstanceResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_db_subnet_group.go b/pkg/resource/aws/aws_db_subnet_group.go index 1f3322a4..2a6ad6c6 100644 --- a/pkg/resource/aws/aws_db_subnet_group.go +++ b/pkg/resource/aws/aws_db_subnet_group.go @@ -11,4 +11,5 @@ func initAwsDbSubnetGroupMetaData(resourceSchemaRepository resource.SchemaReposi val := res.Attrs val.SafeDelete([]string{"name_prefix"}) }) + resourceSchemaRepository.SetFlags(AwsDbSubnetGroupResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_default_route_table.go b/pkg/resource/aws/aws_default_route_table.go index 6a1f51ef..3f24cbc4 100644 --- a/pkg/resource/aws/aws_default_route_table.go +++ b/pkg/resource/aws/aws_default_route_table.go @@ -10,4 +10,5 @@ func initAwsDefaultRouteTableMetadata(resourceSchemaRepository resource.SchemaRe "vpc_id": *res.Attributes().GetString("vpc_id"), } }) + resourceSchemaRepository.SetFlags(AwsDefaultRouteTableResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_default_security_group.go b/pkg/resource/aws/aws_default_security_group.go index b1e54520..1a822a03 100644 --- a/pkg/resource/aws/aws_default_security_group.go +++ b/pkg/resource/aws/aws_default_security_group.go @@ -13,4 +13,5 @@ func initAwsDefaultSecurityGroupMetaData(resourceSchemaRepository resource.Schem val.SafeDelete([]string{"ingress"}) val.SafeDelete([]string{"egress"}) }) + resourceSchemaRepository.SetFlags(AwsDefaultSecurityGroupResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_default_subnet.go b/pkg/resource/aws/aws_default_subnet.go index b8df89b7..f1966a11 100644 --- a/pkg/resource/aws/aws_default_subnet.go +++ b/pkg/resource/aws/aws_default_subnet.go @@ -11,4 +11,5 @@ func initAwsDefaultSubnetMetaData(resourceSchemaRepository resource.SchemaReposi val := res.Attrs val.SafeDelete([]string{"timeouts"}) }) + resourceSchemaRepository.SetFlags(AwsDefaultSubnetResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_default_vpc.go b/pkg/resource/aws/aws_default_vpc.go index 46d13514..3fc5a30b 100644 --- a/pkg/resource/aws/aws_default_vpc.go +++ b/pkg/resource/aws/aws_default_vpc.go @@ -1,3 +1,9 @@ package aws +import "github.com/cloudskiff/driftctl/pkg/resource" + const AwsDefaultVpcResourceType = "aws_default_vpc" + +func initAwsDefaultVpcMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { + resourceSchemaRepository.SetFlags(AwsDefaultVpcResourceType, resource.FlagDeepMode) +} diff --git a/pkg/resource/aws/aws_dynamodb_table.go b/pkg/resource/aws/aws_dynamodb_table.go index 9b83ce5e..96b6b13b 100644 --- a/pkg/resource/aws/aws_dynamodb_table.go +++ b/pkg/resource/aws/aws_dynamodb_table.go @@ -16,4 +16,6 @@ func initAwsDynamodbTableMetaData(resourceSchemaRepository resource.SchemaReposi val := res.Attrs val.SafeDelete([]string{"timeouts"}) }) + resourceSchemaRepository.SetFlags(AwsDynamodbTableResourceType, resource.FlagDeepMode) + } diff --git a/pkg/resource/aws/aws_ebs_snapshot.go b/pkg/resource/aws/aws_ebs_snapshot.go index 837afe9f..3c041aa1 100644 --- a/pkg/resource/aws/aws_ebs_snapshot.go +++ b/pkg/resource/aws/aws_ebs_snapshot.go @@ -11,4 +11,5 @@ func initAwsEbsSnapshotMetaData(resourceSchemaRepository resource.SchemaReposito val := res.Attrs val.SafeDelete([]string{"timeouts"}) }) + resourceSchemaRepository.SetFlags(AwsEbsSnapshotResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_ebs_volume.go b/pkg/resource/aws/aws_ebs_volume.go index f326fdf1..2e8864db 100644 --- a/pkg/resource/aws/aws_ebs_volume.go +++ b/pkg/resource/aws/aws_ebs_volume.go @@ -14,4 +14,5 @@ func initAwsEbsVolumeMetaData(resourceSchemaRepository resource.SchemaRepository val.SafeDelete([]string{"snapshot_id"}) val.DeleteIfDefault("throughput") }) + resourceSchemaRepository.SetFlags(AwsEbsVolumeResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_ecr_repository.go b/pkg/resource/aws/aws_ecr_repository.go index 36a9de56..1e744a24 100644 --- a/pkg/resource/aws/aws_ecr_repository.go +++ b/pkg/resource/aws/aws_ecr_repository.go @@ -9,4 +9,5 @@ func initAwsEcrRepositoryMetaData(resourceSchemaRepository resource.SchemaReposi val := res.Attrs val.SafeDelete([]string{"timeouts"}) }) + resourceSchemaRepository.SetFlags(AwsEcrRepositoryResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_eip.go b/pkg/resource/aws/aws_eip.go index fda2e7b7..c8ac3670 100644 --- a/pkg/resource/aws/aws_eip.go +++ b/pkg/resource/aws/aws_eip.go @@ -11,4 +11,5 @@ func initAwsEipMetaData(resourceSchemaRepository resource.SchemaRepositoryInterf val := res.Attrs val.SafeDelete([]string{"timeouts"}) }) + resourceSchemaRepository.SetFlags(AwsEipResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_eip_association.go b/pkg/resource/aws/aws_eip_association.go index 44bff290..5c38e688 100644 --- a/pkg/resource/aws/aws_eip_association.go +++ b/pkg/resource/aws/aws_eip_association.go @@ -1,3 +1,9 @@ package aws +import "github.com/cloudskiff/driftctl/pkg/resource" + const AwsEipAssociationResourceType = "aws_eip_association" + +func initAwsEipAssociationMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { + resourceSchemaRepository.SetFlags(AwsEipAssociationResourceType, resource.FlagDeepMode) +} diff --git a/pkg/resource/aws/aws_iam_access_key.go b/pkg/resource/aws/aws_iam_access_key.go index 0f808abe..8c9bfbea 100644 --- a/pkg/resource/aws/aws_iam_access_key.go +++ b/pkg/resource/aws/aws_iam_access_key.go @@ -34,4 +34,5 @@ func initAwsIAMAccessKeyMetaData(resourceSchemaRepository resource.SchemaReposit } return attrs }) + resourceSchemaRepository.SetFlags(AwsIamAccessKeyResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_iam_policy.go b/pkg/resource/aws/aws_iam_policy.go index 974f99bf..a28fdbb0 100644 --- a/pkg/resource/aws/aws_iam_policy.go +++ b/pkg/resource/aws/aws_iam_policy.go @@ -22,4 +22,5 @@ func initAwsIAMPolicyMetaData(resourceSchemaRepository resource.SchemaRepository val.SafeDelete([]string{"name_prefix"}) }) + resourceSchemaRepository.SetFlags(AwsIamPolicyResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_iam_policy_attachment.go b/pkg/resource/aws/aws_iam_policy_attachment.go index b17346d3..afe26168 100644 --- a/pkg/resource/aws/aws_iam_policy_attachment.go +++ b/pkg/resource/aws/aws_iam_policy_attachment.go @@ -11,4 +11,5 @@ func initAwsIAMPolicyAttachmentMetaData(resourceSchemaRepository resource.Schema val := res.Attrs val.SafeDelete([]string{"name"}) }) + resourceSchemaRepository.SetFlags(AwsIamPolicyAttachmentResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_iam_role.go b/pkg/resource/aws/aws_iam_role.go index 4da4777d..857ff3a7 100644 --- a/pkg/resource/aws/aws_iam_role.go +++ b/pkg/resource/aws/aws_iam_role.go @@ -16,4 +16,5 @@ func initAwsIAMRoleMetaData(resourceSchemaRepository resource.SchemaRepositoryIn val := res.Attrs val.SafeDelete([]string{"force_detach_policies"}) }) + resourceSchemaRepository.SetFlags(AwsIamRoleResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_iam_role_policy.go b/pkg/resource/aws/aws_iam_role_policy.go index 80d46ca6..26a2aa64 100644 --- a/pkg/resource/aws/aws_iam_role_policy.go +++ b/pkg/resource/aws/aws_iam_role_policy.go @@ -12,4 +12,5 @@ func initAwsIAMRolePolicyMetaData(resourceSchemaRepository resource.SchemaReposi attributeSchema.JsonString = true }, }) + resourceSchemaRepository.SetFlags(AwsIamRolePolicyResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_iam_role_policy_attachment.go b/pkg/resource/aws/aws_iam_role_policy_attachment.go index 74a0f3bc..111664dc 100644 --- a/pkg/resource/aws/aws_iam_role_policy_attachment.go +++ b/pkg/resource/aws/aws_iam_role_policy_attachment.go @@ -11,4 +11,5 @@ func initAwsIamRolePolicyAttachmentMetaData(resourceSchemaRepository resource.Sc "policy_arn": *res.Attributes().GetString("policy_arn"), } }) + resourceSchemaRepository.SetFlags(AwsIamRolePolicyAttachmentResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_iam_user.go b/pkg/resource/aws/aws_iam_user.go index b4df4340..bcebcbca 100644 --- a/pkg/resource/aws/aws_iam_user.go +++ b/pkg/resource/aws/aws_iam_user.go @@ -15,4 +15,5 @@ func initAwsIAMUserMetaData(resourceSchemaRepository resource.SchemaRepositoryIn } val.SafeDelete([]string{"force_destroy"}) }) + resourceSchemaRepository.SetFlags(AwsIamUserResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_iam_user_policy.go b/pkg/resource/aws/aws_iam_user_policy.go index be876295..3d8ad1c8 100644 --- a/pkg/resource/aws/aws_iam_user_policy.go +++ b/pkg/resource/aws/aws_iam_user_policy.go @@ -12,4 +12,5 @@ func initAwsIAMUserPolicyMetaData(resourceSchemaRepository resource.SchemaReposi attributeSchema.JsonString = true }, }) + resourceSchemaRepository.SetFlags(AwsIamUserPolicyResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_iam_user_policy_attachment.go b/pkg/resource/aws/aws_iam_user_policy_attachment.go index 27571b32..71e14923 100644 --- a/pkg/resource/aws/aws_iam_user_policy_attachment.go +++ b/pkg/resource/aws/aws_iam_user_policy_attachment.go @@ -11,4 +11,5 @@ func initAwsIamUserPolicyAttachmentMetaData(resourceSchemaRepository resource.Sc "policy_arn": *res.Attributes().GetString("policy_arn"), } }) + resourceSchemaRepository.SetFlags(AwsIamUserPolicyAttachmentResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_instance.go b/pkg/resource/aws/aws_instance.go index 3842a92a..e8d5b3d1 100644 --- a/pkg/resource/aws/aws_instance.go +++ b/pkg/resource/aws/aws_instance.go @@ -26,4 +26,5 @@ func initAwsInstanceMetaData(resourceSchemaRepository resource.SchemaRepositoryI } return attrs }) + resourceSchemaRepository.SetFlags(AwsInstanceResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_internet_gateway.go b/pkg/resource/aws/aws_internet_gateway.go index 8b33dcf7..207e29fd 100644 --- a/pkg/resource/aws/aws_internet_gateway.go +++ b/pkg/resource/aws/aws_internet_gateway.go @@ -1,3 +1,11 @@ package aws +import ( + "github.com/cloudskiff/driftctl/pkg/resource" +) + const AwsInternetGatewayResourceType = "aws_internet_gateway" + +func initAwsInternetGatewayMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { + resourceSchemaRepository.SetFlags(AwsInternetGatewayResourceType, resource.FlagDeepMode) +} diff --git a/pkg/resource/aws/aws_key_pair.go b/pkg/resource/aws/aws_key_pair.go index 9d8c8592..82f7661b 100644 --- a/pkg/resource/aws/aws_key_pair.go +++ b/pkg/resource/aws/aws_key_pair.go @@ -12,4 +12,5 @@ func initAwsKeyPairMetaData(resourceSchemaRepository resource.SchemaRepositoryIn val.SafeDelete([]string{"key_name_prefix"}) val.SafeDelete([]string{"public_key"}) }) + resourceSchemaRepository.SetFlags(AwsKeyPairResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_kms_alias.go b/pkg/resource/aws/aws_kms_alias.go index 6e38ca56..07df1a53 100644 --- a/pkg/resource/aws/aws_kms_alias.go +++ b/pkg/resource/aws/aws_kms_alias.go @@ -12,4 +12,5 @@ func initAwsKmsAliasMetaData(resourceSchemaRepository resource.SchemaRepositoryI val.SafeDelete([]string{"name"}) val.SafeDelete([]string{"name_prefix"}) }) + resourceSchemaRepository.SetFlags(AwsKmsAliasResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_kms_key.go b/pkg/resource/aws/aws_kms_key.go index 91d0ee6c..4547ec85 100644 --- a/pkg/resource/aws/aws_kms_key.go +++ b/pkg/resource/aws/aws_kms_key.go @@ -22,4 +22,5 @@ func initAwsKmsKeyMetaData(resourceSchemaRepository resource.SchemaRepositoryInt } _ = val.SafeSet([]string{"policy"}, jsonString) }) + resourceSchemaRepository.SetFlags(AwsKmsKeyResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_lambda_event_source_mapping.go b/pkg/resource/aws/aws_lambda_event_source_mapping.go index d512f85d..2dee6e27 100644 --- a/pkg/resource/aws/aws_lambda_event_source_mapping.go +++ b/pkg/resource/aws/aws_lambda_event_source_mapping.go @@ -27,4 +27,5 @@ func initAwsLambdaEventSourceMappingMetaData(resourceSchemaRepository resource.S } return attrs }) + resourceSchemaRepository.SetFlags(AwsLambdaEventSourceMappingResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_lambda_function.go b/pkg/resource/aws/aws_lambda_function.go index 0023611c..ca44d652 100644 --- a/pkg/resource/aws/aws_lambda_function.go +++ b/pkg/resource/aws/aws_lambda_function.go @@ -27,4 +27,5 @@ func initAwsLambdaFunctionMetaData(resourceSchemaRepository resource.SchemaRepos val.DeleteIfDefault("signing_profile_version_arn") val.SafeDelete([]string{"source_code_size"}) }) + resourceSchemaRepository.SetFlags(AwsLambdaFunctionResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_nat_gateway.go b/pkg/resource/aws/aws_nat_gateway.go index 9dd9290b..a22d28e5 100644 --- a/pkg/resource/aws/aws_nat_gateway.go +++ b/pkg/resource/aws/aws_nat_gateway.go @@ -1,3 +1,9 @@ package aws +import "github.com/cloudskiff/driftctl/pkg/resource" + const AwsNatGatewayResourceType = "aws_nat_gateway" + +func initNatGatewayMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { + resourceSchemaRepository.SetFlags(AwsNatGatewayResourceType, resource.FlagDeepMode) +} diff --git a/pkg/resource/aws/aws_rds_cluster.go b/pkg/resource/aws/aws_rds_cluster.go index 16115289..e89dad15 100644 --- a/pkg/resource/aws/aws_rds_cluster.go +++ b/pkg/resource/aws/aws_rds_cluster.go @@ -19,4 +19,5 @@ func initAwsRDSClusterMetaData(resourceSchemaRepository resource.SchemaRepositor val.SafeDelete([]string{"cluster_members"}) val.SafeDelete([]string{"skip_final_snapshot"}) }) + resourceSchemaRepository.SetFlags(AwsRDSClusterResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_route.go b/pkg/resource/aws/aws_route.go index 027da81e..7ba1e612 100644 --- a/pkg/resource/aws/aws_route.go +++ b/pkg/resource/aws/aws_route.go @@ -57,6 +57,7 @@ func initAwsRouteMetaData(resourceSchemaRepository resource.SchemaRepositoryInte } return attrs }) + resourceSchemaRepository.SetFlags(AwsRouteResourceType, resource.FlagDeepMode) } func CalculateRouteID(tableId, CidrBlock, Ipv6CidrBlock, PrefixListId *string) string { diff --git a/pkg/resource/aws/aws_route53_health_check.go b/pkg/resource/aws/aws_route53_health_check.go index 483aeb55..a4530a8f 100644 --- a/pkg/resource/aws/aws_route53_health_check.go +++ b/pkg/resource/aws/aws_route53_health_check.go @@ -39,4 +39,5 @@ func initAwsRoute53HealthCheckMetaData(resourceSchemaRepository resource.SchemaR } return attrs }) + resourceSchemaRepository.SetFlags(AwsRoute53HealthCheckResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_route53_record.go b/pkg/resource/aws/aws_route53_record.go index e75dc145..73378e17 100644 --- a/pkg/resource/aws/aws_route53_record.go +++ b/pkg/resource/aws/aws_route53_record.go @@ -29,4 +29,5 @@ func initAwsRoute53RecordMetaData(resourceSchemaRepository resource.SchemaReposi } return attrs }) + resourceSchemaRepository.SetFlags(AwsRoute53RecordResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_route53_zone.go b/pkg/resource/aws/aws_route53_zone.go index e4ec6c96..bb71134c 100644 --- a/pkg/resource/aws/aws_route53_zone.go +++ b/pkg/resource/aws/aws_route53_zone.go @@ -19,4 +19,5 @@ func initAwsRoute53ZoneMetaData(resourceSchemaRepository resource.SchemaReposito } return attrs }) + resourceSchemaRepository.SetFlags(AwsRoute53ZoneResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_route_table.go b/pkg/resource/aws/aws_route_table.go index f389e53e..effb852a 100644 --- a/pkg/resource/aws/aws_route_table.go +++ b/pkg/resource/aws/aws_route_table.go @@ -1,3 +1,9 @@ package aws +import "github.com/cloudskiff/driftctl/pkg/resource" + const AwsRouteTableResourceType = "aws_route_table" + +func initAwsRouteTableMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { + resourceSchemaRepository.SetFlags(AwsRouteTableResourceType, resource.FlagDeepMode) +} diff --git a/pkg/resource/aws/aws_route_table_association.go b/pkg/resource/aws/aws_route_table_association.go index 41440f73..1fc5696a 100644 --- a/pkg/resource/aws/aws_route_table_association.go +++ b/pkg/resource/aws/aws_route_table_association.go @@ -26,4 +26,5 @@ func initAwsRouteTableAssociationMetaData(resourceSchemaRepository resource.Sche } return attrs }) + resourceSchemaRepository.SetFlags(AwsRouteTableAssociationResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_s3_bucket.go b/pkg/resource/aws/aws_s3_bucket.go index 0179c05d..df9e41b9 100644 --- a/pkg/resource/aws/aws_s3_bucket.go +++ b/pkg/resource/aws/aws_s3_bucket.go @@ -22,4 +22,5 @@ func initAwsS3BucketMetaData(resourceSchemaRepository resource.SchemaRepositoryI val.SafeDelete([]string{"force_destroy"}) val.SafeDelete([]string{"bucket_prefix"}) }) + resourceSchemaRepository.SetFlags(AwsS3BucketResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_s3_bucket_inventory.go b/pkg/resource/aws/aws_s3_bucket_inventory.go index d973b1f3..5096279c 100644 --- a/pkg/resource/aws/aws_s3_bucket_inventory.go +++ b/pkg/resource/aws/aws_s3_bucket_inventory.go @@ -10,4 +10,5 @@ func initAwsS3BucketInventoryMetadata(resourceSchemaRepository resource.SchemaRe "alias": *res.Attributes().GetString("region"), } }) + resourceSchemaRepository.SetFlags(AwsS3BucketInventoryResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_s3_bucket_metric.go b/pkg/resource/aws/aws_s3_bucket_metric.go index ff8cf0d4..87d9ee44 100644 --- a/pkg/resource/aws/aws_s3_bucket_metric.go +++ b/pkg/resource/aws/aws_s3_bucket_metric.go @@ -10,4 +10,5 @@ func initAwsS3BucketMetricMetadata(resourceSchemaRepository resource.SchemaRepos "alias": *res.Attributes().GetString("region"), } }) + resourceSchemaRepository.SetFlags(AwsS3BucketMetricResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_s3_bucket_notification.go b/pkg/resource/aws/aws_s3_bucket_notification.go index 9c61fa4b..20401204 100644 --- a/pkg/resource/aws/aws_s3_bucket_notification.go +++ b/pkg/resource/aws/aws_s3_bucket_notification.go @@ -10,4 +10,5 @@ func initAwsS3BucketNotificationMetadata(resourceSchemaRepository resource.Schem "alias": *res.Attributes().GetString("region"), } }) + resourceSchemaRepository.SetFlags(AwsS3BucketNotificationResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_s3_bucket_policy.go b/pkg/resource/aws/aws_s3_bucket_policy.go index 332ec91b..119371ae 100644 --- a/pkg/resource/aws/aws_s3_bucket_policy.go +++ b/pkg/resource/aws/aws_s3_bucket_policy.go @@ -26,4 +26,5 @@ func initAwsS3BucketPolicyMetaData(resourceSchemaRepository resource.SchemaRepos } _ = val.SafeSet([]string{"policy"}, jsonString) }) + resourceSchemaRepository.SetFlags(AwsS3BucketPolicyResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_security_group.go b/pkg/resource/aws/aws_security_group.go index d4be08b9..c8632c97 100644 --- a/pkg/resource/aws/aws_security_group.go +++ b/pkg/resource/aws/aws_security_group.go @@ -14,4 +14,5 @@ func initAwsSecurityGroupMetaData(resourceSchemaRepository resource.SchemaReposi val.SafeDelete([]string{"ingress"}) val.SafeDelete([]string{"egress"}) }) + resourceSchemaRepository.SetFlags(AwsSecurityGroupResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_security_group_rule.go b/pkg/resource/aws/aws_security_group_rule.go index de31be7e..9baa69d3 100644 --- a/pkg/resource/aws/aws_security_group_rule.go +++ b/pkg/resource/aws/aws_security_group_rule.go @@ -161,4 +161,5 @@ func initAwsSecurityGroupRuleMetaData(resourceSchemaRepository resource.SchemaRe } return attrs }) + resourceSchemaRepository.SetFlags(AwsSecurityGroupRuleResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_sns_topic.go b/pkg/resource/aws/aws_sns_topic.go index 1cd885c3..cb671ff6 100644 --- a/pkg/resource/aws/aws_sns_topic.go +++ b/pkg/resource/aws/aws_sns_topic.go @@ -40,4 +40,5 @@ func initSnsTopicMetaData(resourceSchemaRepository resource.SchemaRepositoryInte } return attrs }) + resourceSchemaRepository.SetFlags(AwsSnsTopicResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_sns_topic_policy.go b/pkg/resource/aws/aws_sns_topic_policy.go index f1de6d75..edb8b081 100644 --- a/pkg/resource/aws/aws_sns_topic_policy.go +++ b/pkg/resource/aws/aws_sns_topic_policy.go @@ -29,4 +29,5 @@ func initSnsTopicPolicyMetaData(resourceSchemaRepository resource.SchemaReposito } _ = val.SafeSet([]string{"policy"}, jsonString) }) + resourceSchemaRepository.SetFlags(AwsSnsTopicPolicyResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_sns_topic_subscription.go b/pkg/resource/aws/aws_sns_topic_subscription.go index de3f961c..d643185f 100644 --- a/pkg/resource/aws/aws_sns_topic_subscription.go +++ b/pkg/resource/aws/aws_sns_topic_subscription.go @@ -42,4 +42,5 @@ func initSnsTopicSubscriptionMetaData(resourceSchemaRepository resource.SchemaRe val.SafeDelete([]string{"confirmation_timeout_in_minutes"}) } }) + resourceSchemaRepository.SetFlags(AwsSnsTopicSubscriptionResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_sqs_queue.go b/pkg/resource/aws/aws_sqs_queue.go index 5f72d488..d7023876 100644 --- a/pkg/resource/aws/aws_sqs_queue.go +++ b/pkg/resource/aws/aws_sqs_queue.go @@ -1,3 +1,11 @@ package aws +import ( + "github.com/cloudskiff/driftctl/pkg/resource" +) + const AwsSqsQueueResourceType = "aws_sqs_queue" + +func initSqsQueueMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { + resourceSchemaRepository.SetFlags(AwsSqsQueueResourceType, resource.FlagDeepMode) +} diff --git a/pkg/resource/aws/aws_sqs_queue_policy.go b/pkg/resource/aws/aws_sqs_queue_policy.go index ef167f85..21886d93 100644 --- a/pkg/resource/aws/aws_sqs_queue_policy.go +++ b/pkg/resource/aws/aws_sqs_queue_policy.go @@ -21,4 +21,5 @@ func initAwsSQSQueuePolicyMetaData(resourceSchemaRepository resource.SchemaRepos } _ = val.SafeSet([]string{"policy"}, jsonString) }) + resourceSchemaRepository.SetFlags(AwsSqsQueuePolicyResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_subnet.go b/pkg/resource/aws/aws_subnet.go index fb7950dd..fb1f4964 100644 --- a/pkg/resource/aws/aws_subnet.go +++ b/pkg/resource/aws/aws_subnet.go @@ -11,4 +11,5 @@ func initAwsSubnetMetaData(resourceSchemaRepository resource.SchemaRepositoryInt val := res.Attrs val.SafeDelete([]string{"timeouts"}) }) + resourceSchemaRepository.SetFlags(AwsSubnetResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_vpc.go b/pkg/resource/aws/aws_vpc.go index cd8ad718..181e351d 100644 --- a/pkg/resource/aws/aws_vpc.go +++ b/pkg/resource/aws/aws_vpc.go @@ -1,3 +1,9 @@ package aws +import "github.com/cloudskiff/driftctl/pkg/resource" + const AwsVpcResourceType = "aws_vpc" + +func initAwsVpcMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { + resourceSchemaRepository.SetFlags(AwsVpcResourceType, resource.FlagDeepMode) +} diff --git a/pkg/resource/aws/metadatas.go b/pkg/resource/aws/metadatas.go index c9ff9fab..bb8cb48e 100644 --- a/pkg/resource/aws/metadatas.go +++ b/pkg/resource/aws/metadatas.go @@ -9,12 +9,15 @@ func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInt initAwsDbSubnetGroupMetaData(resourceSchemaRepository) initAwsDefaultSecurityGroupMetaData(resourceSchemaRepository) initAwsDefaultSubnetMetaData(resourceSchemaRepository) + initAwsDefaultVpcMetaData(resourceSchemaRepository) initAwsDefaultRouteTableMetadata(resourceSchemaRepository) initAwsDynamodbTableMetaData(resourceSchemaRepository) initAwsEbsSnapshotMetaData(resourceSchemaRepository) initAwsInstanceMetaData(resourceSchemaRepository) + initAwsInternetGatewayMetaData(resourceSchemaRepository) initAwsEbsVolumeMetaData(resourceSchemaRepository) initAwsEipMetaData(resourceSchemaRepository) + initAwsEipAssociationMetaData(resourceSchemaRepository) initAwsS3BucketMetaData(resourceSchemaRepository) initAwsS3BucketPolicyMetaData(resourceSchemaRepository) initAwsS3BucketInventoryMetadata(resourceSchemaRepository) @@ -27,9 +30,11 @@ func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInt initAwsRoute53RecordMetaData(resourceSchemaRepository) initAwsRoute53ZoneMetaData(resourceSchemaRepository) initAwsRoute53HealthCheckMetaData(resourceSchemaRepository) + initAwsRouteTableMetaData(resourceSchemaRepository) initSnsTopicSubscriptionMetaData(resourceSchemaRepository) initSnsTopicPolicyMetaData(resourceSchemaRepository) initSnsTopicMetaData(resourceSchemaRepository) + initSqsQueueMetaData(resourceSchemaRepository) initAwsIAMAccessKeyMetaData(resourceSchemaRepository) initAwsIAMPolicyMetaData(resourceSchemaRepository) initAwsIAMPolicyAttachmentMetaData(resourceSchemaRepository) @@ -44,10 +49,12 @@ func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInt initAwsKmsAliasMetaData(resourceSchemaRepository) initAwsLambdaFunctionMetaData(resourceSchemaRepository) initAwsLambdaEventSourceMappingMetaData(resourceSchemaRepository) + initNatGatewayMetaData(resourceSchemaRepository) initAwsSubnetMetaData(resourceSchemaRepository) initAwsSQSQueuePolicyMetaData(resourceSchemaRepository) initAwsSecurityGroupRuleMetaData(resourceSchemaRepository) initAwsSecurityGroupMetaData(resourceSchemaRepository) initAwsRDSClusterMetaData(resourceSchemaRepository) initAwsCloudformationStackMetaData(resourceSchemaRepository) + initAwsVpcMetaData(resourceSchemaRepository) } diff --git a/pkg/resource/github/github_branch_protection.go b/pkg/resource/github/github_branch_protection.go index 2f0e0cf6..e4a4ee15 100644 --- a/pkg/resource/github/github_branch_protection.go +++ b/pkg/resource/github/github_branch_protection.go @@ -39,4 +39,5 @@ func initGithubBranchProtectionMetaData(resourceSchemaRepository resource.Schema attrs["Id"] = res.ResourceId() return attrs }) + resourceSchemaRepository.SetFlags(GithubBranchProtectionResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/github/github_membership.go b/pkg/resource/github/github_membership.go index 2453a7ca..7c102901 100644 --- a/pkg/resource/github/github_membership.go +++ b/pkg/resource/github/github_membership.go @@ -10,4 +10,5 @@ func initGithubMembershipMetaData(resourceSchemaRepository resource.SchemaReposi val := res.Attrs val.SafeDelete([]string{"etag"}) }) + resourceSchemaRepository.SetFlags(GithubMembershipResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/github/github_repository.go b/pkg/resource/github/github_repository.go index 921b02e3..0f3a50d0 100644 --- a/pkg/resource/github/github_repository.go +++ b/pkg/resource/github/github_repository.go @@ -10,4 +10,5 @@ func initGithubRepositoryMetaData(resourceSchemaRepository resource.SchemaReposi val.SafeDelete([]string{"auto_init"}) val.SafeDelete([]string{"etag"}) }) + resourceSchemaRepository.SetFlags(GithubRepositoryResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/github/github_team.go b/pkg/resource/github/github_team.go index 32169d26..a1aaf6e8 100644 --- a/pkg/resource/github/github_team.go +++ b/pkg/resource/github/github_team.go @@ -22,4 +22,5 @@ func initGithubTeamMetaData(resourceSchemaRepository resource.SchemaRepositoryIn } return attrs }) + resourceSchemaRepository.SetFlags(GithubTeamResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/github/github_team_membership.go b/pkg/resource/github/github_team_membership.go index aa4804f5..952dee1a 100644 --- a/pkg/resource/github/github_team_membership.go +++ b/pkg/resource/github/github_team_membership.go @@ -10,4 +10,5 @@ func initGithubTeamMembershipMetaData(resourceSchemaRepository resource.SchemaRe val := res.Attrs val.SafeDelete([]string{"etag"}) }) + resourceSchemaRepository.SetFlags(GithubTeamMembershipResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/google/google_compute_firewall.go b/pkg/resource/google/google_compute_firewall.go index 7f7171f0..e4adb6e9 100644 --- a/pkg/resource/google/google_compute_firewall.go +++ b/pkg/resource/google/google_compute_firewall.go @@ -14,4 +14,5 @@ func initGoogleComputeFirewallMetadata(resourceSchemaRepository resource.SchemaR resourceSchemaRepository.SetNormalizeFunc(GoogleComputeFirewallResourceType, func(res *resource.Resource) { res.Attrs.SafeDelete([]string{"timeouts"}) }) + resourceSchemaRepository.SetFlags(GoogleComputeFirewallResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/google/google_storage_bucket.go b/pkg/resource/google/google_storage_bucket.go index 30527892..60ca5752 100644 --- a/pkg/resource/google/google_storage_bucket.go +++ b/pkg/resource/google/google_storage_bucket.go @@ -13,4 +13,5 @@ func initGoogleStorageBucketMetadata(resourceSchemaRepository resource.SchemaRep "name": res.ResourceId(), } }) + resourceSchemaRepository.SetFlags(GoogleStorageBucketResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/schemas.go b/pkg/resource/schemas.go index 7aaf62d7..92bc85d7 100644 --- a/pkg/resource/schemas.go +++ b/pkg/resource/schemas.go @@ -14,8 +14,23 @@ type AttributeSchema struct { JsonString bool } +type Flags uint32 + +const ( + FlagDeepMode Flags = 1 << iota +) + +func (f Flags) HasFlag(flag Flags) bool { + return f&flag != 0 +} + +func (f *Flags) AddFlag(flag Flags) { + *f |= flag +} + type Schema struct { ProviderVersion *version.Version + Flags Flags SchemaVersion int64 Attributes map[string]AttributeSchema NormalizeFunc func(res *Resource) @@ -41,6 +56,7 @@ func (s *Schema) IsJsonStringField(path []string) bool { type SchemaRepositoryInterface interface { GetSchema(resourceType string) (*Schema, bool) + SetFlags(typ string, flags ...Flags) UpdateSchema(typ string, schemasMutators map[string]func(attributeSchema *AttributeSchema)) SetNormalizeFunc(typ string, normalizeFunc func(res *Resource)) SetHumanReadableAttributesFunc(typ string, humanReadableAttributesFunc func(res *Resource) map[string]string) @@ -106,6 +122,17 @@ func (r *SchemaRepository) Init(providerName, providerVersion string, schema map return nil } +func (r SchemaRepository) SetFlags(typ string, flags ...Flags) { + metadata, exist := r.GetSchema(typ) + if !exist { + logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to set flags, no schema found") + return + } + for _, flag := range flags { + metadata.Flags.AddFlag(flag) + } +} + func (r *SchemaRepository) UpdateSchema(typ string, schemasMutators map[string]func(attributeSchema *AttributeSchema)) { for s, f := range schemasMutators { metadata, exist := r.GetSchema(typ)