From f9065269e8ea23b6de339d12c0089b5150b5f0e2 Mon Sep 17 00:00:00 2001 From: Elie CHARRA Date: Thu, 21 Jul 2022 15:08:43 +0200 Subject: [PATCH] chore: move schema repo in driftctl --- enumeration/resource/schemas.go | 121 ---------- pkg/analyser/analyzer_test.go | 4 +- pkg/cmd/scan.go | 29 +-- pkg/driftctl.go | 18 +- pkg/driftctl_test.go | 27 +-- .../aws_sns_topic_policy_expander.go | 5 +- .../aws_sqs_queue_policy_expander.go | 5 +- pkg/resource/aws/aws_ami.go | 7 +- pkg/resource/aws/aws_apigatewayv2_mapping.go | 7 +- pkg/resource/aws/aws_apigatewayv2_model.go | 7 +- pkg/resource/aws/aws_appautoscaling_policy.go | 7 +- pkg/resource/aws/aws_appautoscaling_target.go | 7 +- pkg/resource/aws/aws_cloudformation_stack.go | 7 +- .../aws/aws_cloudfront_distribution.go | 7 +- pkg/resource/aws/aws_db_instance.go | 7 +- pkg/resource/aws/aws_db_subnet_group.go | 7 +- pkg/resource/aws/aws_default_network_acl.go | 7 +- pkg/resource/aws/aws_default_route_table.go | 7 +- .../aws/aws_default_security_group.go | 7 +- pkg/resource/aws/aws_default_subnet.go | 7 +- pkg/resource/aws/aws_default_vpc.go | 7 +- pkg/resource/aws/aws_dynamodb_table.go | 7 +- .../aws/aws_ebs_encryption_by_default.go | 7 +- pkg/resource/aws/aws_ebs_snapshot.go | 7 +- pkg/resource/aws/aws_ebs_volume.go | 7 +- pkg/resource/aws/aws_ecr_repository.go | 7 +- pkg/resource/aws/aws_eip.go | 7 +- pkg/resource/aws/aws_eip_association.go | 7 +- pkg/resource/aws/aws_iam_access_key.go | 7 +- pkg/resource/aws/aws_iam_policy.go | 3 +- pkg/resource/aws/aws_iam_policy_attachment.go | 7 +- pkg/resource/aws/aws_iam_role.go | 7 +- pkg/resource/aws/aws_iam_role_policy.go | 7 +- .../aws/aws_iam_role_policy_attachment.go | 7 +- pkg/resource/aws/aws_iam_user.go | 7 +- pkg/resource/aws/aws_iam_user_policy.go | 7 +- .../aws/aws_iam_user_policy_attachment.go | 7 +- pkg/resource/aws/aws_instance.go | 4 +- pkg/resource/aws/aws_internet_gateway.go | 7 +- pkg/resource/aws/aws_key_pair.go | 7 +- pkg/resource/aws/aws_kms_alias.go | 7 +- pkg/resource/aws/aws_kms_key.go | 3 +- .../aws/aws_lambda_event_source_mapping.go | 7 +- pkg/resource/aws/aws_lambda_function.go | 7 +- pkg/resource/aws/aws_launch_template.go | 7 +- pkg/resource/aws/aws_lb.go | 7 +- pkg/resource/aws/aws_nat_gateway.go | 7 +- pkg/resource/aws/aws_network_acl.go | 7 +- pkg/resource/aws/aws_network_acl_rule.go | 3 +- pkg/resource/aws/aws_rds_cluster.go | 7 +- pkg/resource/aws/aws_route.go | 4 +- pkg/resource/aws/aws_route53_health_check.go | 4 +- pkg/resource/aws/aws_route53_record.go | 7 +- pkg/resource/aws/aws_route53_zone.go | 7 +- pkg/resource/aws/aws_route_table.go | 7 +- .../aws/aws_route_table_association.go | 7 +- pkg/resource/aws/aws_s3_bucket.go | 7 +- .../aws_s3_bucket_analytics_configuration.go | 7 +- pkg/resource/aws/aws_s3_bucket_inventory.go | 7 +- pkg/resource/aws/aws_s3_bucket_metric.go | 7 +- .../aws/aws_s3_bucket_notification.go | 7 +- pkg/resource/aws/aws_s3_bucket_policy.go | 3 +- pkg/resource/aws/aws_security_group.go | 7 +- pkg/resource/aws/aws_security_group_rule.go | 3 +- pkg/resource/aws/aws_sns_topic.go | 7 +- pkg/resource/aws/aws_sns_topic_policy.go | 3 +- .../aws/aws_sns_topic_subscription.go | 3 +- pkg/resource/aws/aws_sqs_queue.go | 7 +- pkg/resource/aws/aws_sqs_queue_policy.go | 3 +- pkg/resource/aws/aws_subnet.go | 7 +- pkg/resource/aws/aws_vpc.go | 7 +- pkg/resource/aws/metadata_test.go | 217 +++++++++--------- pkg/resource/aws/metadatas.go | 4 +- .../azurerm/azurerm_container_registry.go | 7 +- pkg/resource/azurerm/azurerm_firewall.go | 7 +- pkg/resource/azurerm/azurerm_image.go | 7 +- pkg/resource/azurerm/azurerm_lb.go | 7 +- pkg/resource/azurerm/azurerm_lb_rule.go | 7 +- .../azurerm/azurerm_network_security_group.go | 7 +- .../azurerm/azurerm_postgresql_database.go | 7 +- .../azurerm/azurerm_postgresql_server.go | 7 +- .../azurerm/azurerm_private_dns_a_record.go | 7 +- .../azurerm_private_dns_aaaa_record.go | 7 +- .../azurerm_private_dns_cname_record.go | 7 +- .../azurerm/azurerm_private_dns_mx_record.go | 7 +- .../azurerm/azurerm_private_dns_ptr_record.go | 7 +- .../azurerm/azurerm_private_dns_srv_record.go | 7 +- .../azurerm/azurerm_private_dns_txt_record.go | 7 +- .../azurerm/azurerm_private_dns_zone.go | 7 +- pkg/resource/azurerm/azurerm_public_ip.go | 7 +- .../azurerm/azurerm_resource_group.go | 7 +- pkg/resource/azurerm/azurerm_route.go | 7 +- pkg/resource/azurerm/azurerm_route_table.go | 7 +- .../azurerm/azurerm_ssh_public_key.go | 7 +- .../azurerm/azurerm_virtual_network.go | 7 +- pkg/resource/azurerm/metadata.go | 4 +- pkg/resource/azurerm/metadata_test.go | 55 ++--- pkg/resource/factory.go | 10 +- .../github/github_branch_protection.go | 4 +- pkg/resource/github/github_membership.go | 3 +- pkg/resource/github/github_repository.go | 3 +- pkg/resource/github/github_team.go | 3 +- pkg/resource/github/github_team_membership.go | 3 +- pkg/resource/github/metadata_test.go | 15 +- pkg/resource/github/metadatas.go | 4 +- .../google/google_bigquery_dataset.go | 3 +- pkg/resource/google/google_bigquery_table.go | 7 +- pkg/resource/google/google_compute_address.go | 7 +- pkg/resource/google/google_compute_disk.go | 7 +- .../google/google_compute_firewall.go | 3 +- .../google/google_compute_global_address.go | 7 +- .../google/google_compute_health_check.go | 7 +- pkg/resource/google/google_compute_image.go | 7 +- .../google/google_compute_instance_group.go | 3 +- .../google_compute_instance_group_manager.go | 7 +- pkg/resource/google/google_compute_network.go | 3 +- .../google/google_compute_subnetwork.go | 3 +- .../google/google_project_iam_member.go | 3 +- pkg/resource/google/google_storage_bucket.go | 3 +- .../google_storage_bucket_iam_member.go | 3 +- pkg/resource/google/metadata_test.go | 51 ++-- pkg/resource/google/metadatas.go | 2 +- pkg/resource/schemas.go | 12 + pkg/resource/schemas/repository.go | 134 +++++++++++ test/resource/resource.go | 13 +- 125 files changed, 836 insertions(+), 544 deletions(-) create mode 100644 pkg/resource/schemas.go create mode 100644 pkg/resource/schemas/repository.go diff --git a/enumeration/resource/schemas.go b/enumeration/resource/schemas.go index a21cb798..01d5c039 100644 --- a/enumeration/resource/schemas.go +++ b/enumeration/resource/schemas.go @@ -5,8 +5,6 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/terraform/configs/configschema" - "github.com/hashicorp/terraform/providers" - "github.com/sirupsen/logrus" ) type AttributeSchema struct { @@ -53,122 +51,3 @@ func (s *Schema) IsJsonStringField(path []string) bool { } return metadata.JsonString } - -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) - SetDiscriminantFunc(string, func(*Resource, *Resource) bool) -} - -type SchemaRepository struct { - schemas map[string]*Schema - ProviderName string - ProviderVersion *version.Version -} - -func NewSchemaRepository() *SchemaRepository { - return &SchemaRepository{ - schemas: make(map[string]*Schema), - } -} - -func (r *SchemaRepository) GetSchema(resourceType string) (*Schema, bool) { - schema, exist := r.schemas[resourceType] - return schema, exist -} - -func (r *SchemaRepository) fetchNestedBlocks(root string, metadata map[string]AttributeSchema, block map[string]*configschema.NestedBlock) { - for s, nestedBlock := range block { - path := s - if root != "" { - path = strings.Join([]string{root, s}, ".") - } - for s2, attr := range nestedBlock.Attributes { - nestedPath := strings.Join([]string{path, s2}, ".") - metadata[nestedPath] = AttributeSchema{ - ConfigSchema: *attr, - } - } - r.fetchNestedBlocks(path, metadata, nestedBlock.BlockTypes) - } -} - -func (r *SchemaRepository) Init(providerName, providerVersion string, schema map[string]providers.Schema) error { - v, err := version.NewVersion(providerVersion) - if err != nil { - return err - } - r.ProviderVersion = v - r.ProviderName = providerName - for typ, sch := range schema { - attributeMetas := map[string]AttributeSchema{} - for s, attribute := range sch.Block.Attributes { - attributeMetas[s] = AttributeSchema{ - ConfigSchema: *attribute, - } - } - - r.fetchNestedBlocks("", attributeMetas, sch.Block.BlockTypes) - - r.schemas[typ] = &Schema{ - ProviderVersion: r.ProviderVersion, - SchemaVersion: sch.Version, - Attributes: attributeMetas, - } - } - 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) - if !exist { - logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to set metadata, no schema found") - return - } - m := (*metadata).Attributes[s] - f(&m) - (*metadata).Attributes[s] = m - } -} - -func (r *SchemaRepository) SetNormalizeFunc(typ string, normalizeFunc func(res *Resource)) { - metadata, exist := r.GetSchema(typ) - if !exist { - logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to set normalize func, no schema found") - return - } - (*metadata).NormalizeFunc = normalizeFunc -} - -func (r *SchemaRepository) SetHumanReadableAttributesFunc(typ string, humanReadableAttributesFunc func(res *Resource) map[string]string) { - metadata, exist := r.GetSchema(typ) - if !exist { - logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to add human readable attributes, no schema found") - return - } - (*metadata).HumanReadableAttributesFunc = humanReadableAttributesFunc -} - -func (r *SchemaRepository) SetDiscriminantFunc(typ string, fn func(self, res *Resource) bool) { - metadata, exist := r.GetSchema(typ) - if !exist { - logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to set discriminant function, no schema found") - return - } - (*metadata).DiscriminantFunc = fn -} diff --git a/pkg/analyser/analyzer_test.go b/pkg/analyser/analyzer_test.go index 9b0c116a..68ed848a 100644 --- a/pkg/analyser/analyzer_test.go +++ b/pkg/analyser/analyzer_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + dctlresource "github.com/snyk/driftctl/pkg/resource" + alerter2 "github.com/snyk/driftctl/enumeration/alerter" "github.com/snyk/driftctl/pkg/filter" @@ -1264,7 +1266,7 @@ func TestAnalyze(t *testing.T) { } } -func addSchemaToRes(res *resource.Resource, repo resource.SchemaRepositoryInterface) { +func addSchemaToRes(res *resource.Resource, repo dctlresource.SchemaRepositoryInterface) { schema, _ := repo.GetSchema(res.ResourceType()) res.Sch = schema } diff --git a/pkg/cmd/scan.go b/pkg/cmd/scan.go index af2b2ffe..657d8364 100644 --- a/pkg/cmd/scan.go +++ b/pkg/cmd/scan.go @@ -19,7 +19,6 @@ import ( "github.com/snyk/driftctl/enumeration/alerter" "github.com/snyk/driftctl/enumeration/remote" "github.com/snyk/driftctl/enumeration/remote/common" - "github.com/snyk/driftctl/enumeration/resource" "github.com/snyk/driftctl/enumeration/terraform" "github.com/snyk/driftctl/enumeration/terraform/lock" "github.com/snyk/driftctl/pkg/analyser" @@ -27,10 +26,7 @@ import ( "github.com/snyk/driftctl/pkg/iac/terraform/state" "github.com/snyk/driftctl/pkg/memstore" dctlresource "github.com/snyk/driftctl/pkg/resource" - "github.com/snyk/driftctl/pkg/resource/aws" - "github.com/snyk/driftctl/pkg/resource/azurerm" - "github.com/snyk/driftctl/pkg/resource/github" - "github.com/snyk/driftctl/pkg/resource/google" + "github.com/snyk/driftctl/pkg/resource/schemas" "github.com/snyk/driftctl/pkg/telemetry" "github.com/snyk/driftctl/pkg/terraform/hcl" "github.com/spf13/cobra" @@ -291,7 +287,7 @@ func scanRun(opts *pkg.ScanOptions) error { iacProgress := globaloutput.NewProgress("Scanning states", "Scanned states", true) scanProgress := globaloutput.NewProgress("Scanning resources", "Scanned resources", false) - resourceSchemaRepository := resource.NewSchemaRepository() + resourceSchemaRepository := schemas.NewSchemaRepository() resFactory := dctlresource.NewDriftctlResourceFactory(resourceSchemaRepository) @@ -300,17 +296,10 @@ func scanRun(opts *pkg.ScanOptions) error { return err } - switch opts.To { - case common.RemoteAWSTerraform: - aws.InitResourcesMetadata(resourceSchemaRepository) - case common.RemoteGithubTerraform: - github.InitResourcesMetadata(resourceSchemaRepository) - case common.RemoteGoogleTerraform: - google.InitResourcesMetadata(resourceSchemaRepository) - case common.RemoteAzureTerraform: - azurerm.InitResourcesMetadata(resourceSchemaRepository) - default: - return errors.Errorf("unsupported remote '%s'", opts.To) + providerName := common.RemoteParameter(opts.To).GetProviderAddress().Type + err = resourceSchemaRepository.Init(providerName, opts.ProviderVersion, providerLibrary.Provider(opts.To).Schema()) + if err != nil { + return err } // Teardown @@ -355,8 +344,8 @@ func scanRun(opts *pkg.ScanOptions) error { return err } - analysis.ProviderVersion = resourceSchemaRepository.ProviderVersion.String() - analysis.ProviderName = resourceSchemaRepository.ProviderName + analysis.ProviderVersion = opts.ProviderVersion + analysis.ProviderName = opts.To store.Bucket(memstore.TelemetryBucket).Set("provider_name", analysis.ProviderName) validOutput := false @@ -377,7 +366,7 @@ func scanRun(opts *pkg.ScanOptions) error { } globaloutput.Printf(color.WhiteString("Scan duration: %s\n", analysis.Duration.Round(time.Second))) - globaloutput.Printf(color.WhiteString("Provider version used to scan: %s. Use --tf-provider-version to use another version.\n"), resourceSchemaRepository.ProviderVersion.String()) + globaloutput.Printf(color.WhiteString("Provider version used to scan: %s. Use --tf-provider-version to use another version.\n"), opts.ProviderVersion) if !opts.DisableTelemetry { tl := telemetry.NewTelemetry(&build.Build{}) diff --git a/pkg/driftctl.go b/pkg/driftctl.go index 953f4cf4..3bd515f0 100644 --- a/pkg/driftctl.go +++ b/pkg/driftctl.go @@ -4,21 +4,19 @@ import ( "fmt" "time" - "github.com/snyk/driftctl/enumeration/alerter" - resource2 "github.com/snyk/driftctl/pkg/resource" - "github.com/jmespath/go-jmespath" "github.com/sirupsen/logrus" - "github.com/snyk/driftctl/pkg/memstore" - globaloutput "github.com/snyk/driftctl/pkg/output" - + "github.com/snyk/driftctl/enumeration/alerter" "github.com/snyk/driftctl/enumeration/resource" "github.com/snyk/driftctl/pkg/analyser" "github.com/snyk/driftctl/pkg/cmd/scan/output" "github.com/snyk/driftctl/pkg/filter" "github.com/snyk/driftctl/pkg/iac/config" "github.com/snyk/driftctl/pkg/iac/terraform/state/backend" + "github.com/snyk/driftctl/pkg/memstore" "github.com/snyk/driftctl/pkg/middlewares" + globaloutput "github.com/snyk/driftctl/pkg/output" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) type FmtOptions struct { @@ -47,26 +45,26 @@ type ScanOptions struct { type DriftCTL struct { remoteSupplier resource.Supplier - iacSupplier resource2.IaCSupplier + iacSupplier dctlresource.IaCSupplier alerter alerter.AlerterInterface analyzer *analyser.Analyzer resourceFactory resource.ResourceFactory scanProgress globaloutput.Progress iacProgress globaloutput.Progress - resourceSchemaRepository resource.SchemaRepositoryInterface + resourceSchemaRepository dctlresource.SchemaRepositoryInterface opts *ScanOptions store memstore.Store } func NewDriftCTL(remoteSupplier resource.Supplier, - iacSupplier resource2.IaCSupplier, + iacSupplier dctlresource.IaCSupplier, alerter *alerter.Alerter, analyzer *analyser.Analyzer, resFactory resource.ResourceFactory, opts *ScanOptions, scanProgress globaloutput.Progress, iacProgress globaloutput.Progress, - resourceSchemaRepository resource.SchemaRepositoryInterface, + resourceSchemaRepository dctlresource.SchemaRepositoryInterface, store memstore.Store) *DriftCTL { return &DriftCTL{ remoteSupplier, diff --git a/pkg/driftctl_test.go b/pkg/driftctl_test.go index d3ead48e..14126cb4 100644 --- a/pkg/driftctl_test.go +++ b/pkg/driftctl_test.go @@ -14,7 +14,6 @@ import ( "github.com/snyk/driftctl/pkg/output" dctlresource "github.com/snyk/driftctl/pkg/resource" "github.com/snyk/driftctl/pkg/resource/aws" - "github.com/snyk/driftctl/pkg/resource/github" "github.com/snyk/driftctl/test" testresource "github.com/snyk/driftctl/test/resource" "github.com/stretchr/testify/assert" @@ -31,7 +30,7 @@ type TestCase struct { provider *TestProvider stateResources []*resource.Resource remoteResources []*resource.Resource - mocks func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) + mocks func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) assert func(t *testing.T, result *test.ScanResult, err error) assertStore func(*testing.T, memstore.Store) options *pkg.ScanOptions @@ -48,8 +47,6 @@ func runTest(t *testing.T, cases TestCases) { } } repo := testresource.InitFakeSchemaRepository(c.provider.Name, c.provider.Version) - aws.InitResourcesMetadata(repo) - github.InitResourcesMetadata(repo) t.Run(c.name, func(t *testing.T) { testAlerter := alerter.NewAlerter() @@ -363,7 +360,7 @@ func TestDriftctlRun_BasicBehavior(t *testing.T) { }, { name: "we should ignore default AWS IAM role when strict mode is disabled", - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { factory.(*dctlresource.MockResourceFactory).On( "CreateAbstractResource", aws.AwsIamPolicyAttachmentResourceType, @@ -461,7 +458,7 @@ func TestDriftctlRun_BasicBehavior(t *testing.T) { }, { name: "we should not ignore default AWS IAM role when strict mode is enabled", - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { factory.(*dctlresource.MockResourceFactory).On( "CreateAbstractResource", aws.AwsIamPolicyAttachmentResourceType, @@ -559,7 +556,7 @@ func TestDriftctlRun_BasicBehavior(t *testing.T) { }, { name: "we should not ignore default AWS IAM role when strict mode is enabled and a filter is specified", - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { factory.(*dctlresource.MockResourceFactory).On( "CreateAbstractResource", aws.AwsIamPolicyAttachmentResourceType, @@ -790,7 +787,7 @@ func TestDriftctlRun_Middlewares(t *testing.T) { }, }, }, - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { factory.(*dctlresource.MockResourceFactory).On( "CreateAbstractResource", aws.AwsS3BucketPolicyResourceType, @@ -877,7 +874,7 @@ func TestDriftctlRun_Middlewares(t *testing.T) { }, }, }, - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { foo := resource.Resource{ Id: "vol-018c5ae89895aca4c", Type: "aws_ebs_volume", @@ -992,7 +989,7 @@ func TestDriftctlRun_Middlewares(t *testing.T) { }, }, }, - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { factory.(*dctlresource.MockResourceFactory).On("CreateAbstractResource", "aws_route", "r-table1080289494", mock.MatchedBy(func(input map[string]interface{}) bool { return matchByAttributes(input, map[string]interface{}{ "destination_cidr_block": "0.0.0.0/0", @@ -1070,7 +1067,7 @@ func TestDriftctlRun_Middlewares(t *testing.T) { }, }, }, - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { factory.(*dctlresource.MockResourceFactory).On("CreateAbstractResource", "aws_sns_topic_policy", "foo", map[string]interface{}{ "id": "foo", "arn": "arn", @@ -1132,7 +1129,7 @@ func TestDriftctlRun_Middlewares(t *testing.T) { }, }, }, - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { factory.(*dctlresource.MockResourceFactory).On("CreateAbstractResource", "aws_sqs_queue_policy", "foo", map[string]interface{}{ "id": "foo", "queue_url": "foo", @@ -1344,7 +1341,7 @@ func TestDriftctlRun_Middlewares(t *testing.T) { }, }, }, - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { rule1 := resource.Resource{ Type: aws.AwsSecurityGroupRuleResourceType, Id: "sgrule-1707973622", @@ -1553,7 +1550,7 @@ func TestDriftctlRun_Middlewares(t *testing.T) { }, }, }, - mocks: func(factory resource.ResourceFactory, repo resource.SchemaRepositoryInterface) { + mocks: func(factory resource.ResourceFactory, repo dctlresource.SchemaRepositoryInterface) { factory.(*dctlresource.MockResourceFactory).On("CreateAbstractResource", aws.AwsIamPolicyAttachmentResourceType, "iduser1", map[string]interface{}{ "id": "iduser1", "policy_arn": "policy_arn1", @@ -1784,7 +1781,7 @@ func TestDriftctlRun_Middlewares(t *testing.T) { runTest(t, cases) } -func getSchema(repo resource.SchemaRepositoryInterface, resourceType string) *resource.Schema { +func getSchema(repo dctlresource.SchemaRepositoryInterface, resourceType string) *resource.Schema { sch, _ := repo.GetSchema(resourceType) return sch } diff --git a/pkg/middlewares/aws_sns_topic_policy_expander.go b/pkg/middlewares/aws_sns_topic_policy_expander.go index 233198aa..7b4707c6 100644 --- a/pkg/middlewares/aws_sns_topic_policy_expander.go +++ b/pkg/middlewares/aws_sns_topic_policy_expander.go @@ -4,16 +4,17 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" "github.com/snyk/driftctl/pkg/resource/aws" ) // Explodes policy found in aws_sns_topic from state resources to aws_sns_topic_policy resources type AwsSNSTopicPolicyExpander struct { resourceFactory resource.ResourceFactory - resourceSchemaRepository resource.SchemaRepositoryInterface + resourceSchemaRepository dctlresource.SchemaRepositoryInterface } -func NewAwsSNSTopicPolicyExpander(resourceFactory resource.ResourceFactory, resourceSchemaRepository resource.SchemaRepositoryInterface) AwsSNSTopicPolicyExpander { +func NewAwsSNSTopicPolicyExpander(resourceFactory resource.ResourceFactory, resourceSchemaRepository dctlresource.SchemaRepositoryInterface) AwsSNSTopicPolicyExpander { return AwsSNSTopicPolicyExpander{ resourceFactory, resourceSchemaRepository, diff --git a/pkg/middlewares/aws_sqs_queue_policy_expander.go b/pkg/middlewares/aws_sqs_queue_policy_expander.go index 81472478..9bd2100c 100644 --- a/pkg/middlewares/aws_sqs_queue_policy_expander.go +++ b/pkg/middlewares/aws_sqs_queue_policy_expander.go @@ -3,16 +3,17 @@ package middlewares import ( "github.com/sirupsen/logrus" "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" "github.com/snyk/driftctl/pkg/resource/aws" ) // Explodes policy found in aws_sqs_queue.policy from state resources to dedicated resources type AwsSQSQueuePolicyExpander struct { resourceFactory resource.ResourceFactory - resourceSchemaRepository resource.SchemaRepositoryInterface + resourceSchemaRepository dctlresource.SchemaRepositoryInterface } -func NewAwsSQSQueuePolicyExpander(resourceFactory resource.ResourceFactory, resourceSchemaRepository resource.SchemaRepositoryInterface) AwsSQSQueuePolicyExpander { +func NewAwsSQSQueuePolicyExpander(resourceFactory resource.ResourceFactory, resourceSchemaRepository dctlresource.SchemaRepositoryInterface) AwsSQSQueuePolicyExpander { return AwsSQSQueuePolicyExpander{ resourceFactory, resourceSchemaRepository, diff --git a/pkg/resource/aws/aws_ami.go b/pkg/resource/aws/aws_ami.go index b436575e..6934d4d9 100644 --- a/pkg/resource/aws/aws_ami.go +++ b/pkg/resource/aws/aws_ami.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsAmiResourceType = "aws_ami" -func initAwsAmiMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsAmiMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsAmiResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_apigatewayv2_mapping.go b/pkg/resource/aws/aws_apigatewayv2_mapping.go index dd563a9a..55269a55 100644 --- a/pkg/resource/aws/aws_apigatewayv2_mapping.go +++ b/pkg/resource/aws/aws_apigatewayv2_mapping.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsApiGatewayV2MappingResourceType = "aws_apigatewayv2_api_mapping" -func initAwsApiGatewayV2MappingMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsApiGatewayV2MappingMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc( AwsApiGatewayV2MappingResourceType, func(res *resource.Resource) map[string]string { diff --git a/pkg/resource/aws/aws_apigatewayv2_model.go b/pkg/resource/aws/aws_apigatewayv2_model.go index 471ae493..879861ee 100644 --- a/pkg/resource/aws/aws_apigatewayv2_model.go +++ b/pkg/resource/aws/aws_apigatewayv2_model.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsApiGatewayV2ModelResourceType = "aws_apigatewayv2_model" -func initAwsApiGatewayV2ModelMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsApiGatewayV2ModelMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc( AwsApiGatewayV2ModelResourceType, func(res *resource.Resource) map[string]string { diff --git a/pkg/resource/aws/aws_appautoscaling_policy.go b/pkg/resource/aws/aws_appautoscaling_policy.go index 33c6ea0b..30087e64 100644 --- a/pkg/resource/aws/aws_appautoscaling_policy.go +++ b/pkg/resource/aws/aws_appautoscaling_policy.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsAppAutoscalingPolicyResourceType = "aws_appautoscaling_policy" -func initAwsAppAutoscalingPolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsAppAutoscalingPolicyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AwsAppAutoscalingPolicyResourceType, func(res *resource.Resource) map[string]string { attrs := make(map[string]string) if v := res.Attributes().GetString("scalable_dimension"); v != nil && *v != "" { diff --git a/pkg/resource/aws/aws_appautoscaling_target.go b/pkg/resource/aws/aws_appautoscaling_target.go index 67ce5e84..5819da28 100644 --- a/pkg/resource/aws/aws_appautoscaling_target.go +++ b/pkg/resource/aws/aws_appautoscaling_target.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsAppAutoscalingTargetResourceType = "aws_appautoscaling_target" -func initAwsAppAutoscalingTargetMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsAppAutoscalingTargetMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AwsAppAutoscalingTargetResourceType, func(res *resource.Resource) map[string]string { attrs := make(map[string]string) if v := res.Attributes().GetString("scalable_dimension"); v != nil && *v != "" { diff --git a/pkg/resource/aws/aws_cloudformation_stack.go b/pkg/resource/aws/aws_cloudformation_stack.go index d65c6297..6f47f2e1 100644 --- a/pkg/resource/aws/aws_cloudformation_stack.go +++ b/pkg/resource/aws/aws_cloudformation_stack.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsCloudformationStackResourceType = "aws_cloudformation_stack" -func initAwsCloudformationStackMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsCloudformationStackMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsCloudformationStackResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_cloudfront_distribution.go b/pkg/resource/aws/aws_cloudfront_distribution.go index 44fbf3af..5dba03be 100644 --- a/pkg/resource/aws/aws_cloudfront_distribution.go +++ b/pkg/resource/aws/aws_cloudfront_distribution.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsCloudfrontDistributionResourceType = "aws_cloudfront_distribution" -func initAwsCloudfrontDistributionMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsCloudfrontDistributionMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsCloudfrontDistributionResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"etag"}) diff --git a/pkg/resource/aws/aws_db_instance.go b/pkg/resource/aws/aws_db_instance.go index 280681fd..b9af967e 100644 --- a/pkg/resource/aws/aws_db_instance.go +++ b/pkg/resource/aws/aws_db_instance.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsDbInstanceResourceType = "aws_db_instance" -func initAwsDbInstanceMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsDbInstanceMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsDbInstanceResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"delete_automated_backups"}) diff --git a/pkg/resource/aws/aws_db_subnet_group.go b/pkg/resource/aws/aws_db_subnet_group.go index a716cbaa..c190929a 100644 --- a/pkg/resource/aws/aws_db_subnet_group.go +++ b/pkg/resource/aws/aws_db_subnet_group.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsDbSubnetGroupResourceType = "aws_db_subnet_group" -func initAwsDbSubnetGroupMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsDbSubnetGroupMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsDbSubnetGroupResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"name_prefix"}) diff --git a/pkg/resource/aws/aws_default_network_acl.go b/pkg/resource/aws/aws_default_network_acl.go index 353b5ddd..3f21c400 100644 --- a/pkg/resource/aws/aws_default_network_acl.go +++ b/pkg/resource/aws/aws_default_network_acl.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsDefaultNetworkACLResourceType = "aws_default_network_acl" -func initAwsDefaultNetworkACLMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsDefaultNetworkACLMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsDefaultNetworkACLResourceType, func(res *resource.Resource) { res.Attrs.SafeDelete([]string{"default_network_acl_id"}) diff --git a/pkg/resource/aws/aws_default_route_table.go b/pkg/resource/aws/aws_default_route_table.go index 0965c995..e76780cc 100644 --- a/pkg/resource/aws/aws_default_route_table.go +++ b/pkg/resource/aws/aws_default_route_table.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsDefaultRouteTableResourceType = "aws_default_route_table" -func initAwsDefaultRouteTableMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsDefaultRouteTableMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsDefaultRouteTableResourceType, resource.FlagDeepMode) resourceSchemaRepository.SetNormalizeFunc(AwsDefaultRouteTableResourceType, func(res *resource.Resource) { val := res.Attrs diff --git a/pkg/resource/aws/aws_default_security_group.go b/pkg/resource/aws/aws_default_security_group.go index 6615025c..c045dd75 100644 --- a/pkg/resource/aws/aws_default_security_group.go +++ b/pkg/resource/aws/aws_default_security_group.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsDefaultSecurityGroupResourceType = "aws_default_security_group" -func initAwsDefaultSecurityGroupMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsDefaultSecurityGroupMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsDefaultSecurityGroupResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"revoke_rules_on_delete"}) diff --git a/pkg/resource/aws/aws_default_subnet.go b/pkg/resource/aws/aws_default_subnet.go index d0e597de..b08853d1 100644 --- a/pkg/resource/aws/aws_default_subnet.go +++ b/pkg/resource/aws/aws_default_subnet.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsDefaultSubnetResourceType = "aws_default_subnet" -func initAwsDefaultSubnetMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsDefaultSubnetMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsDefaultSubnetResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_default_vpc.go b/pkg/resource/aws/aws_default_vpc.go index 62a02a12..7cfc3733 100644 --- a/pkg/resource/aws/aws_default_vpc.go +++ b/pkg/resource/aws/aws_default_vpc.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsDefaultVpcResourceType = "aws_default_vpc" -func initAwsDefaultVpcMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsDefaultVpcMetaData(resourceSchemaRepository dctlresource.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 eb0d4c7d..30ae1fbb 100644 --- a/pkg/resource/aws/aws_dynamodb_table.go +++ b/pkg/resource/aws/aws_dynamodb_table.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsDynamodbTableResourceType = "aws_dynamodb_table" -func initAwsDynamodbTableMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsDynamodbTableMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsDynamodbTableResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_ebs_encryption_by_default.go b/pkg/resource/aws/aws_ebs_encryption_by_default.go index 502b99f3..ba831bc3 100644 --- a/pkg/resource/aws/aws_ebs_encryption_by_default.go +++ b/pkg/resource/aws/aws_ebs_encryption_by_default.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsEbsEncryptionByDefaultResourceType = "aws_ebs_encryption_by_default" -func initAwsEbsEncryptionByDefaultMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsEbsEncryptionByDefaultMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsEbsEncryptionByDefaultResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_ebs_snapshot.go b/pkg/resource/aws/aws_ebs_snapshot.go index ff870fa8..4510a1ca 100644 --- a/pkg/resource/aws/aws_ebs_snapshot.go +++ b/pkg/resource/aws/aws_ebs_snapshot.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsEbsSnapshotResourceType = "aws_ebs_snapshot" -func initAwsEbsSnapshotMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsEbsSnapshotMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsEbsSnapshotResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_ebs_volume.go b/pkg/resource/aws/aws_ebs_volume.go index 004e611a..10d7e03b 100644 --- a/pkg/resource/aws/aws_ebs_volume.go +++ b/pkg/resource/aws/aws_ebs_volume.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsEbsVolumeResourceType = "aws_ebs_volume" -func initAwsEbsVolumeMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsEbsVolumeMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsEbsVolumeResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"arn"}) diff --git a/pkg/resource/aws/aws_ecr_repository.go b/pkg/resource/aws/aws_ecr_repository.go index faea0a07..300c48db 100644 --- a/pkg/resource/aws/aws_ecr_repository.go +++ b/pkg/resource/aws/aws_ecr_repository.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsEcrRepositoryResourceType = "aws_ecr_repository" -func initAwsEcrRepositoryMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsEcrRepositoryMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsEcrRepositoryResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_eip.go b/pkg/resource/aws/aws_eip.go index 06fe011f..7895aef2 100644 --- a/pkg/resource/aws/aws_eip.go +++ b/pkg/resource/aws/aws_eip.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsEipResourceType = "aws_eip" -func initAwsEipMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsEipMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsEipResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_eip_association.go b/pkg/resource/aws/aws_eip_association.go index 60248114..6a6e742f 100644 --- a/pkg/resource/aws/aws_eip_association.go +++ b/pkg/resource/aws/aws_eip_association.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsEipAssociationResourceType = "aws_eip_association" -func initAwsEipAssociationMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsEipAssociationMetaData(resourceSchemaRepository dctlresource.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 240512ac..02b9b8cd 100644 --- a/pkg/resource/aws/aws_iam_access_key.go +++ b/pkg/resource/aws/aws_iam_access_key.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsIamAccessKeyResourceType = "aws_iam_access_key" -func initAwsIAMAccessKeyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsIAMAccessKeyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsIamAccessKeyResourceType, func(res *resource.Resource) { val := res.Attrs // As we can't read secrets from aws API once access_key created we need to set diff --git a/pkg/resource/aws/aws_iam_policy.go b/pkg/resource/aws/aws_iam_policy.go index 1718e3b6..6becab4c 100644 --- a/pkg/resource/aws/aws_iam_policy.go +++ b/pkg/resource/aws/aws_iam_policy.go @@ -3,11 +3,12 @@ package aws import ( "github.com/snyk/driftctl/enumeration/resource" "github.com/snyk/driftctl/pkg/helpers" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const AwsIamPolicyResourceType = "aws_iam_policy" -func initAwsIAMPolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsIAMPolicyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsIamPolicyResourceType, func(res *resource.Resource) { val := res.Attrs jsonString, err := helpers.NormalizeJsonString((*val)["policy"]) diff --git a/pkg/resource/aws/aws_iam_policy_attachment.go b/pkg/resource/aws/aws_iam_policy_attachment.go index 36ad1ce4..3201a4c3 100644 --- a/pkg/resource/aws/aws_iam_policy_attachment.go +++ b/pkg/resource/aws/aws_iam_policy_attachment.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsIamPolicyAttachmentResourceType = "aws_iam_policy_attachment" -func initAwsIAMPolicyAttachmentMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsIAMPolicyAttachmentMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsIamPolicyAttachmentResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"name"}) diff --git a/pkg/resource/aws/aws_iam_role.go b/pkg/resource/aws/aws_iam_role.go index 31c84611..36b6b0cb 100644 --- a/pkg/resource/aws/aws_iam_role.go +++ b/pkg/resource/aws/aws_iam_role.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsIamRoleResourceType = "aws_iam_role" -func initAwsIAMRoleMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsIAMRoleMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsIamRoleResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"force_detach_policies"}) diff --git a/pkg/resource/aws/aws_iam_role_policy.go b/pkg/resource/aws/aws_iam_role_policy.go index c0fb3756..16bcda30 100644 --- a/pkg/resource/aws/aws_iam_role_policy.go +++ b/pkg/resource/aws/aws_iam_role_policy.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsIamRolePolicyResourceType = "aws_iam_role_policy" -func initAwsIAMRolePolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsIAMRolePolicyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.UpdateSchema(AwsIamRolePolicyResourceType, map[string]func(attributeSchema *resource.AttributeSchema){ "policy": func(attributeSchema *resource.AttributeSchema) { attributeSchema.JsonString = true diff --git a/pkg/resource/aws/aws_iam_role_policy_attachment.go b/pkg/resource/aws/aws_iam_role_policy_attachment.go index a9d83f24..d94687b5 100644 --- a/pkg/resource/aws/aws_iam_role_policy_attachment.go +++ b/pkg/resource/aws/aws_iam_role_policy_attachment.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsIamRolePolicyAttachmentResourceType = "aws_iam_role_policy_attachment" -func initAwsIamRolePolicyAttachmentMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsIamRolePolicyAttachmentMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsIamRolePolicyAttachmentResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_iam_user.go b/pkg/resource/aws/aws_iam_user.go index 576cd882..1068bed1 100644 --- a/pkg/resource/aws/aws_iam_user.go +++ b/pkg/resource/aws/aws_iam_user.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsIamUserResourceType = "aws_iam_user" -func initAwsIAMUserMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsIAMUserMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsIamUserResourceType, func(res *resource.Resource) { val := res.Attrs permissionsBoundary, exist := val.Get("permissions_boundary") diff --git a/pkg/resource/aws/aws_iam_user_policy.go b/pkg/resource/aws/aws_iam_user_policy.go index 9eb7ae9e..d7aba042 100644 --- a/pkg/resource/aws/aws_iam_user_policy.go +++ b/pkg/resource/aws/aws_iam_user_policy.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsIamUserPolicyResourceType = "aws_iam_user_policy" -func initAwsIAMUserPolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsIAMUserPolicyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.UpdateSchema(AwsIamUserPolicyResourceType, map[string]func(attributeSchema *resource.AttributeSchema){ "policy": func(attributeSchema *resource.AttributeSchema) { attributeSchema.JsonString = true diff --git a/pkg/resource/aws/aws_iam_user_policy_attachment.go b/pkg/resource/aws/aws_iam_user_policy_attachment.go index 9b7a41d1..e4319c80 100644 --- a/pkg/resource/aws/aws_iam_user_policy_attachment.go +++ b/pkg/resource/aws/aws_iam_user_policy_attachment.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsIamUserPolicyAttachmentResourceType = "aws_iam_user_policy_attachment" -func initAwsIamUserPolicyAttachmentMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsIamUserPolicyAttachmentMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsIamUserPolicyAttachmentResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_instance.go b/pkg/resource/aws/aws_instance.go index 21fbfff6..d31417be 100644 --- a/pkg/resource/aws/aws_instance.go +++ b/pkg/resource/aws/aws_instance.go @@ -2,13 +2,13 @@ package aws import ( "github.com/hashicorp/go-version" - "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const AwsInstanceResourceType = "aws_instance" -func initAwsInstanceMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsInstanceMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsInstanceResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_internet_gateway.go b/pkg/resource/aws/aws_internet_gateway.go index 500a664e..700ce031 100644 --- a/pkg/resource/aws/aws_internet_gateway.go +++ b/pkg/resource/aws/aws_internet_gateway.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsInternetGatewayResourceType = "aws_internet_gateway" -func initAwsInternetGatewayMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsInternetGatewayMetaData(resourceSchemaRepository dctlresource.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 387aa690..0fedadb2 100644 --- a/pkg/resource/aws/aws_key_pair.go +++ b/pkg/resource/aws/aws_key_pair.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsKeyPairResourceType = "aws_key_pair" -func initAwsKeyPairMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsKeyPairMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsKeyPairResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"key_name_prefix"}) diff --git a/pkg/resource/aws/aws_kms_alias.go b/pkg/resource/aws/aws_kms_alias.go index ae291c50..895697d7 100644 --- a/pkg/resource/aws/aws_kms_alias.go +++ b/pkg/resource/aws/aws_kms_alias.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsKmsAliasResourceType = "aws_kms_alias" -func initAwsKmsAliasMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsKmsAliasMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsKmsAliasResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"name"}) diff --git a/pkg/resource/aws/aws_kms_key.go b/pkg/resource/aws/aws_kms_key.go index e52160a2..3a4e6800 100644 --- a/pkg/resource/aws/aws_kms_key.go +++ b/pkg/resource/aws/aws_kms_key.go @@ -3,11 +3,12 @@ package aws import ( "github.com/snyk/driftctl/enumeration/resource" "github.com/snyk/driftctl/pkg/helpers" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const AwsKmsKeyResourceType = "aws_kms_key" -func initAwsKmsKeyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsKmsKeyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsKmsKeyResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"deletion_window_in_days"}) diff --git a/pkg/resource/aws/aws_lambda_event_source_mapping.go b/pkg/resource/aws/aws_lambda_event_source_mapping.go index b6dc064b..55b11dba 100644 --- a/pkg/resource/aws/aws_lambda_event_source_mapping.go +++ b/pkg/resource/aws/aws_lambda_event_source_mapping.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsLambdaEventSourceMappingResourceType = "aws_lambda_event_source_mapping" -func initAwsLambdaEventSourceMappingMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsLambdaEventSourceMappingMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsLambdaEventSourceMappingResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"state_transition_reason"}) diff --git a/pkg/resource/aws/aws_lambda_function.go b/pkg/resource/aws/aws_lambda_function.go index 3dd86ac7..0a1fa42f 100644 --- a/pkg/resource/aws/aws_lambda_function.go +++ b/pkg/resource/aws/aws_lambda_function.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsLambdaFunctionResourceType = "aws_lambda_function" -func initAwsLambdaFunctionMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsLambdaFunctionMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsLambdaFunctionResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_launch_template.go b/pkg/resource/aws/aws_launch_template.go index ce931e20..f944f202 100644 --- a/pkg/resource/aws/aws_launch_template.go +++ b/pkg/resource/aws/aws_launch_template.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsLaunchTemplateResourceType = "aws_launch_template" -func initAwsLaunchTemplateMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsLaunchTemplateMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsLaunchTemplateResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_lb.go b/pkg/resource/aws/aws_lb.go index 791f8068..e1e9aa90 100644 --- a/pkg/resource/aws/aws_lb.go +++ b/pkg/resource/aws/aws_lb.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsLoadBalancerResourceType = "aws_lb" -func initAwsLoadBalancerMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsLoadBalancerMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AwsLoadBalancerResourceType, func(res *resource.Resource) map[string]string { return map[string]string{ "Name": *res.Attributes().GetString("name"), diff --git a/pkg/resource/aws/aws_nat_gateway.go b/pkg/resource/aws/aws_nat_gateway.go index c51f3a98..8120599d 100644 --- a/pkg/resource/aws/aws_nat_gateway.go +++ b/pkg/resource/aws/aws_nat_gateway.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsNatGatewayResourceType = "aws_nat_gateway" -func initNatGatewayMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initNatGatewayMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsNatGatewayResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_network_acl.go b/pkg/resource/aws/aws_network_acl.go index e2e4650e..9aacebf7 100644 --- a/pkg/resource/aws/aws_network_acl.go +++ b/pkg/resource/aws/aws_network_acl.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsNetworkACLResourceType = "aws_network_acl" -func initAwsNetworkACLMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsNetworkACLMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsNetworkACLResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_network_acl_rule.go b/pkg/resource/aws/aws_network_acl_rule.go index 2cfd12cb..69e87d78 100644 --- a/pkg/resource/aws/aws_network_acl_rule.go +++ b/pkg/resource/aws/aws_network_acl_rule.go @@ -3,6 +3,7 @@ package aws import ( "bytes" "fmt" + dctlresource "github.com/snyk/driftctl/pkg/resource" "strconv" "github.com/hashicorp/terraform/helper/hashcode" @@ -161,7 +162,7 @@ var protocolsNumbers = map[string]int{ "254": 254, } -func initAwsNetworkACLRuleMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsNetworkACLRuleMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsNetworkACLRuleResourceType, func(res *resource.Resource) { res.Attrs.DeleteIfDefault("icmp_code") res.Attrs.DeleteIfDefault("icmp_type") diff --git a/pkg/resource/aws/aws_rds_cluster.go b/pkg/resource/aws/aws_rds_cluster.go index 6a520c64..ecf2d123 100644 --- a/pkg/resource/aws/aws_rds_cluster.go +++ b/pkg/resource/aws/aws_rds_cluster.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsRDSClusterResourceType = "aws_rds_cluster" -func initAwsRDSClusterMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsRDSClusterMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsRDSClusterResourceType, func(res *resource.Resource) { val := res.Attributes() val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_route.go b/pkg/resource/aws/aws_route.go index 0325d335..64fe1c02 100644 --- a/pkg/resource/aws/aws_route.go +++ b/pkg/resource/aws/aws_route.go @@ -2,15 +2,15 @@ package aws import ( "fmt" - "github.com/hashicorp/terraform/helper/hashcode" + dctlresource "github.com/snyk/driftctl/pkg/resource" "github.com/snyk/driftctl/enumeration/resource" ) const AwsRouteResourceType = "aws_route" -func initAwsRouteMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsRouteMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsRouteResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_route53_health_check.go b/pkg/resource/aws/aws_route53_health_check.go index e87e5b37..71514c24 100644 --- a/pkg/resource/aws/aws_route53_health_check.go +++ b/pkg/resource/aws/aws_route53_health_check.go @@ -2,13 +2,13 @@ package aws import ( "fmt" - "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const AwsRoute53HealthCheckResourceType = "aws_route53_health_check" -func initAwsRoute53HealthCheckMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsRoute53HealthCheckMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AwsRoute53HealthCheckResourceType, func(res *resource.Resource) map[string]string { val := res.Attrs attrs := make(map[string]string) diff --git a/pkg/resource/aws/aws_route53_record.go b/pkg/resource/aws/aws_route53_record.go index c4c9e20c..4ac6c06d 100644 --- a/pkg/resource/aws/aws_route53_record.go +++ b/pkg/resource/aws/aws_route53_record.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsRoute53RecordResourceType = "aws_route53_record" -func initAwsRoute53RecordMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsRoute53RecordMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsRoute53RecordResourceType, func(res *resource.Resource) { val := res.Attrs val.DeleteIfDefault("health_check_id") diff --git a/pkg/resource/aws/aws_route53_zone.go b/pkg/resource/aws/aws_route53_zone.go index 419def8b..8b40986f 100644 --- a/pkg/resource/aws/aws_route53_zone.go +++ b/pkg/resource/aws/aws_route53_zone.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsRoute53ZoneResourceType = "aws_route53_zone" -func initAwsRoute53ZoneMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsRoute53ZoneMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsRoute53ZoneResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"force_destroy"}) diff --git a/pkg/resource/aws/aws_route_table.go b/pkg/resource/aws/aws_route_table.go index edef3856..0085d2b8 100644 --- a/pkg/resource/aws/aws_route_table.go +++ b/pkg/resource/aws/aws_route_table.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsRouteTableResourceType = "aws_route_table" -func initAwsRouteTableMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsRouteTableMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsRouteTableResourceType, resource.FlagDeepMode) resourceSchemaRepository.SetNormalizeFunc(AwsRouteTableResourceType, func(res *resource.Resource) { val := res.Attrs diff --git a/pkg/resource/aws/aws_route_table_association.go b/pkg/resource/aws/aws_route_table_association.go index 1632de70..6378f5c7 100644 --- a/pkg/resource/aws/aws_route_table_association.go +++ b/pkg/resource/aws/aws_route_table_association.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsRouteTableAssociationResourceType = "aws_route_table_association" -func initAwsRouteTableAssociationMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsRouteTableAssociationMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AwsRouteTableAssociationResourceType, func(res *resource.Resource) map[string]string { val := res.Attrs attrs := make(map[string]string) diff --git a/pkg/resource/aws/aws_s3_bucket.go b/pkg/resource/aws/aws_s3_bucket.go index dc615c1a..6a2aefad 100644 --- a/pkg/resource/aws/aws_s3_bucket.go +++ b/pkg/resource/aws/aws_s3_bucket.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsS3BucketResourceType = "aws_s3_bucket" -func initAwsS3BucketMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsS3BucketMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsS3BucketResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"force_destroy"}) diff --git a/pkg/resource/aws/aws_s3_bucket_analytics_configuration.go b/pkg/resource/aws/aws_s3_bucket_analytics_configuration.go index 470d5faa..2d7a9543 100644 --- a/pkg/resource/aws/aws_s3_bucket_analytics_configuration.go +++ b/pkg/resource/aws/aws_s3_bucket_analytics_configuration.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsS3BucketAnalyticsConfigurationResourceType = "aws_s3_bucket_analytics_configuration" -func initAwsS3BucketAnalyticsConfigurationMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsS3BucketAnalyticsConfigurationMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsS3BucketAnalyticsConfigurationResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/aws_s3_bucket_inventory.go b/pkg/resource/aws/aws_s3_bucket_inventory.go index 7424fc84..df4509cb 100644 --- a/pkg/resource/aws/aws_s3_bucket_inventory.go +++ b/pkg/resource/aws/aws_s3_bucket_inventory.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsS3BucketInventoryResourceType = "aws_s3_bucket_inventory" -func initAwsS3BucketInventoryMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsS3BucketInventoryMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { 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 68e14a8d..634b7fb8 100644 --- a/pkg/resource/aws/aws_s3_bucket_metric.go +++ b/pkg/resource/aws/aws_s3_bucket_metric.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsS3BucketMetricResourceType = "aws_s3_bucket_metric" -func initAwsS3BucketMetricMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsS3BucketMetricMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { 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 789ff720..172e7c90 100644 --- a/pkg/resource/aws/aws_s3_bucket_notification.go +++ b/pkg/resource/aws/aws_s3_bucket_notification.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsS3BucketNotificationResourceType = "aws_s3_bucket_notification" -func initAwsS3BucketNotificationMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsS3BucketNotificationMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { 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 3621b598..ad7aa68a 100644 --- a/pkg/resource/aws/aws_s3_bucket_policy.go +++ b/pkg/resource/aws/aws_s3_bucket_policy.go @@ -3,11 +3,12 @@ package aws import ( "github.com/snyk/driftctl/enumeration/resource" "github.com/snyk/driftctl/pkg/helpers" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const AwsS3BucketPolicyResourceType = "aws_s3_bucket_policy" -func initAwsS3BucketPolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsS3BucketPolicyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsS3BucketPolicyResourceType, func(res *resource.Resource) { val := res.Attrs jsonString, err := helpers.NormalizeJsonString((*val)["policy"]) diff --git a/pkg/resource/aws/aws_security_group.go b/pkg/resource/aws/aws_security_group.go index 5ded2939..25b5331d 100644 --- a/pkg/resource/aws/aws_security_group.go +++ b/pkg/resource/aws/aws_security_group.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsSecurityGroupResourceType = "aws_security_group" -func initAwsSecurityGroupMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsSecurityGroupMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsSecurityGroupResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"revoke_rules_on_delete"}) diff --git a/pkg/resource/aws/aws_security_group_rule.go b/pkg/resource/aws/aws_security_group_rule.go index e4e8ea47..ebae6ce9 100644 --- a/pkg/resource/aws/aws_security_group_rule.go +++ b/pkg/resource/aws/aws_security_group_rule.go @@ -3,6 +3,7 @@ package aws import ( "bytes" "fmt" + dctlresource "github.com/snyk/driftctl/pkg/resource" "strings" "github.com/hashicorp/terraform/helper/hashcode" @@ -11,7 +12,7 @@ import ( const AwsSecurityGroupRuleResourceType = "aws_security_group_rule" -func initAwsSecurityGroupRuleMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsSecurityGroupRuleMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsSecurityGroupRuleResourceType, func(res *resource.Resource) { val := res.Attrs val.DeleteIfDefault("security_group_id") diff --git a/pkg/resource/aws/aws_sns_topic.go b/pkg/resource/aws/aws_sns_topic.go index 40516244..ea4ae873 100644 --- a/pkg/resource/aws/aws_sns_topic.go +++ b/pkg/resource/aws/aws_sns_topic.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsSnsTopicResourceType = "aws_sns_topic" -func initSnsTopicMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initSnsTopicMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsSnsTopicResourceType, func(res *resource.Resource) { val := res.Attrs val.DeleteIfDefault("sqs_success_feedback_sample_rate") diff --git a/pkg/resource/aws/aws_sns_topic_policy.go b/pkg/resource/aws/aws_sns_topic_policy.go index a6f034a2..9b4a7670 100644 --- a/pkg/resource/aws/aws_sns_topic_policy.go +++ b/pkg/resource/aws/aws_sns_topic_policy.go @@ -3,11 +3,12 @@ package aws import ( "github.com/snyk/driftctl/enumeration/resource" "github.com/snyk/driftctl/pkg/helpers" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const AwsSnsTopicPolicyResourceType = "aws_sns_topic_policy" -func initSnsTopicPolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initSnsTopicPolicyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsSnsTopicPolicyResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"owner"}) diff --git a/pkg/resource/aws/aws_sns_topic_subscription.go b/pkg/resource/aws/aws_sns_topic_subscription.go index 4e508d25..1075be87 100644 --- a/pkg/resource/aws/aws_sns_topic_subscription.go +++ b/pkg/resource/aws/aws_sns_topic_subscription.go @@ -3,11 +3,12 @@ package aws import ( "github.com/snyk/driftctl/enumeration/resource" "github.com/snyk/driftctl/pkg/helpers" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const AwsSnsTopicSubscriptionResourceType = "aws_sns_topic_subscription" -func initSnsTopicSubscriptionMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initSnsTopicSubscriptionMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsSnsTopicSubscriptionResourceType, func(res *resource.Resource) { val := res.Attrs jsonString, err := helpers.NormalizeJsonString((*val)["delivery_policy"]) diff --git a/pkg/resource/aws/aws_sqs_queue.go b/pkg/resource/aws/aws_sqs_queue.go index 7c7aa1bf..da740abb 100644 --- a/pkg/resource/aws/aws_sqs_queue.go +++ b/pkg/resource/aws/aws_sqs_queue.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsSqsQueueResourceType = "aws_sqs_queue" -func initSqsQueueMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initSqsQueueMetaData(resourceSchemaRepository dctlresource.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 a339ff3e..a3b9d0ff 100644 --- a/pkg/resource/aws/aws_sqs_queue_policy.go +++ b/pkg/resource/aws/aws_sqs_queue_policy.go @@ -3,11 +3,12 @@ package aws import ( "github.com/snyk/driftctl/enumeration/resource" "github.com/snyk/driftctl/pkg/helpers" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const AwsSqsQueuePolicyResourceType = "aws_sqs_queue_policy" -func initAwsSQSQueuePolicyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsSQSQueuePolicyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsSqsQueuePolicyResourceType, func(res *resource.Resource) { val := res.Attrs jsonString, err := helpers.NormalizeJsonString((*val)["policy"]) diff --git a/pkg/resource/aws/aws_subnet.go b/pkg/resource/aws/aws_subnet.go index 6419b157..298ed4b6 100644 --- a/pkg/resource/aws/aws_subnet.go +++ b/pkg/resource/aws/aws_subnet.go @@ -1,10 +1,13 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsSubnetResourceType = "aws_subnet" -func initAwsSubnetMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsSubnetMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AwsSubnetResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/aws/aws_vpc.go b/pkg/resource/aws/aws_vpc.go index 8d7ae9ac..5f991400 100644 --- a/pkg/resource/aws/aws_vpc.go +++ b/pkg/resource/aws/aws_vpc.go @@ -1,9 +1,12 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AwsVpcResourceType = "aws_vpc" -func initAwsVpcMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAwsVpcMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetFlags(AwsVpcResourceType, resource.FlagDeepMode) } diff --git a/pkg/resource/aws/metadata_test.go b/pkg/resource/aws/metadata_test.go index aab306ab..10d53c5f 100644 --- a/pkg/resource/aws/metadata_test.go +++ b/pkg/resource/aws/metadata_test.go @@ -1,125 +1,126 @@ -package aws +package aws_test import ( "testing" "github.com/snyk/driftctl/enumeration/resource" + "github.com/snyk/driftctl/pkg/resource/aws" testresource "github.com/snyk/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: {}, - AwsApiGatewayBasePathMappingResourceType: {}, - AwsApiGatewayDeploymentResourceType: {}, - AwsApiGatewayDomainNameResourceType: {}, - AwsApiGatewayGatewayResponseResourceType: {}, - AwsApiGatewayIntegrationResourceType: {}, - AwsApiGatewayIntegrationResponseResourceType: {}, - AwsApiGatewayMethodResourceType: {}, - AwsApiGatewayMethodResponseResourceType: {}, - AwsApiGatewayMethodSettingsResourceType: {}, - AwsApiGatewayModelResourceType: {}, - AwsApiGatewayRequestValidatorResourceType: {}, - AwsApiGatewayResourceResourceType: {}, - AwsApiGatewayRestApiResourceType: {}, - AwsApiGatewayRestApiPolicyResourceType: {}, - AwsApiGatewayStageResourceType: {}, - AwsApiGatewayVpcLinkResourceType: {}, - AwsApiGatewayV2ApiResourceType: {}, - AwsApiGatewayV2RouteResourceType: {}, - AwsApiGatewayV2DeploymentResourceType: {}, - AwsApiGatewayV2VpcLinkResourceType: {}, - AwsApiGatewayV2AuthorizerResourceType: {}, - AwsApiGatewayV2RouteResponseResourceType: {}, - AwsApiGatewayV2DomainNameResourceType: {}, - AwsApiGatewayV2ModelResourceType: {}, - AwsApiGatewayV2StageResourceType: {}, - AwsApiGatewayV2MappingResourceType: {}, - AwsApiGatewayV2IntegrationResourceType: {}, - AwsApiGatewayV2IntegrationResponseResourceType: {}, - 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}, - AwsEbsEncryptionByDefaultResourceType: {resource.FlagDeepMode}, - AwsEbsSnapshotResourceType: {resource.FlagDeepMode}, - AwsEbsVolumeResourceType: {resource.FlagDeepMode}, - AwsEcrRepositoryResourceType: {resource.FlagDeepMode}, - AwsEipResourceType: {resource.FlagDeepMode}, - AwsEipAssociationResourceType: {resource.FlagDeepMode}, - AwsElastiCacheClusterResourceType: {}, - 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}, - AwsIamGroupPolicyResourceType: {}, - AwsIamGroupPolicyAttachmentResourceType: {}, - 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}, - AwsS3BucketPublicAccessBlockResourceType: {}, - 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}, - AwsLaunchTemplateResourceType: {resource.FlagDeepMode}, - AwsLaunchConfigurationResourceType: {}, - AwsLoadBalancerResourceType: {}, - AwsApplicationLoadBalancerResourceType: {}, - AwsClassicLoadBalancerResourceType: {}, - AwsLoadBalancerListenerResourceType: {}, - AwsApplicationLoadBalancerListenerResourceType: {}, - AwsIamGroupResourceType: {}, - AwsEcrRepositoryPolicyResourceType: {}, + aws.AwsAmiResourceType: {resource.FlagDeepMode}, + aws.AwsApiGatewayAccountResourceType: {}, + aws.AwsApiGatewayApiKeyResourceType: {}, + aws.AwsApiGatewayAuthorizerResourceType: {}, + aws.AwsApiGatewayBasePathMappingResourceType: {}, + aws.AwsApiGatewayDeploymentResourceType: {}, + aws.AwsApiGatewayDomainNameResourceType: {}, + aws.AwsApiGatewayGatewayResponseResourceType: {}, + aws.AwsApiGatewayIntegrationResourceType: {}, + aws.AwsApiGatewayIntegrationResponseResourceType: {}, + aws.AwsApiGatewayMethodResourceType: {}, + aws.AwsApiGatewayMethodResponseResourceType: {}, + aws.AwsApiGatewayMethodSettingsResourceType: {}, + aws.AwsApiGatewayModelResourceType: {}, + aws.AwsApiGatewayRequestValidatorResourceType: {}, + aws.AwsApiGatewayResourceResourceType: {}, + aws.AwsApiGatewayRestApiResourceType: {}, + aws.AwsApiGatewayRestApiPolicyResourceType: {}, + aws.AwsApiGatewayStageResourceType: {}, + aws.AwsApiGatewayVpcLinkResourceType: {}, + aws.AwsApiGatewayV2ApiResourceType: {}, + aws.AwsApiGatewayV2RouteResourceType: {}, + aws.AwsApiGatewayV2DeploymentResourceType: {}, + aws.AwsApiGatewayV2VpcLinkResourceType: {}, + aws.AwsApiGatewayV2AuthorizerResourceType: {}, + aws.AwsApiGatewayV2RouteResponseResourceType: {}, + aws.AwsApiGatewayV2DomainNameResourceType: {}, + aws.AwsApiGatewayV2ModelResourceType: {}, + aws.AwsApiGatewayV2StageResourceType: {}, + aws.AwsApiGatewayV2MappingResourceType: {}, + aws.AwsApiGatewayV2IntegrationResourceType: {}, + aws.AwsApiGatewayV2IntegrationResponseResourceType: {}, + aws.AwsAppAutoscalingPolicyResourceType: {resource.FlagDeepMode}, + aws.AwsAppAutoscalingScheduledActionResourceType: {}, + aws.AwsAppAutoscalingTargetResourceType: {resource.FlagDeepMode}, + aws.AwsCloudformationStackResourceType: {resource.FlagDeepMode}, + aws.AwsCloudfrontDistributionResourceType: {resource.FlagDeepMode}, + aws.AwsDbInstanceResourceType: {resource.FlagDeepMode}, + aws.AwsDbSubnetGroupResourceType: {resource.FlagDeepMode}, + aws.AwsDefaultNetworkACLResourceType: {resource.FlagDeepMode}, + aws.AwsDefaultRouteTableResourceType: {resource.FlagDeepMode}, + aws.AwsDefaultSecurityGroupResourceType: {resource.FlagDeepMode}, + aws.AwsDefaultSubnetResourceType: {resource.FlagDeepMode}, + aws.AwsDefaultVpcResourceType: {resource.FlagDeepMode}, + aws.AwsDynamodbTableResourceType: {resource.FlagDeepMode}, + aws.AwsEbsEncryptionByDefaultResourceType: {resource.FlagDeepMode}, + aws.AwsEbsSnapshotResourceType: {resource.FlagDeepMode}, + aws.AwsEbsVolumeResourceType: {resource.FlagDeepMode}, + aws.AwsEcrRepositoryResourceType: {resource.FlagDeepMode}, + aws.AwsEipResourceType: {resource.FlagDeepMode}, + aws.AwsEipAssociationResourceType: {resource.FlagDeepMode}, + aws.AwsElastiCacheClusterResourceType: {}, + aws.AwsIamAccessKeyResourceType: {resource.FlagDeepMode}, + aws.AwsIamPolicyResourceType: {resource.FlagDeepMode}, + aws.AwsIamPolicyAttachmentResourceType: {resource.FlagDeepMode}, + aws.AwsIamRoleResourceType: {resource.FlagDeepMode}, + aws.AwsIamRolePolicyResourceType: {resource.FlagDeepMode}, + aws.AwsIamRolePolicyAttachmentResourceType: {resource.FlagDeepMode}, + aws.AwsIamUserResourceType: {resource.FlagDeepMode}, + aws.AwsIamUserPolicyResourceType: {resource.FlagDeepMode}, + aws.AwsIamUserPolicyAttachmentResourceType: {resource.FlagDeepMode}, + aws.AwsIamGroupPolicyResourceType: {}, + aws.AwsIamGroupPolicyAttachmentResourceType: {}, + aws.AwsInstanceResourceType: {resource.FlagDeepMode}, + aws.AwsInternetGatewayResourceType: {resource.FlagDeepMode}, + aws.AwsKeyPairResourceType: {resource.FlagDeepMode}, + aws.AwsKmsAliasResourceType: {resource.FlagDeepMode}, + aws.AwsKmsKeyResourceType: {resource.FlagDeepMode}, + aws.AwsLambdaEventSourceMappingResourceType: {resource.FlagDeepMode}, + aws.AwsLambdaFunctionResourceType: {resource.FlagDeepMode}, + aws.AwsNatGatewayResourceType: {resource.FlagDeepMode}, + aws.AwsNetworkACLResourceType: {resource.FlagDeepMode}, + aws.AwsRDSClusterResourceType: {resource.FlagDeepMode}, + aws.AwsRDSClusterInstanceResourceType: {}, + aws.AwsRouteResourceType: {resource.FlagDeepMode}, + aws.AwsRoute53HealthCheckResourceType: {resource.FlagDeepMode}, + aws.AwsRoute53RecordResourceType: {resource.FlagDeepMode}, + aws.AwsRoute53ZoneResourceType: {resource.FlagDeepMode}, + aws.AwsRouteTableResourceType: {resource.FlagDeepMode}, + aws.AwsRouteTableAssociationResourceType: {resource.FlagDeepMode}, + aws.AwsS3BucketResourceType: {resource.FlagDeepMode}, + aws.AwsS3BucketAnalyticsConfigurationResourceType: {resource.FlagDeepMode}, + aws.AwsS3BucketInventoryResourceType: {resource.FlagDeepMode}, + aws.AwsS3BucketMetricResourceType: {resource.FlagDeepMode}, + aws.AwsS3BucketNotificationResourceType: {resource.FlagDeepMode}, + aws.AwsS3BucketPolicyResourceType: {resource.FlagDeepMode}, + aws.AwsS3BucketPublicAccessBlockResourceType: {}, + aws.AwsSecurityGroupResourceType: {resource.FlagDeepMode}, + aws.AwsSnsTopicResourceType: {resource.FlagDeepMode}, + aws.AwsSnsTopicPolicyResourceType: {resource.FlagDeepMode}, + aws.AwsSnsTopicSubscriptionResourceType: {resource.FlagDeepMode}, + aws.AwsSqsQueueResourceType: {resource.FlagDeepMode}, + aws.AwsSqsQueuePolicyResourceType: {resource.FlagDeepMode}, + aws.AwsSubnetResourceType: {resource.FlagDeepMode}, + aws.AwsVpcResourceType: {resource.FlagDeepMode}, + aws.AwsSecurityGroupRuleResourceType: {resource.FlagDeepMode}, + aws.AwsNetworkACLRuleResourceType: {resource.FlagDeepMode}, + aws.AwsLaunchTemplateResourceType: {resource.FlagDeepMode}, + aws.AwsLaunchConfigurationResourceType: {}, + aws.AwsLoadBalancerResourceType: {}, + aws.AwsApplicationLoadBalancerResourceType: {}, + aws.AwsClassicLoadBalancerResourceType: {}, + aws.AwsLoadBalancerListenerResourceType: {}, + aws.AwsApplicationLoadBalancerListenerResourceType: {}, + aws.AwsIamGroupResourceType: {}, + aws.AwsEcrRepositoryPolicyResourceType: {}, } schemaRepository := testresource.InitFakeSchemaRepository("aws", "3.19.0") - InitResourcesMetadata(schemaRepository) + aws.InitResourcesMetadata(schemaRepository) for ty, flags := range testcases { t.Run(ty, func(tt *testing.T) { diff --git a/pkg/resource/aws/metadatas.go b/pkg/resource/aws/metadatas.go index 7f3bca99..512dd2ae 100644 --- a/pkg/resource/aws/metadatas.go +++ b/pkg/resource/aws/metadatas.go @@ -1,6 +1,8 @@ package aws -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/pkg/resource" +) func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { initAwsAmiMetaData(resourceSchemaRepository) diff --git a/pkg/resource/azurerm/azurerm_container_registry.go b/pkg/resource/azurerm/azurerm_container_registry.go index 4a6d52b6..9239775d 100644 --- a/pkg/resource/azurerm/azurerm_container_registry.go +++ b/pkg/resource/azurerm/azurerm_container_registry.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureContainerRegistryResourceType = "azurerm_container_registry" -func initAzureContainerRegistryMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureContainerRegistryMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzureContainerRegistryResourceType, func(res *resource.Resource) map[string]string { val := res.Attrs attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_firewall.go b/pkg/resource/azurerm/azurerm_firewall.go index ded79fe2..ed3f90a2 100644 --- a/pkg/resource/azurerm/azurerm_firewall.go +++ b/pkg/resource/azurerm/azurerm_firewall.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureFirewallResourceType = "azurerm_firewall" -func initAzureFirewallMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureFirewallMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzureFirewallResourceType, func(res *resource.Resource) map[string]string { val := res.Attrs attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_image.go b/pkg/resource/azurerm/azurerm_image.go index 0a650295..a0823b4f 100644 --- a/pkg/resource/azurerm/azurerm_image.go +++ b/pkg/resource/azurerm/azurerm_image.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureImageResourceType = "azurerm_image" -func initAzureImageMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureImageMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzureImageResourceType, func(res *resource.Resource) map[string]string { attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_lb.go b/pkg/resource/azurerm/azurerm_lb.go index 04a7cc0d..c715d76e 100644 --- a/pkg/resource/azurerm/azurerm_lb.go +++ b/pkg/resource/azurerm/azurerm_lb.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureLoadBalancerResourceType = "azurerm_lb" -func initAzureLoadBalancerMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureLoadBalancerMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzureLoadBalancerResourceType, func(res *resource.Resource) map[string]string { val := res.Attrs attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_lb_rule.go b/pkg/resource/azurerm/azurerm_lb_rule.go index 2fe23ae6..762f1cf9 100644 --- a/pkg/resource/azurerm/azurerm_lb_rule.go +++ b/pkg/resource/azurerm/azurerm_lb_rule.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureLoadBalancerRuleResourceType = "azurerm_lb_rule" -func initAzureLoadBalancerRuleMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureLoadBalancerRuleMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzureLoadBalancerRuleResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_network_security_group.go b/pkg/resource/azurerm/azurerm_network_security_group.go index a8688379..77481d9c 100644 --- a/pkg/resource/azurerm/azurerm_network_security_group.go +++ b/pkg/resource/azurerm/azurerm_network_security_group.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureNetworkSecurityGroupResourceType = "azurerm_network_security_group" -func initAzureNetworkSecurityGroupMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureNetworkSecurityGroupMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzureNetworkSecurityGroupResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_postgresql_database.go b/pkg/resource/azurerm/azurerm_postgresql_database.go index 7a5784f9..a47ca822 100644 --- a/pkg/resource/azurerm/azurerm_postgresql_database.go +++ b/pkg/resource/azurerm/azurerm_postgresql_database.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePostgresqlDatabaseResourceType = "azurerm_postgresql_database" -func initAzurePostgresqlDatabaseMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePostgresqlDatabaseMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzurePostgresqlDatabaseResourceType, func(res *resource.Resource) map[string]string { val := res.Attrs attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_postgresql_server.go b/pkg/resource/azurerm/azurerm_postgresql_server.go index 167e68c3..b2570d5d 100644 --- a/pkg/resource/azurerm/azurerm_postgresql_server.go +++ b/pkg/resource/azurerm/azurerm_postgresql_server.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePostgresqlServerResourceType = "azurerm_postgresql_server" -func initAzurePostgresqlServerMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePostgresqlServerMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzurePostgresqlServerResourceType, func(res *resource.Resource) map[string]string { val := res.Attrs attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_private_dns_a_record.go b/pkg/resource/azurerm/azurerm_private_dns_a_record.go index e67af833..8205b956 100644 --- a/pkg/resource/azurerm/azurerm_private_dns_a_record.go +++ b/pkg/resource/azurerm/azurerm_private_dns_a_record.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePrivateDNSARecordResourceType = "azurerm_private_dns_a_record" -func initAzurePrivateDNSARecordMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePrivateDNSARecordMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzurePrivateDNSARecordResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_private_dns_aaaa_record.go b/pkg/resource/azurerm/azurerm_private_dns_aaaa_record.go index 0c06bb77..f39f60d4 100644 --- a/pkg/resource/azurerm/azurerm_private_dns_aaaa_record.go +++ b/pkg/resource/azurerm/azurerm_private_dns_aaaa_record.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePrivateDNSAAAARecordResourceType = "azurerm_private_dns_aaaa_record" -func initAzurePrivateDNSAAAARecordMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePrivateDNSAAAARecordMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzurePrivateDNSAAAARecordResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_private_dns_cname_record.go b/pkg/resource/azurerm/azurerm_private_dns_cname_record.go index 18a2f905..3e99dc30 100644 --- a/pkg/resource/azurerm/azurerm_private_dns_cname_record.go +++ b/pkg/resource/azurerm/azurerm_private_dns_cname_record.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePrivateDNSCNameRecordResourceType = "azurerm_private_dns_cname_record" -func initAzurePrivateDNSCNameRecordMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePrivateDNSCNameRecordMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzurePrivateDNSCNameRecordResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_private_dns_mx_record.go b/pkg/resource/azurerm/azurerm_private_dns_mx_record.go index e2602954..12a47c1a 100644 --- a/pkg/resource/azurerm/azurerm_private_dns_mx_record.go +++ b/pkg/resource/azurerm/azurerm_private_dns_mx_record.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePrivateDNSMXRecordResourceType = "azurerm_private_dns_mx_record" -func initAzurePrivateDNSMXRecordMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePrivateDNSMXRecordMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzurePrivateDNSMXRecordResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_private_dns_ptr_record.go b/pkg/resource/azurerm/azurerm_private_dns_ptr_record.go index c93a4a3a..5c48e5d0 100644 --- a/pkg/resource/azurerm/azurerm_private_dns_ptr_record.go +++ b/pkg/resource/azurerm/azurerm_private_dns_ptr_record.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePrivateDNSPTRRecordResourceType = "azurerm_private_dns_ptr_record" -func initAzurePrivateDNSPTRRecordMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePrivateDNSPTRRecordMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzurePrivateDNSPTRRecordResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_private_dns_srv_record.go b/pkg/resource/azurerm/azurerm_private_dns_srv_record.go index 9af2d31b..17e4e42f 100644 --- a/pkg/resource/azurerm/azurerm_private_dns_srv_record.go +++ b/pkg/resource/azurerm/azurerm_private_dns_srv_record.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePrivateDNSSRVRecordResourceType = "azurerm_private_dns_srv_record" -func initAzurePrivateDNSSRVRecordMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePrivateDNSSRVRecordMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzurePrivateDNSSRVRecordResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_private_dns_txt_record.go b/pkg/resource/azurerm/azurerm_private_dns_txt_record.go index f351267c..f840781f 100644 --- a/pkg/resource/azurerm/azurerm_private_dns_txt_record.go +++ b/pkg/resource/azurerm/azurerm_private_dns_txt_record.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePrivateDNSTXTRecordResourceType = "azurerm_private_dns_txt_record" -func initAzurePrivateDNSTXTRecordMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePrivateDNSTXTRecordMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzurePrivateDNSTXTRecordResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_private_dns_zone.go b/pkg/resource/azurerm/azurerm_private_dns_zone.go index d923825d..e125a7ea 100644 --- a/pkg/resource/azurerm/azurerm_private_dns_zone.go +++ b/pkg/resource/azurerm/azurerm_private_dns_zone.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePrivateDNSZoneResourceType = "azurerm_private_dns_zone" -func initAzurePrivateDNSZoneMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePrivateDNSZoneMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzurePrivateDNSZoneResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"number_of_record_sets"}) res.Attributes().SafeDelete([]string{"timeouts"}) diff --git a/pkg/resource/azurerm/azurerm_public_ip.go b/pkg/resource/azurerm/azurerm_public_ip.go index ac3d0710..3d7b7583 100644 --- a/pkg/resource/azurerm/azurerm_public_ip.go +++ b/pkg/resource/azurerm/azurerm_public_ip.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzurePublicIPResourceType = "azurerm_public_ip" -func initAzurePublicIPMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzurePublicIPMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzurePublicIPResourceType, func(res *resource.Resource) map[string]string { val := res.Attrs attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_resource_group.go b/pkg/resource/azurerm/azurerm_resource_group.go index f30885cb..28dc2d05 100644 --- a/pkg/resource/azurerm/azurerm_resource_group.go +++ b/pkg/resource/azurerm/azurerm_resource_group.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureResourceGroupResourceType = "azurerm_resource_group" -func initAzureResourceGroupMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureResourceGroupMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzureResourceGroupResourceType, func(res *resource.Resource) map[string]string { val := res.Attrs attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_route.go b/pkg/resource/azurerm/azurerm_route.go index 35ef2c12..11eecaf2 100644 --- a/pkg/resource/azurerm/azurerm_route.go +++ b/pkg/resource/azurerm/azurerm_route.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureRouteResourceType = "azurerm_route" -func initAzureRouteMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureRouteMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzureRouteResourceType, func(res *resource.Resource) map[string]string { attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_route_table.go b/pkg/resource/azurerm/azurerm_route_table.go index acfb26d9..7cd04d30 100644 --- a/pkg/resource/azurerm/azurerm_route_table.go +++ b/pkg/resource/azurerm/azurerm_route_table.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureRouteTableResourceType = "azurerm_route_table" -func initAzureRouteTableMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureRouteTableMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzureRouteTableResourceType, func(res *resource.Resource) map[string]string { attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/azurerm_ssh_public_key.go b/pkg/resource/azurerm/azurerm_ssh_public_key.go index a82f894a..30fb3b6a 100644 --- a/pkg/resource/azurerm/azurerm_ssh_public_key.go +++ b/pkg/resource/azurerm/azurerm_ssh_public_key.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureSSHPublicKeyResourceType = "azurerm_ssh_public_key" -func initAzureSSHPublicKeyMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureSSHPublicKeyMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(AzureSSHPublicKeyResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/azurerm/azurerm_virtual_network.go b/pkg/resource/azurerm/azurerm_virtual_network.go index a8e358fa..8424d837 100644 --- a/pkg/resource/azurerm/azurerm_virtual_network.go +++ b/pkg/resource/azurerm/azurerm_virtual_network.go @@ -1,10 +1,13 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const AzureVirtualNetworkResourceType = "azurerm_virtual_network" -func initAzureVirtualNetworkMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initAzureVirtualNetworkMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(AzureVirtualNetworkResourceType, func(res *resource.Resource) map[string]string { attrs := make(map[string]string) diff --git a/pkg/resource/azurerm/metadata.go b/pkg/resource/azurerm/metadata.go index 86f14f31..a01b7533 100644 --- a/pkg/resource/azurerm/metadata.go +++ b/pkg/resource/azurerm/metadata.go @@ -1,6 +1,8 @@ package azurerm -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/pkg/resource" +) func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { initAzureContainerRegistryMetadata(resourceSchemaRepository) diff --git a/pkg/resource/azurerm/metadata_test.go b/pkg/resource/azurerm/metadata_test.go index 725a4c13..9bb7c91b 100644 --- a/pkg/resource/azurerm/metadata_test.go +++ b/pkg/resource/azurerm/metadata_test.go @@ -1,44 +1,45 @@ -package azurerm +package azurerm_test import ( "testing" "github.com/snyk/driftctl/enumeration/resource" + "github.com/snyk/driftctl/pkg/resource/azurerm" testresource "github.com/snyk/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}, - AzureLoadBalancerResourceType: {}, - AzurePrivateDNSZoneResourceType: {resource.FlagDeepMode}, - AzurePrivateDNSARecordResourceType: {resource.FlagDeepMode}, - AzurePrivateDNSAAAARecordResourceType: {resource.FlagDeepMode}, - AzurePrivateDNSCNameRecordResourceType: {resource.FlagDeepMode}, - AzurePrivateDNSPTRRecordResourceType: {resource.FlagDeepMode}, - AzurePrivateDNSMXRecordResourceType: {resource.FlagDeepMode}, - AzurePrivateDNSSRVRecordResourceType: {resource.FlagDeepMode}, - AzurePrivateDNSTXTRecordResourceType: {resource.FlagDeepMode}, - AzureImageResourceType: {}, - AzureSSHPublicKeyResourceType: {resource.FlagDeepMode}, - AzureLoadBalancerRuleResourceType: {resource.FlagDeepMode}, + azurerm.AzureContainerRegistryResourceType: {}, + azurerm.AzureFirewallResourceType: {}, + azurerm.AzurePostgresqlServerResourceType: {}, + azurerm.AzurePostgresqlDatabaseResourceType: {}, + azurerm.AzurePublicIPResourceType: {}, + azurerm.AzureResourceGroupResourceType: {}, + azurerm.AzureRouteResourceType: {}, + azurerm.AzureRouteTableResourceType: {}, + azurerm.AzureStorageAccountResourceType: {}, + azurerm.AzureStorageContainerResourceType: {}, + azurerm.AzureSubnetResourceType: {}, + azurerm.AzureVirtualNetworkResourceType: {}, + azurerm.AzureNetworkSecurityGroupResourceType: {resource.FlagDeepMode}, + azurerm.AzureLoadBalancerResourceType: {}, + azurerm.AzurePrivateDNSZoneResourceType: {resource.FlagDeepMode}, + azurerm.AzurePrivateDNSARecordResourceType: {resource.FlagDeepMode}, + azurerm.AzurePrivateDNSAAAARecordResourceType: {resource.FlagDeepMode}, + azurerm.AzurePrivateDNSCNameRecordResourceType: {resource.FlagDeepMode}, + azurerm.AzurePrivateDNSPTRRecordResourceType: {resource.FlagDeepMode}, + azurerm.AzurePrivateDNSMXRecordResourceType: {resource.FlagDeepMode}, + azurerm.AzurePrivateDNSSRVRecordResourceType: {resource.FlagDeepMode}, + azurerm.AzurePrivateDNSTXTRecordResourceType: {resource.FlagDeepMode}, + azurerm.AzureImageResourceType: {}, + azurerm.AzureSSHPublicKeyResourceType: {resource.FlagDeepMode}, + azurerm.AzureLoadBalancerRuleResourceType: {resource.FlagDeepMode}, } schemaRepository := testresource.InitFakeSchemaRepository("azurerm", "2.71.0") - InitResourcesMetadata(schemaRepository) + azurerm.InitResourcesMetadata(schemaRepository) for ty, flags := range testcases { t.Run(ty, func(tt *testing.T) { diff --git a/pkg/resource/factory.go b/pkg/resource/factory.go index 85ad4f0b..989a1e1c 100644 --- a/pkg/resource/factory.go +++ b/pkg/resource/factory.go @@ -1,16 +1,18 @@ package resource -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" +) type ResourceFactory interface { CreateAbstractResource(ty, id string, data map[string]interface{}) *resource.Resource } type DriftctlResourceFactory struct { - resourceSchemaRepository resource.SchemaRepositoryInterface + resourceSchemaRepository SchemaRepositoryInterface } -func NewDriftctlResourceFactory(resourceSchemaRepository resource.SchemaRepositoryInterface) *DriftctlResourceFactory { +func NewDriftctlResourceFactory(resourceSchemaRepository SchemaRepositoryInterface) *DriftctlResourceFactory { return &DriftctlResourceFactory{ resourceSchemaRepository: resourceSchemaRepository, } @@ -28,7 +30,7 @@ func (r *DriftctlResourceFactory) CreateAbstractResource(ty, id string, data map Sch: schema, } - schema, exist := r.resourceSchemaRepository.(*resource.SchemaRepository).GetSchema(ty) + schema, exist := r.resourceSchemaRepository.GetSchema(ty) if exist && schema.NormalizeFunc != nil { schema.NormalizeFunc(&res) } diff --git a/pkg/resource/github/github_branch_protection.go b/pkg/resource/github/github_branch_protection.go index 0a4d87fa..f20e7e8b 100644 --- a/pkg/resource/github/github_branch_protection.go +++ b/pkg/resource/github/github_branch_protection.go @@ -2,13 +2,13 @@ package github import ( "encoding/base64" - "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GithubBranchProtectionResourceType = "github_branch_protection" -func initGithubBranchProtectionMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGithubBranchProtectionMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GithubBranchProtectionResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"repository_id"}) // Terraform provider is always returning nil diff --git a/pkg/resource/github/github_membership.go b/pkg/resource/github/github_membership.go index e41974b7..aca43a56 100644 --- a/pkg/resource/github/github_membership.go +++ b/pkg/resource/github/github_membership.go @@ -2,11 +2,12 @@ package github import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GithubMembershipResourceType = "github_membership" -func initGithubMembershipMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGithubMembershipMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GithubMembershipResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"etag"}) diff --git a/pkg/resource/github/github_repository.go b/pkg/resource/github/github_repository.go index c399b374..a5296ff2 100644 --- a/pkg/resource/github/github_repository.go +++ b/pkg/resource/github/github_repository.go @@ -2,11 +2,12 @@ package github import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GithubRepositoryResourceType = "github_repository" -func initGithubRepositoryMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGithubRepositoryMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GithubRepositoryResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"auto_init"}) diff --git a/pkg/resource/github/github_team.go b/pkg/resource/github/github_team.go index ececcc69..9bff4ef7 100644 --- a/pkg/resource/github/github_team.go +++ b/pkg/resource/github/github_team.go @@ -2,11 +2,12 @@ package github import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GithubTeamResourceType = "github_team" -func initGithubTeamMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGithubTeamMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GithubTeamResourceType, func(res *resource.Resource) { val := res.Attrs if defaultMaintainer, exist := val.Get("create_default_maintainer"); !exist || defaultMaintainer == nil { diff --git a/pkg/resource/github/github_team_membership.go b/pkg/resource/github/github_team_membership.go index fbc32ae2..8b388908 100644 --- a/pkg/resource/github/github_team_membership.go +++ b/pkg/resource/github/github_team_membership.go @@ -2,11 +2,12 @@ package github import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GithubTeamMembershipResourceType = "github_team_membership" -func initGithubTeamMembershipMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGithubTeamMembershipMetaData(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GithubTeamMembershipResourceType, func(res *resource.Resource) { val := res.Attrs val.SafeDelete([]string{"etag"}) diff --git a/pkg/resource/github/metadata_test.go b/pkg/resource/github/metadata_test.go index fd0977d8..34150fdc 100644 --- a/pkg/resource/github/metadata_test.go +++ b/pkg/resource/github/metadata_test.go @@ -1,24 +1,25 @@ -package github +package github_test import ( "testing" "github.com/snyk/driftctl/enumeration/resource" + "github.com/snyk/driftctl/pkg/resource/github" testresource "github.com/snyk/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}, + github.GithubBranchProtectionResourceType: {resource.FlagDeepMode}, + github.GithubMembershipResourceType: {resource.FlagDeepMode}, + github.GithubTeamMembershipResourceType: {resource.FlagDeepMode}, + github.GithubRepositoryResourceType: {resource.FlagDeepMode}, + github.GithubTeamResourceType: {resource.FlagDeepMode}, } schemaRepository := testresource.InitFakeSchemaRepository("github", "4.4.0") - InitResourcesMetadata(schemaRepository) + github.InitResourcesMetadata(schemaRepository) for ty, flags := range testcases { t.Run(ty, func(tt *testing.T) { diff --git a/pkg/resource/github/metadatas.go b/pkg/resource/github/metadatas.go index 24622785..ea01b024 100644 --- a/pkg/resource/github/metadatas.go +++ b/pkg/resource/github/metadatas.go @@ -1,6 +1,8 @@ package github -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/pkg/resource" +) func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { initGithubBranchProtectionMetaData(resourceSchemaRepository) diff --git a/pkg/resource/google/google_bigquery_dataset.go b/pkg/resource/google/google_bigquery_dataset.go index c37e423d..4a3bfc5c 100644 --- a/pkg/resource/google/google_bigquery_dataset.go +++ b/pkg/resource/google/google_bigquery_dataset.go @@ -2,11 +2,12 @@ package google import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GoogleBigqueryDatasetResourceType = "google_bigquery_dataset" -func initGoogleBigqueryDatasetMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleBigqueryDatasetMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(GoogleBigqueryDatasetResourceType, func(res *resource.Resource) map[string]string { return map[string]string{ "name": *res.Attrs.GetString("friendly_name"), diff --git a/pkg/resource/google/google_bigquery_table.go b/pkg/resource/google/google_bigquery_table.go index 9c39658d..eae644ee 100644 --- a/pkg/resource/google/google_bigquery_table.go +++ b/pkg/resource/google/google_bigquery_table.go @@ -1,10 +1,13 @@ package google -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const GoogleBigqueryTableResourceType = "google_bigquery_table" -func initGoogleBigqueryTableMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleBigqueryTableMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(GoogleBigqueryTableResourceType, func(res *resource.Resource) map[string]string { return map[string]string{ "name": *res.Attrs.GetString("friendly_name"), diff --git a/pkg/resource/google/google_compute_address.go b/pkg/resource/google/google_compute_address.go index a3773285..b8d328e4 100644 --- a/pkg/resource/google/google_compute_address.go +++ b/pkg/resource/google/google_compute_address.go @@ -1,10 +1,13 @@ package google -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const GoogleComputeAddressResourceType = "google_compute_address" -func initGoogleComputeAddressMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleComputeAddressMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(GoogleComputeAddressResourceType, func(res *resource.Resource) map[string]string { return map[string]string{ "Name": *res.Attributes().GetString("name"), diff --git a/pkg/resource/google/google_compute_disk.go b/pkg/resource/google/google_compute_disk.go index ed40a222..fe0a70c6 100644 --- a/pkg/resource/google/google_compute_disk.go +++ b/pkg/resource/google/google_compute_disk.go @@ -1,10 +1,13 @@ package google -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const GoogleComputeDiskResourceType = "google_compute_disk" -func initGoogleComputeDiskMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleComputeDiskMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(GoogleComputeDiskResourceType, func(res *resource.Resource) map[string]string { return map[string]string{ "Name": *res.Attributes().GetString("name"), diff --git a/pkg/resource/google/google_compute_firewall.go b/pkg/resource/google/google_compute_firewall.go index 7f7d912d..79621aca 100644 --- a/pkg/resource/google/google_compute_firewall.go +++ b/pkg/resource/google/google_compute_firewall.go @@ -2,11 +2,12 @@ package google import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GoogleComputeFirewallResourceType = "google_compute_firewall" -func initGoogleComputeFirewallMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleComputeFirewallMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GoogleComputeFirewallResourceType, func(res *resource.Resource) { res.Attrs.SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/google/google_compute_global_address.go b/pkg/resource/google/google_compute_global_address.go index 1c3af037..e04cb330 100644 --- a/pkg/resource/google/google_compute_global_address.go +++ b/pkg/resource/google/google_compute_global_address.go @@ -1,10 +1,13 @@ package google -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const GoogleComputeGlobalAddressResourceType = "google_compute_global_address" -func initGoogleComputeGlobalAddressMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleComputeGlobalAddressMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(GoogleComputeGlobalAddressResourceType, func(res *resource.Resource) map[string]string { return map[string]string{ "Name": *res.Attributes().GetString("name"), diff --git a/pkg/resource/google/google_compute_health_check.go b/pkg/resource/google/google_compute_health_check.go index c33b8173..598cd379 100644 --- a/pkg/resource/google/google_compute_health_check.go +++ b/pkg/resource/google/google_compute_health_check.go @@ -1,10 +1,13 @@ package google -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const GoogleComputeHealthCheckResourceType = "google_compute_health_check" -func initGoogleComputeHealthCheckMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleComputeHealthCheckMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(GoogleComputeHealthCheckResourceType, func(res *resource.Resource) map[string]string { return map[string]string{ "Name": *res.Attributes().GetString("name"), diff --git a/pkg/resource/google/google_compute_image.go b/pkg/resource/google/google_compute_image.go index f52788da..6159c918 100644 --- a/pkg/resource/google/google_compute_image.go +++ b/pkg/resource/google/google_compute_image.go @@ -1,10 +1,13 @@ package google -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const GoogleComputeImageResourceType = "google_compute_image" -func initGoogleComputeImageMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleComputeImageMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(GoogleComputeImageResourceType, func(res *resource.Resource) map[string]string { return map[string]string{ "Name": *res.Attributes().GetString("name"), diff --git a/pkg/resource/google/google_compute_instance_group.go b/pkg/resource/google/google_compute_instance_group.go index 2d5c288e..fd43bff1 100644 --- a/pkg/resource/google/google_compute_instance_group.go +++ b/pkg/resource/google/google_compute_instance_group.go @@ -2,11 +2,12 @@ package google import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GoogleComputeInstanceGroupResourceType = "google_compute_instance_group" -func initGoogleComputeInstanceGroupMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleComputeInstanceGroupMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GoogleComputeInstanceGroupResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) }) diff --git a/pkg/resource/google/google_compute_instance_group_manager.go b/pkg/resource/google/google_compute_instance_group_manager.go index 35ab1fbb..403d5c23 100644 --- a/pkg/resource/google/google_compute_instance_group_manager.go +++ b/pkg/resource/google/google_compute_instance_group_manager.go @@ -1,10 +1,13 @@ package google -import "github.com/snyk/driftctl/enumeration/resource" +import ( + "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" +) const GoogleComputeInstanceGroupManagerResourceType = "google_compute_instance_group_manager" -func initComputeInstanceGroupManagerMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initComputeInstanceGroupManagerMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetHumanReadableAttributesFunc(GoogleComputeInstanceGroupManagerResourceType, func(res *resource.Resource) map[string]string { attrs := make(map[string]string) if v := res.Attributes().GetString("name"); v != nil && *v != "" { diff --git a/pkg/resource/google/google_compute_network.go b/pkg/resource/google/google_compute_network.go index 0032f595..d8fd65a4 100644 --- a/pkg/resource/google/google_compute_network.go +++ b/pkg/resource/google/google_compute_network.go @@ -2,11 +2,12 @@ package google import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GoogleComputeNetworkResourceType = "google_compute_network" -func initGoogleComputeNetworkMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleComputeNetworkMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GoogleComputeNetworkResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) res.Attributes().SafeDelete([]string{"self_link"}) diff --git a/pkg/resource/google/google_compute_subnetwork.go b/pkg/resource/google/google_compute_subnetwork.go index 89b9d395..2ef02343 100644 --- a/pkg/resource/google/google_compute_subnetwork.go +++ b/pkg/resource/google/google_compute_subnetwork.go @@ -2,11 +2,12 @@ package google import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GoogleComputeSubnetworkResourceType = "google_compute_subnetwork" -func initGoogleComputeSubnetworkMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleComputeSubnetworkMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GoogleComputeSubnetworkResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"timeouts"}) res.Attributes().SafeDelete([]string{"self_link"}) diff --git a/pkg/resource/google/google_project_iam_member.go b/pkg/resource/google/google_project_iam_member.go index f3b06bf2..9a5866e4 100644 --- a/pkg/resource/google/google_project_iam_member.go +++ b/pkg/resource/google/google_project_iam_member.go @@ -2,11 +2,12 @@ package google import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GoogleProjectIamMemberResourceType = "google_project_iam_member" -func initGoogleProjectIAMMemberMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleProjectIAMMemberMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GoogleProjectIamMemberResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"force_destroy"}) res.Attributes().SafeDelete([]string{"etag"}) diff --git a/pkg/resource/google/google_storage_bucket.go b/pkg/resource/google/google_storage_bucket.go index 9ce508f1..1961d935 100644 --- a/pkg/resource/google/google_storage_bucket.go +++ b/pkg/resource/google/google_storage_bucket.go @@ -2,11 +2,12 @@ package google import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GoogleStorageBucketResourceType = "google_storage_bucket" -func initGoogleStorageBucketMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleStorageBucketMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GoogleStorageBucketResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"force_destroy"}) }) diff --git a/pkg/resource/google/google_storage_bucket_iam_member.go b/pkg/resource/google/google_storage_bucket_iam_member.go index a33c26fc..247f81c7 100644 --- a/pkg/resource/google/google_storage_bucket_iam_member.go +++ b/pkg/resource/google/google_storage_bucket_iam_member.go @@ -2,11 +2,12 @@ package google import ( "github.com/snyk/driftctl/enumeration/resource" + dctlresource "github.com/snyk/driftctl/pkg/resource" ) const GoogleStorageBucketIamMemberResourceType = "google_storage_bucket_iam_member" -func initGoogleStorageBucketIamBMemberMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { +func initGoogleStorageBucketIamBMemberMetadata(resourceSchemaRepository dctlresource.SchemaRepositoryInterface) { resourceSchemaRepository.SetNormalizeFunc(GoogleStorageBucketIamMemberResourceType, func(res *resource.Resource) { res.Attributes().SafeDelete([]string{"force_destroy"}) res.Attributes().SafeDelete([]string{"etag"}) diff --git a/pkg/resource/google/metadata_test.go b/pkg/resource/google/metadata_test.go index 7181e212..602c247c 100644 --- a/pkg/resource/google/metadata_test.go +++ b/pkg/resource/google/metadata_test.go @@ -1,42 +1,43 @@ -package google +package google_test import ( "testing" "github.com/snyk/driftctl/enumeration/resource" + "github.com/snyk/driftctl/pkg/resource/google" testresource "github.com/snyk/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: {}, - GoogleComputeDiskResourceType: {}, - GoogleBigTableInstanceResourceType: {}, - GoogleComputeGlobalAddressResourceType: {}, - GoogleCloudRunServiceResourceType: {}, - GoogleComputeNodeGroupResourceType: {}, - GoogleComputeForwardingRuleResourceType: {}, - GoogleComputeInstanceGroupManagerResourceType: {}, - GoogleComputeGlobalForwardingRuleResourceType: {}, + google.GoogleBigqueryDatasetResourceType: {}, + google.GoogleComputeFirewallResourceType: {resource.FlagDeepMode}, + google.GoogleComputeInstanceResourceType: {}, + google.GoogleComputeInstanceGroupResourceType: {resource.FlagDeepMode}, + google.GoogleComputeNetworkResourceType: {resource.FlagDeepMode}, + google.GoogleComputeRouterResourceType: {}, + google.GoogleDNSManagedZoneResourceType: {}, + google.GoogleProjectIamBindingResourceType: {}, + google.GoogleProjectIamMemberResourceType: {resource.FlagDeepMode}, + google.GoogleProjectIamPolicyResourceType: {}, + google.GoogleStorageBucketResourceType: {resource.FlagDeepMode}, + google.GoogleStorageBucketIamBindingResourceType: {}, + google.GoogleStorageBucketIamMemberResourceType: {resource.FlagDeepMode}, + google.GoogleStorageBucketIamPolicyResourceType: {}, + google.GoogleBigqueryTableResourceType: {}, + google.GoogleComputeDiskResourceType: {}, + google.GoogleBigTableInstanceResourceType: {}, + google.GoogleComputeGlobalAddressResourceType: {}, + google.GoogleCloudRunServiceResourceType: {}, + google.GoogleComputeNodeGroupResourceType: {}, + google.GoogleComputeForwardingRuleResourceType: {}, + google.GoogleComputeInstanceGroupManagerResourceType: {}, + google.GoogleComputeGlobalForwardingRuleResourceType: {}, } schemaRepository := testresource.InitFakeSchemaRepository("google", "3.78.0") - InitResourcesMetadata(schemaRepository) + google.InitResourcesMetadata(schemaRepository) for ty, flags := range testcases { t.Run(ty, func(tt *testing.T) { diff --git a/pkg/resource/google/metadatas.go b/pkg/resource/google/metadatas.go index 0666ba74..72c446ee 100644 --- a/pkg/resource/google/metadatas.go +++ b/pkg/resource/google/metadatas.go @@ -1,7 +1,7 @@ package google import ( - "github.com/snyk/driftctl/enumeration/resource" + "github.com/snyk/driftctl/pkg/resource" ) func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) { diff --git a/pkg/resource/schemas.go b/pkg/resource/schemas.go new file mode 100644 index 00000000..48c20b27 --- /dev/null +++ b/pkg/resource/schemas.go @@ -0,0 +1,12 @@ +package resource + +import "github.com/snyk/driftctl/enumeration/resource" + +type SchemaRepositoryInterface interface { + GetSchema(resourceType string) (*resource.Schema, bool) + SetFlags(typ string, flags ...resource.Flags) + UpdateSchema(typ string, schemasMutators map[string]func(attributeSchema *resource.AttributeSchema)) + SetNormalizeFunc(typ string, normalizeFunc func(res *resource.Resource)) + SetHumanReadableAttributesFunc(typ string, humanReadableAttributesFunc func(res *resource.Resource) map[string]string) + SetDiscriminantFunc(string, func(*resource.Resource, *resource.Resource) bool) +} diff --git a/pkg/resource/schemas/repository.go b/pkg/resource/schemas/repository.go new file mode 100644 index 00000000..fe09f15b --- /dev/null +++ b/pkg/resource/schemas/repository.go @@ -0,0 +1,134 @@ +package schemas + +import ( + "strings" + + "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform/configs/configschema" + "github.com/hashicorp/terraform/providers" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "github.com/snyk/driftctl/enumeration/resource" + "github.com/snyk/driftctl/pkg/resource/aws" + "github.com/snyk/driftctl/pkg/resource/azurerm" + "github.com/snyk/driftctl/pkg/resource/github" + "github.com/snyk/driftctl/pkg/resource/google" +) + +type SchemaRepository struct { + schemas map[string]*resource.Schema +} + +func NewSchemaRepository() *SchemaRepository { + return &SchemaRepository{ + schemas: make(map[string]*resource.Schema), + } +} + +func (r *SchemaRepository) GetSchema(resourceType string) (*resource.Schema, bool) { + schema, exist := r.schemas[resourceType] + return schema, exist +} + +func (r *SchemaRepository) fetchNestedBlocks(root string, metadata map[string]resource.AttributeSchema, block map[string]*configschema.NestedBlock) { + for s, nestedBlock := range block { + path := s + if root != "" { + path = strings.Join([]string{root, s}, ".") + } + for s2, attr := range nestedBlock.Attributes { + nestedPath := strings.Join([]string{path, s2}, ".") + metadata[nestedPath] = resource.AttributeSchema{ + ConfigSchema: *attr, + } + } + r.fetchNestedBlocks(path, metadata, nestedBlock.BlockTypes) + } +} + +func (r *SchemaRepository) Init(providerName, providerVersion string, schema map[string]providers.Schema) error { + v, err := version.NewVersion(providerVersion) + if err != nil { + return err + } + for typ, sch := range schema { + attributeMetas := map[string]resource.AttributeSchema{} + for s, attribute := range sch.Block.Attributes { + attributeMetas[s] = resource.AttributeSchema{ + ConfigSchema: *attribute, + } + } + + r.fetchNestedBlocks("", attributeMetas, sch.Block.BlockTypes) + + r.schemas[typ] = &resource.Schema{ + ProviderVersion: v, + SchemaVersion: sch.Version, + Attributes: attributeMetas, + } + } + switch providerName { + case "aws": + aws.InitResourcesMetadata(r) + case "github": + github.InitResourcesMetadata(r) + case "google": + google.InitResourcesMetadata(r) + case "azurerm": + azurerm.InitResourcesMetadata(r) + default: + return errors.Errorf("unsupported remote '%s'", providerName) + } + return nil +} + +func (r SchemaRepository) SetFlags(typ string, flags ...resource.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 *resource.AttributeSchema)) { + for s, f := range schemasMutators { + metadata, exist := r.GetSchema(typ) + if !exist { + logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to set metadata, no schema found") + return + } + m := (*metadata).Attributes[s] + f(&m) + (*metadata).Attributes[s] = m + } +} + +func (r *SchemaRepository) SetNormalizeFunc(typ string, normalizeFunc func(res *resource.Resource)) { + metadata, exist := r.GetSchema(typ) + if !exist { + logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to set normalize func, no schema found") + return + } + (*metadata).NormalizeFunc = normalizeFunc +} + +func (r *SchemaRepository) SetHumanReadableAttributesFunc(typ string, humanReadableAttributesFunc func(res *resource.Resource) map[string]string) { + metadata, exist := r.GetSchema(typ) + if !exist { + logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to add human readable attributes, no schema found") + return + } + (*metadata).HumanReadableAttributesFunc = humanReadableAttributesFunc +} + +func (r *SchemaRepository) SetDiscriminantFunc(typ string, fn func(self, res *resource.Resource) bool) { + metadata, exist := r.GetSchema(typ) + if !exist { + logrus.WithFields(logrus.Fields{"type": typ}).Warning("Unable to set discriminant function, no schema found") + return + } + (*metadata).DiscriminantFunc = fn +} diff --git a/test/resource/resource.go b/test/resource/resource.go index f720d392..84a8492f 100644 --- a/test/resource/resource.go +++ b/test/resource/resource.go @@ -1,22 +1,23 @@ -package resource +package resource_test import ( "github.com/hashicorp/terraform/providers" - "github.com/snyk/driftctl/enumeration/resource" - "github.com/snyk/driftctl/test/schemas" + "github.com/snyk/driftctl/pkg/resource" + "github.com/snyk/driftctl/pkg/resource/schemas" + testschemas "github.com/snyk/driftctl/test/schemas" ) func InitFakeSchemaRepository(provider, version string) resource.SchemaRepositoryInterface { - repo := resource.NewSchemaRepository() + repo := schemas.NewSchemaRepository() schema := make(map[string]providers.Schema) if provider != "" { - s, err := schemas.ReadTestSchema(provider, version) + s, err := testschemas.ReadTestSchema(provider, version) if err != nil { // TODO HANDLER ERROR PROPERLY panic(err) } schema = s } - _ = repo.Init("Fake", "1.0.0", schema) + _ = repo.Init(provider, version, schema) return repo }