diff --git a/pkg/resource/aws/aws_s3_bucket_analytics_configuration.go b/pkg/resource/aws/aws_s3_bucket_analytics_configuration.go index ac3b620c..dca70d1b 100644 --- a/pkg/resource/aws/aws_s3_bucket_analytics_configuration.go +++ b/pkg/resource/aws/aws_s3_bucket_analytics_configuration.go @@ -10,4 +10,5 @@ func initAwsS3BucketAnalyticsConfigurationMetaData(resourceSchemaRepository reso "alias": *res.Attributes().GetString("region"), } }) + resourceSchemaRepository.SetFlags(AwsS3BucketAnalyticsConfigurationResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/metadata_test.go b/pkg/resource/aws/metadata_test.go new file mode 100644 index 00000000..4f61c5e7 --- /dev/null +++ b/pkg/resource/aws/metadata_test.go @@ -0,0 +1,106 @@ +package aws + +import ( + "testing" + + "github.com/cloudskiff/driftctl/pkg/resource" + tf "github.com/cloudskiff/driftctl/pkg/terraform" + testresource "github.com/cloudskiff/driftctl/test/resource" + "github.com/stretchr/testify/assert" +) + +func TestAWS_Metadata_Flags(t *testing.T) { + testcases := map[string][]resource.Flags{ + AwsAmiResourceType: {resource.FlagDeepMode}, + AwsApiGatewayAccountResourceType: {}, + AwsApiGatewayApiKeyResourceType: {}, + AwsApiGatewayAuthorizerResourceType: {}, + AwsApiGatewayDeploymentResourceType: {}, + AwsApiGatewayDomainNameResourceType: {}, + AwsApiGatewayRequestValidatorResourceType: {}, + AwsApiGatewayResourceResourceType: {}, + AwsApiGatewayRestApiResourceType: {}, + AwsApiGatewayRestApiPolicyResourceType: {}, + AwsApiGatewayStageResourceType: {}, + AwsApiGatewayVpcLinkResourceType: {}, + AwsAppAutoscalingPolicyResourceType: {resource.FlagDeepMode}, + AwsAppAutoscalingScheduledActionResourceType: {}, + AwsAppAutoscalingTargetResourceType: {resource.FlagDeepMode}, + AwsCloudformationStackResourceType: {resource.FlagDeepMode}, + AwsCloudfrontDistributionResourceType: {resource.FlagDeepMode}, + AwsDbInstanceResourceType: {resource.FlagDeepMode}, + AwsDbSubnetGroupResourceType: {resource.FlagDeepMode}, + AwsDefaultNetworkACLResourceType: {resource.FlagDeepMode}, + AwsDefaultRouteTableResourceType: {resource.FlagDeepMode}, + AwsDefaultSecurityGroupResourceType: {resource.FlagDeepMode}, + AwsDefaultSubnetResourceType: {resource.FlagDeepMode}, + AwsDefaultVpcResourceType: {resource.FlagDeepMode}, + AwsDynamodbTableResourceType: {resource.FlagDeepMode}, + AwsEbsSnapshotResourceType: {resource.FlagDeepMode}, + AwsEbsVolumeResourceType: {resource.FlagDeepMode}, + AwsEcrRepositoryResourceType: {resource.FlagDeepMode}, + AwsEipResourceType: {resource.FlagDeepMode}, + AwsEipAssociationResourceType: {resource.FlagDeepMode}, + AwsIamAccessKeyResourceType: {resource.FlagDeepMode}, + AwsIamPolicyResourceType: {resource.FlagDeepMode}, + AwsIamPolicyAttachmentResourceType: {resource.FlagDeepMode}, + AwsIamRoleResourceType: {resource.FlagDeepMode}, + AwsIamRolePolicyResourceType: {resource.FlagDeepMode}, + AwsIamRolePolicyAttachmentResourceType: {resource.FlagDeepMode}, + AwsIamUserResourceType: {resource.FlagDeepMode}, + AwsIamUserPolicyResourceType: {resource.FlagDeepMode}, + AwsIamUserPolicyAttachmentResourceType: {resource.FlagDeepMode}, + AwsInstanceResourceType: {resource.FlagDeepMode}, + AwsInternetGatewayResourceType: {resource.FlagDeepMode}, + AwsKeyPairResourceType: {resource.FlagDeepMode}, + AwsKmsAliasResourceType: {resource.FlagDeepMode}, + AwsKmsKeyResourceType: {resource.FlagDeepMode}, + AwsLambdaEventSourceMappingResourceType: {resource.FlagDeepMode}, + AwsLambdaFunctionResourceType: {resource.FlagDeepMode}, + AwsNatGatewayResourceType: {resource.FlagDeepMode}, + AwsNetworkACLResourceType: {resource.FlagDeepMode}, + AwsRDSClusterResourceType: {resource.FlagDeepMode}, + AwsRDSClusterInstanceResourceType: {}, + AwsRouteResourceType: {resource.FlagDeepMode}, + AwsRoute53HealthCheckResourceType: {resource.FlagDeepMode}, + AwsRoute53RecordResourceType: {resource.FlagDeepMode}, + AwsRoute53ZoneResourceType: {resource.FlagDeepMode}, + AwsRouteTableResourceType: {resource.FlagDeepMode}, + AwsRouteTableAssociationResourceType: {resource.FlagDeepMode}, + AwsS3BucketResourceType: {resource.FlagDeepMode}, + AwsS3BucketAnalyticsConfigurationResourceType: {resource.FlagDeepMode}, + AwsS3BucketInventoryResourceType: {resource.FlagDeepMode}, + AwsS3BucketMetricResourceType: {resource.FlagDeepMode}, + AwsS3BucketNotificationResourceType: {resource.FlagDeepMode}, + AwsS3BucketPolicyResourceType: {resource.FlagDeepMode}, + AwsSecurityGroupResourceType: {resource.FlagDeepMode}, + AwsSnsTopicResourceType: {resource.FlagDeepMode}, + AwsSnsTopicPolicyResourceType: {resource.FlagDeepMode}, + AwsSnsTopicSubscriptionResourceType: {resource.FlagDeepMode}, + AwsSqsQueueResourceType: {resource.FlagDeepMode}, + AwsSqsQueuePolicyResourceType: {resource.FlagDeepMode}, + AwsSubnetResourceType: {resource.FlagDeepMode}, + AwsVpcResourceType: {resource.FlagDeepMode}, + AwsSecurityGroupRuleResourceType: {resource.FlagDeepMode}, + AwsNetworkACLRuleResourceType: {resource.FlagDeepMode}, + } + + schemaRepository := testresource.InitFakeSchemaRepository(tf.AWS, "3.19.0") + InitResourcesMetadata(schemaRepository) + + for ty, flags := range testcases { + t.Run(ty, func(tt *testing.T) { + sch, exist := schemaRepository.GetSchema(ty) + assert.True(tt, exist) + + if len(flags) == 0 { + assert.Equal(tt, resource.Flags(0x0), sch.Flags, "should not have any flag") + return + } + + for _, flag := range flags { + assert.Truef(tt, sch.Flags.HasFlag(flag), "should have given flag %d", flag) + } + }) + } +} diff --git a/pkg/resource/azurerm/metadata_test.go b/pkg/resource/azurerm/metadata_test.go new file mode 100644 index 00000000..cb8b17b5 --- /dev/null +++ b/pkg/resource/azurerm/metadata_test.go @@ -0,0 +1,47 @@ +package azurerm + +import ( + "testing" + + "github.com/cloudskiff/driftctl/pkg/resource" + tf "github.com/cloudskiff/driftctl/pkg/terraform" + testresource "github.com/cloudskiff/driftctl/test/resource" + "github.com/stretchr/testify/assert" +) + +func TestAzureMetadata_Flags(t *testing.T) { + testcases := map[string][]resource.Flags{ + AzureContainerRegistryResourceType: {}, + AzureFirewallResourceType: {}, + AzurePostgresqlServerResourceType: {}, + AzurePostgresqlDatabaseResourceType: {}, + AzurePublicIPResourceType: {}, + AzureResourceGroupResourceType: {}, + AzureRouteResourceType: {}, + AzureRouteTableResourceType: {}, + AzureStorageAccountResourceType: {}, + AzureStorageContainerResourceType: {}, + AzureSubnetResourceType: {}, + AzureVirtualNetworkResourceType: {}, + AzureNetworkSecurityGroupResourceType: {resource.FlagDeepMode}, + } + + schemaRepository := testresource.InitFakeSchemaRepository(tf.AZURE, "2.71.0") + InitResourcesMetadata(schemaRepository) + + for ty, flags := range testcases { + t.Run(ty, func(tt *testing.T) { + sch, exist := schemaRepository.GetSchema(ty) + assert.True(tt, exist) + + if len(flags) == 0 { + assert.Equal(tt, resource.Flags(0x0), sch.Flags, "should not have any flag") + return + } + + for _, flag := range flags { + assert.Truef(tt, sch.Flags.HasFlag(flag), "should have given flag %d", flag) + } + }) + } +} diff --git a/pkg/resource/github/metadata_test.go b/pkg/resource/github/metadata_test.go new file mode 100644 index 00000000..379bfcf0 --- /dev/null +++ b/pkg/resource/github/metadata_test.go @@ -0,0 +1,39 @@ +package github + +import ( + "testing" + + "github.com/cloudskiff/driftctl/pkg/resource" + tf "github.com/cloudskiff/driftctl/pkg/terraform" + testresource "github.com/cloudskiff/driftctl/test/resource" + "github.com/stretchr/testify/assert" +) + +func TestGitHub_Metadata_Flags(t *testing.T) { + testcases := map[string][]resource.Flags{ + GithubBranchProtectionResourceType: {resource.FlagDeepMode}, + GithubMembershipResourceType: {resource.FlagDeepMode}, + GithubTeamMembershipResourceType: {resource.FlagDeepMode}, + GithubRepositoryResourceType: {resource.FlagDeepMode}, + GithubTeamResourceType: {resource.FlagDeepMode}, + } + + schemaRepository := testresource.InitFakeSchemaRepository(tf.GITHUB, "4.4.0") + InitResourcesMetadata(schemaRepository) + + for ty, flags := range testcases { + t.Run(ty, func(tt *testing.T) { + sch, exist := schemaRepository.GetSchema(ty) + assert.True(tt, exist) + + if len(flags) == 0 { + assert.Equal(tt, resource.Flags(0x0), sch.Flags, "should not have any flag") + return + } + + for _, flag := range flags { + assert.Truef(tt, sch.Flags.HasFlag(flag), "should have given flag %d", flag) + } + }) + } +} diff --git a/pkg/resource/google/metadata_test.go b/pkg/resource/google/metadata_test.go new file mode 100644 index 00000000..bf495f5f --- /dev/null +++ b/pkg/resource/google/metadata_test.go @@ -0,0 +1,49 @@ +package google + +import ( + "testing" + + "github.com/cloudskiff/driftctl/pkg/resource" + tf "github.com/cloudskiff/driftctl/pkg/terraform" + testresource "github.com/cloudskiff/driftctl/test/resource" + "github.com/stretchr/testify/assert" +) + +func TestGoogle_Metadata_Flags(t *testing.T) { + testcases := map[string][]resource.Flags{ + GoogleBigqueryDatasetResourceType: {}, + GoogleComputeFirewallResourceType: {resource.FlagDeepMode}, + GoogleComputeInstanceResourceType: {}, + GoogleComputeInstanceGroupResourceType: {resource.FlagDeepMode}, + GoogleComputeNetworkResourceType: {resource.FlagDeepMode}, + GoogleComputeRouterResourceType: {}, + GoogleDNSManagedZoneResourceType: {}, + GoogleProjectIamBindingResourceType: {}, + GoogleProjectIamMemberResourceType: {resource.FlagDeepMode}, + GoogleProjectIamPolicyResourceType: {}, + GoogleStorageBucketResourceType: {resource.FlagDeepMode}, + GoogleStorageBucketIamBindingResourceType: {}, + GoogleStorageBucketIamMemberResourceType: {resource.FlagDeepMode}, + GoogleStorageBucketIamPolicyResourceType: {}, + GoogleBigqueryTableResourceType: {}, + } + + schemaRepository := testresource.InitFakeSchemaRepository(tf.GOOGLE, "3.78.0") + InitResourcesMetadata(schemaRepository) + + for ty, flags := range testcases { + t.Run(ty, func(tt *testing.T) { + sch, exist := schemaRepository.GetSchema(ty) + assert.True(tt, exist) + + if len(flags) == 0 { + assert.Equal(tt, resource.Flags(0x0), sch.Flags, "should not have any flag") + return + } + + for _, flag := range flags { + assert.Truef(tt, sch.Flags.HasFlag(flag), "should have given flag %d", flag) + } + }) + } +}