From edd741bab0514d3f9672468220e2e046984921c3 Mon Sep 17 00:00:00 2001 From: Matt Bush Date: Mon, 29 Jul 2024 10:54:52 -0700 Subject: [PATCH] Rename FormattedIdentifer external name functions Signed-off-by: Matt Bush --- config/externalname.go | 123 ++++++++++++++++---------------- config/externalnamenottested.go | 38 +++++----- 2 files changed, 80 insertions(+), 81 deletions(-) diff --git a/config/externalname.go b/config/externalname.go index 2b96cd763d..28de23d0b6 100644 --- a/config/externalname.go +++ b/config/externalname.go @@ -163,21 +163,21 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // API Gateway documentation_parts can be imported using REST-API-ID/DOC-PART-ID "aws_api_gateway_documentation_part": config.IdentifierFromProvider, // API Gateway documentation versions can be imported using REST-API-ID/VERSION - "aws_api_gateway_documentation_version": FormattedIdentifierFromProvider("/", "rest_api_id", "version"), + "aws_api_gateway_documentation_version": FormattedIdentifierFromParametersNoIdentifierFields("/", "rest_api_id", "version"), // API Gateway domain names can be imported using their name "aws_api_gateway_domain_name": config.IdentifierFromProvider, // aws_api_gateway_gateway_response can be imported using REST-API-ID/RESPONSE-TYPE - "aws_api_gateway_gateway_response": FormattedIdentifierFromProvider("/", "rest_api_id", "response_type"), + "aws_api_gateway_gateway_response": FormattedIdentifierFromParametersNoIdentifierFields("/", "rest_api_id", "response_type"), // aws_api_gateway_integration can be imported using REST-API-ID/RESOURCE-ID/HTTP-METHOD - "aws_api_gateway_integration": FormattedIdentifierFromProvider("/", "rest_api_id", "resource_id", "http_method"), + "aws_api_gateway_integration": FormattedIdentifierFromParametersNoIdentifierFields("/", "rest_api_id", "resource_id", "http_method"), // aws_api_gateway_integration_response can be imported using REST-API-ID/RESOURCE-ID/HTTP-METHOD/STATUS-CODE - "aws_api_gateway_integration_response": FormattedIdentifierFromProvider("/", "rest_api_id", "resource_id", "http_method", "status_code"), + "aws_api_gateway_integration_response": FormattedIdentifierFromParametersNoIdentifierFields("/", "rest_api_id", "resource_id", "http_method", "status_code"), // aws_api_gateway_method can be imported using REST-API-ID/RESOURCE-ID/HTTP-METHOD - "aws_api_gateway_method": FormattedIdentifierFromProvider("/", "rest_api_id", "resource_id", "http_method"), + "aws_api_gateway_method": FormattedIdentifierFromParametersNoIdentifierFields("/", "rest_api_id", "resource_id", "http_method"), // aws_api_gateway_method_response can be imported using REST-API-ID/RESOURCE-ID/HTTP-METHOD/STATUS-CODE - "aws_api_gateway_method_response": FormattedIdentifierFromProvider("/", "rest_api_id", "resource_id", "http_method", "status_code"), + "aws_api_gateway_method_response": FormattedIdentifierFromParametersNoIdentifierFields("/", "rest_api_id", "resource_id", "http_method", "status_code"), // aws_api_gateway_method_settings can be imported using REST-API-ID/STAGE-NAME/METHOD-PATH - "aws_api_gateway_method_settings": FormattedIdentifierFromProvider("/", "rest_api_id", "stage_name", "method_path"), + "aws_api_gateway_method_settings": FormattedIdentifierFromParametersNoIdentifierFields("/", "rest_api_id", "stage_name", "method_path"), // aws_api_gateway_model can be imported using REST-API-ID/NAME "aws_api_gateway_model": config.IdentifierFromProvider, // aws_api_gateway_request_validator can be imported using REST-API-ID/REQUEST-VALIDATOR-ID @@ -187,9 +187,9 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // aws_api_gateway_rest_api can be imported by using the REST API ID "aws_api_gateway_rest_api": config.IdentifierFromProvider, // aws_api_gateway_rest_api_policy can be imported by using the REST API ID - "aws_api_gateway_rest_api_policy": FormattedIdentifierFromProvider("", "rest_api_id"), + "aws_api_gateway_rest_api_policy": FormattedIdentifierFromParametersNoIdentifierFields("", "rest_api_id"), // aws_api_gateway_stage can be imported using REST-API-ID/STAGE-NAME - "aws_api_gateway_stage": FormattedIdentifierFromProvider("/", "rest_api_id", "stage_name"), + "aws_api_gateway_stage": FormattedIdentifierFromParametersNoIdentifierFields("/", "rest_api_id", "stage_name"), // AWS API Gateway Usage Plan can be imported using the id "aws_api_gateway_usage_plan": config.IdentifierFromProvider, // AWS API Gateway Usage Plan Key can be imported using the USAGE-PLAN-ID/USAGE-PLAN-KEY-ID @@ -517,11 +517,11 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // Imported using name "aws_cloudwatch_event_connection": config.NameAsIdentifier, // Imported using event_bus_name/statement_id - "aws_cloudwatch_event_permission": FormattedIdentifierFromProvider("/", "event_bus_name", "statement_id"), + "aws_cloudwatch_event_permission": FormattedIdentifierFromParametersNoIdentifierFields("/", "event_bus_name", "statement_id"), // Imported using event_bus_name/rule_name "aws_cloudwatch_event_rule": FormattedIdentifierUserDefinedNameLast("name", "/", "event_bus_name"), // Imported using event_bus_name/rule_name/target_id - "aws_cloudwatch_event_target": FormattedIdentifierFromProvider("/", "event_bus_name", "rule", "target_id"), + "aws_cloudwatch_event_target": FormattedIdentifierFromParametersNoIdentifierFields("/", "event_bus_name", "rule", "target_id"), // cloudwatchlogs // @@ -889,7 +889,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // Prefix Lists can be imported using the id "aws_ec2_managed_prefix_list": config.IdentifierFromProvider, // Prefix List Entries can be imported using the prefix_list_id and cidr separated by a , - "aws_ec2_managed_prefix_list_entry": FormattedIdentifierFromProvider(",", "prefix_list_id", "cidr"), + "aws_ec2_managed_prefix_list_entry": FormattedIdentifierFromParametersNoIdentifierFields(",", "prefix_list_id", "cidr"), // Network Insights Paths can be imported using the id "aws_ec2_network_insights_path": config.IdentifierFromProvider, // Serial console access state can be imported @@ -923,21 +923,21 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // aws_ec2_transit_gateway_policy_table can be imported by using the EC2 Transit Gateway Policy Table identifier "aws_ec2_transit_gateway_policy_table": config.IdentifierFromProvider, // aws_ec2_transit_gateway_prefix_list_reference can be imported by using the EC2 Transit Gateway Route Table identifier and EC2 Prefix List identifier, separated by an underscore (_ - "aws_ec2_transit_gateway_prefix_list_reference": FormattedIdentifierFromProvider("_", "transit_gateway_route_table_id", "prefix_list_id"), + "aws_ec2_transit_gateway_prefix_list_reference": FormattedIdentifierFromParametersNoIdentifierFields("_", "transit_gateway_route_table_id", "prefix_list_id"), // Imported by using the EC2 Transit Gateway Route Table, an underscore, // and the destination CIDR: tgw-rtb-12345678_0.0.0.0/0 - "aws_ec2_transit_gateway_route": FormattedIdentifierFromProvider("_", "transit_gateway_route_table_id", "destination_cidr_block"), + "aws_ec2_transit_gateway_route": FormattedIdentifierFromParametersNoIdentifierFields("_", "transit_gateway_route_table_id", "destination_cidr_block"), // Imported by using the EC2 Transit Gateway Route Table identifier: // tgw-rtb-12345678 "aws_ec2_transit_gateway_route_table": config.IdentifierFromProvider, // Imported by using the EC2 Transit Gateway Route Table identifier, an // underscore, and the EC2 Transit Gateway Attachment identifier, e.g., // tgw-rtb-12345678_tgw-attach-87654321 - "aws_ec2_transit_gateway_route_table_association": FormattedIdentifierFromProvider("_", "transit_gateway_route_table_id", "transit_gateway_attachment_id"), + "aws_ec2_transit_gateway_route_table_association": FormattedIdentifierFromParametersNoIdentifierFields("_", "transit_gateway_route_table_id", "transit_gateway_attachment_id"), // Imported by using the EC2 Transit Gateway Route Table identifier, an // underscore, and the EC2 Transit Gateway Attachment identifier: // tgw-rtb-12345678_tgw-attach-87654321 - "aws_ec2_transit_gateway_route_table_propagation": FormattedIdentifierFromProvider("_", "transit_gateway_route_table_id", "transit_gateway_attachment_id"), + "aws_ec2_transit_gateway_route_table_propagation": FormattedIdentifierFromParametersNoIdentifierFields("_", "transit_gateway_route_table_id", "transit_gateway_attachment_id"), // Imported by using the EC2 Transit Gateway Attachment identifier: // tgw-attach-12345678 "aws_ec2_transit_gateway_vpc_attachment": config.IdentifierFromProvider, @@ -1017,9 +1017,9 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // VPC Endpoint connection notifications can be imported using the VPC endpoint connection notification id "aws_vpc_endpoint_connection_notification": config.IdentifierFromProvider, // VPC Endpoint Route Table Associations can be imported using vpc_endpoint_id together with route_table_id - "aws_vpc_endpoint_route_table_association": FormattedIdentifierFromProvider("/", "vpc_endpoint_id", "route_table_id"), + "aws_vpc_endpoint_route_table_association": FormattedIdentifierFromParametersNoIdentifierFields("/", "vpc_endpoint_id", "route_table_id"), // VPC Endpoint Subnet Associations can be imported using vpc_endpoint_id together with subnet_id - "aws_vpc_endpoint_subnet_association": FormattedIdentifierFromProvider("/", "vpc_endpoint_id", "subnet_id"), + "aws_vpc_endpoint_subnet_association": FormattedIdentifierFromParametersNoIdentifierFields("/", "vpc_endpoint_id", "subnet_id"), // VPC Endpoint security group Associations can be imported using vpc_endpoint_id together with security_group_id "aws_vpc_endpoint_security_group_association": config.IdentifierFromProvider, // IPAMs can be imported using the ipam id @@ -1111,12 +1111,12 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // eks // // import EKS access entry using the cluster_name and principal_arn separated by a colon (:). - "aws_eks_access_entry": FormattedIdentifierFromProviderWithIdentifierFields(":", "cluster_name", "principal_arn"), + "aws_eks_access_entry": FormattedIdentifierFromParameters(":", "cluster_name", "principal_arn"), // import EKS access entry using the cluster_name principal_arn and policy_arn separated by a (#) which the tf provider docs incorrectly describe as a colon. - "aws_eks_access_policy_association": FormattedIdentifierFromProviderWithIdentifierFields("#", "cluster_name", "principal_arn", "policy_arn"), + "aws_eks_access_policy_association": FormattedIdentifierFromParameters("#", "cluster_name", "principal_arn", "policy_arn"), // "aws_eks_addon": config.TemplatedStringAsIdentifier("addon_name", "{{ .parameters.cluster_name }}:{{ .external_name }}"), // my_cluster:my_eks_addon - "aws_eks_addon": FormattedIdentifierFromProvider(":", "cluster_name", "addon_name"), + "aws_eks_addon": FormattedIdentifierFromParametersNoIdentifierFields(":", "cluster_name", "addon_name"), // import EKS cluster using the name. "aws_eks_cluster": config.NameAsIdentifier, // my_cluster:my_fargate_profile @@ -1269,7 +1269,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // Glacier Vaults can be imported using the name "aws_glacier_vault": config.NameAsIdentifier, // Glacier Vault Locks can be imported using the Glacier Vault name - "aws_glacier_vault_lock": FormattedIdentifierFromProvider("", "vault_name"), + "aws_glacier_vault_lock": FormattedIdentifierFromParametersNoIdentifierFields("", "vault_name"), // globalaccelerator // @@ -1318,12 +1318,12 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // No import "aws_grafana_role_association": config.IdentifierFromProvider, // Grafana Workspace SAML configuration can be imported using the workspace's id - "aws_grafana_workspace_saml_configuration": FormattedIdentifierFromProvider("", "workspace_id"), + "aws_grafana_workspace_saml_configuration": FormattedIdentifierFromParametersNoIdentifierFields("", "workspace_id"), // No import // TODO: For now API is not normalized. While testing resource we can check the actual ID and normalize the API. "aws_grafana_workspace_api_key": config.IdentifierFromProvider, // Grafana workspace license association can be imported using the workspace's id - "aws_grafana_license_association": FormattedIdentifierFromProvider("", "workspace_id"), + "aws_grafana_license_association": FormattedIdentifierFromParametersNoIdentifierFields("", "workspace_id"), // guardduty // @@ -1473,7 +1473,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ "aws_iot_thing_group": config.NameAsIdentifier, // IoT Thing Group Membership can be imported using the thing group name and thing name // thing_group_name/thing_name - "aws_iot_thing_group_membership": FormattedIdentifierFromProvider("/", "thing_group_name", "thing_name"), + "aws_iot_thing_group_membership": FormattedIdentifierFromParametersNoIdentifierFields("/", "thing_group_name", "thing_name"), // No import // TODO: For now API is not normalized. While testing resource we can check the actual ID and normalize the API. "aws_iot_thing_principal_attachment": config.IdentifierFromProvider, @@ -1543,7 +1543,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ "aws_keyspaces_keyspace": config.NameAsIdentifier, // Use the keyspace_name and table_name separated by / to import a table // my_keyspace/my_table - "aws_keyspaces_table": FormattedIdentifierFromProvider("/", "keyspace_name", "table_name"), + "aws_keyspaces_table": FormattedIdentifierFromParametersNoIdentifierFields("/", "keyspace_name", "table_name"), // kinesis // @@ -1640,7 +1640,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // licensemanager // // License configurations can be imported in the form resource_arn,license_configuration_arn - "aws_licensemanager_association": FormattedIdentifierFromProvider(",", "resource_arn", "license_configuration_arn"), + "aws_licensemanager_association": FormattedIdentifierFromParametersNoIdentifierFields(",", "resource_arn", "license_configuration_arn"), // License configurations can be imported using the id "aws_licensemanager_license_configuration": config.IdentifierFromProvider, @@ -1712,9 +1712,9 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // aws_macie2_findings_filter can be imported using the id "aws_macie2_findings_filter": config.IdentifierFromProvider, // aws_macie2_invitation_accepter can be imported using the admin account ID - "aws_macie2_invitation_accepter": FormattedIdentifierFromProvider("", "administrator_account_id"), + "aws_macie2_invitation_accepter": FormattedIdentifierFromParametersNoIdentifierFields("", "administrator_account_id"), // aws_macie2_member can be imported using the account ID of the member account - "aws_macie2_member": FormattedIdentifierFromProvider("", "account_id"), + "aws_macie2_member": FormattedIdentifierFromParametersNoIdentifierFields("", "account_id"), // mediaconvert // @@ -1742,7 +1742,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // MediaStore Container can be imported using the MediaStore Container Name "aws_media_store_container": config.NameAsIdentifier, // MediaStore Container Policy can be imported using the MediaStore Container Name - "aws_media_store_container_policy": FormattedIdentifierFromProvider("", "container_name"), + "aws_media_store_container_policy": FormattedIdentifierFromParametersNoIdentifierFields("", "container_name"), // memorydb // @@ -1910,7 +1910,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ "aws_organizations_account": config.IdentifierFromProvider, // imported by using the account ID and its service principal: // 123456789012/config.amazonaws.com - "aws_organizations_delegated_administrator": FormattedIdentifierFromProvider("/", "account_id", "service_principal"), + "aws_organizations_delegated_administrator": FormattedIdentifierFromParametersNoIdentifierFields("/", "account_id", "service_principal"), // imported by using the id, which is a Cloud provider-generated string: // o-1234567 "aws_organizations_organization": config.IdentifierFromProvider, @@ -1923,14 +1923,14 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ "aws_organizations_policy": config.IdentifierFromProvider, // imported by using the target ID and policy ID // 123456789012:p-12345678 - "aws_organizations_policy_attachment": FormattedIdentifierFromProvider(":", "target_id", "policy_id"), + "aws_organizations_policy_attachment": FormattedIdentifierFromParametersNoIdentifierFields(":", "target_id", "policy_id"), // pinpoint // // Pinpoint App can be imported using the application-id "aws_pinpoint_app": config.IdentifierFromProvider, // Pinpoint SMS Channel can be imported using the application-id - "aws_pinpoint_sms_channel": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_sms_channel": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // pipes // @@ -1949,7 +1949,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // // QuickSight Group can be imported using the aws account id, namespace and group name separated by / // 123456789123/default/tf-example - "aws_quicksight_group": FormattedIdentifierFromProvider("/", "aws_account_id", "namespace", "group_name"), + "aws_quicksight_group": FormattedIdentifierFromParametersNoIdentifierFields("/", "aws_account_id", "namespace", "group_name"), // No import // TODO: For now API is not normalized. While testing resource we can check the actual ID and normalize the API. "aws_quicksight_user": config.IdentifierFromProvider, @@ -1958,10 +1958,10 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // // RAM Principal Associations can be imported using their Resource Share ARN and the principal separated by a comma: // arn:aws:ram:eu-west-1:123456789012:resource-share/73da1ab9-b94a-4ba3-8eb4-45917f7f4b12,123456789012 - "aws_ram_principal_association": FormattedIdentifierFromProvider(",", "resource_share_arn", "principal"), + "aws_ram_principal_association": FormattedIdentifierFromParametersNoIdentifierFields(",", "resource_share_arn", "principal"), // RAM Resource Associations can be imported using their Resource Share ARN and Resource ARN separated by a comma: // arn:aws:ram:eu-west-1:123456789012:resource-share/73da1ab9-b94a-4ba3-8eb4-45917f7f4b12,arn:aws:ec2:eu-west-1:123456789012:subnet/subnet-12345678 - "aws_ram_resource_association": FormattedIdentifierFromProvider(",", "resource_share_arn", "resource_arn"), + "aws_ram_resource_association": FormattedIdentifierFromParametersNoIdentifierFields(",", "resource_share_arn", "resource_arn"), // Resource shares can be imported using the id "aws_ram_resource_share": config.IdentifierFromProvider, // Resource share accepters can be imported using the resource share ARN: @@ -2013,7 +2013,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ "aws_rds_cluster_parameter_group": config.NameAsIdentifier, // aws_rds_cluster_role_association can be imported using the DB Cluster Identifier and IAM Role ARN separated by a comma (,) // $ terraform import aws_rds_cluster_role_association.example my-db-cluster,arn:aws:iam::123456789012:role/my-role - "aws_rds_cluster_role_association": FormattedIdentifierFromProvider(",", "db_cluster_identifier", "role_arn"), + "aws_rds_cluster_role_association": FormattedIdentifierFromParametersNoIdentifierFields(",", "db_cluster_identifier", "role_arn"), // aws_rds_global_cluster can be imported by using the RDS Global Cluster identifie "aws_rds_global_cluster": config.ParameterAsIdentifier("global_cluster_identifier"), @@ -2089,12 +2089,11 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // df579d9a-6396-410e-ac22-e7ad60cf9e7e "aws_route53_traffic_policy_instance": config.IdentifierFromProvider, // Z123456ABCDEFG:vpc-12345678 - "aws_route53_vpc_association_authorization": FormattedIdentifierFromProvider(":", "zone_id", "vpc_id"), + "aws_route53_vpc_association_authorization": FormattedIdentifierFromParametersNoIdentifierFields(":", "zone_id", "vpc_id"), // Z1D633PJN98FT9 "aws_route53_zone": config.IdentifierFromProvider, // Z123456ABCDEFG:vpc-12345678 - // "aws_route53_zone_association": FormattedIdentifierFromProvider(":", "zone_id", "vpc_id"), - "aws_route53_zone_association": FormattedIdentifierFromProvider(":", "zone_id", "vpc_id"), + "aws_route53_zone_association": FormattedIdentifierFromParametersNoIdentifierFields(":", "zone_id", "vpc_id"), // route53recoverycontrolconfig // @@ -2149,21 +2148,21 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // the S3 bucket ACL resource should be imported using the bucket "aws_s3_bucket_acl": config.IdentifierFromProvider, // S3 bucket analytics configurations can be imported using bucket:analytics - "aws_s3_bucket_analytics_configuration": FormattedIdentifierFromProvider(":", "bucket", "name"), + "aws_s3_bucket_analytics_configuration": FormattedIdentifierFromParametersNoIdentifierFields(":", "bucket", "name"), // The S3 bucket CORS configuration resource should be imported using the bucket "aws_s3_bucket_cors_configuration": config.IdentifierFromProvider, // S3 bucket intelligent tiering configurations can be imported using bucket:name // $ terraform import aws_s3_bucket_intelligent_tiering_configuration.my-bucket-entire-bucket my-bucket:EntireBucket - "aws_s3_bucket_intelligent_tiering_configuration": FormattedIdentifierFromProvider(":", "bucket", "name"), + "aws_s3_bucket_intelligent_tiering_configuration": FormattedIdentifierFromParametersNoIdentifierFields(":", "bucket", "name"), // S3 bucket inventory configurations can be imported using bucket:inventory // $ terraform import aws_s3_bucket_inventory.my-bucket-entire-bucket my-bucket:EntireBucket - "aws_s3_bucket_inventory": FormattedIdentifierFromProvider(":", "bucket", "name"), + "aws_s3_bucket_inventory": FormattedIdentifierFromParametersNoIdentifierFields(":", "bucket", "name"), // The S3 bucket lifecycle configuration resource should be imported using the bucket "aws_s3_bucket_lifecycle_configuration": config.IdentifierFromProvider, // The S3 bucket logging resource should be imported using the bucket "aws_s3_bucket_logging": config.IdentifierFromProvider, // S3 bucket metric configurations can be imported using bucket:metric - "aws_s3_bucket_metric": FormattedIdentifierFromProvider(":", "bucket", "name"), + "aws_s3_bucket_metric": FormattedIdentifierFromParametersNoIdentifierFields(":", "bucket", "name"), // S3 bucket notification can be imported using the bucket "aws_s3_bucket_notification": config.IdentifierFromProvider, // Objects can be imported using the id. The id is the bucket name and the key together @@ -2188,7 +2187,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ "aws_s3_bucket_website_configuration": config.IdentifierFromProvider, // Objects can be imported using the id. The id is the bucket name and the key together // $ terraform import aws_s3_object.object some-bucket-name/some/key.txt - "aws_s3_object": FormattedIdentifierFromProvider("/", "bucket", "key"), + "aws_s3_object": FormattedIdentifierFromParametersNoIdentifierFields("/", "bucket", "key"), // No import // TODO: For now API is not normalized. While testing resource we can check the actual ID and normalize the API. "aws_s3_object_copy": config.IdentifierFromProvider, @@ -2284,7 +2283,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // EventBridge schema registries can be imported using the name "aws_schemas_registry": config.NameAsIdentifier, // EventBridge schema can be imported using the name and registry_name - "aws_schemas_schema": FormattedIdentifierFromProvider("/", "name", "registry_name"), + "aws_schemas_schema": FormattedIdentifierFromParametersNoIdentifierFields("/", "name", "registry_name"), // secretsmanager // @@ -2318,13 +2317,13 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // imported using the account ID "aws_securityhub_invite_accepter": config.IdentifierFromProvider, // imported using security hub member account ID - "aws_securityhub_member": FormattedIdentifierFromProvider("", "account_id"), + "aws_securityhub_member": FormattedIdentifierFromParametersNoIdentifierFields("", "account_id"), // imported in the form product_arn,arn: // arn:aws:securityhub:eu-west-1:733251395267:product/alertlogic/althreatmanagement,arn:aws:securityhub:eu-west-1:123456789012:product-subscription/alertlogic/althreatmanagement // looks like it's possible to derive the external-name from // the product_arn argument according to the above example // (by replacing product by product-subscription), which makes this - // a special case of FormattedIdentifierFromProvider + // a special case of FormattedIdentifierFromParametersNoIdentifierFields "aws_securityhub_product_subscription": func() config.ExternalName { e := config.IdentifierFromProvider e.GetIDFn = func(_ context.Context, _ string, parameters map[string]interface{}, _ map[string]interface{}) (string, error) { @@ -2342,7 +2341,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ }(), // imported using the standards subscription ARN: // arn:aws:securityhub:eu-west-1:123456789012:subscription/pci-dss/v/3.2.1 - "aws_securityhub_standards_subscription": FormattedIdentifierFromProvider("", "standards_arn"), + "aws_securityhub_standards_subscription": FormattedIdentifierFromParametersNoIdentifierFields("", "standards_arn"), // serverlessrepo // @@ -2371,7 +2370,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // TODO: looks like we can generated the above id using: // accept_language,principal_arn,portfolio_id // , which lends itself to: - // FormattedIdentifierFromProvider(",", "accept_language", "principal_arn", "portfolio_id") + // FormattedIdentifierFromParametersNoIdentifierFields(",", "accept_language", "principal_arn", "portfolio_id") // However, accept_language is optional. We had better make it required as // the default is provided by Terraform (and we have no means to default // the generated CRD fields as of now) @@ -2384,7 +2383,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // TODO: looks like we can generated the above id using: // accept_language,portfolio_id,product_id // , which lends itself to: - // FormattedIdentifierFromProvider(",", "accept_language", "portfolio_id", "product_id") + // FormattedIdentifierFromParametersNoIdentifierFields(",", "accept_language", "portfolio_id", "product_id") // However, accept_language is optional. We had better make it required as // the default is provided by Terraform (and we have no means to default // the generated CRD fields as of now) @@ -2405,7 +2404,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ "aws_servicecatalog_tag_option": config.IdentifierFromProvider, // imported using the tag option ID and resource ID: // tag-pjtvyakdlyo3m:prod-dnigbtea24ste - "aws_servicecatalog_tag_option_resource_association": FormattedIdentifierFromProvider(":", "tag_option_id", "resource_id"), + "aws_servicecatalog_tag_option_resource_association": FormattedIdentifierFromParametersNoIdentifierFields(":", "tag_option_id", "resource_id"), // servicediscovery // @@ -2422,7 +2421,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ // // aws_servicequotas_service_quota can be imported by using the service code and quota code, separated by a front slash (/) // vpc/L-F678F1CE - "aws_servicequotas_service_quota": FormattedIdentifierFromProvider("/", "service_code", "quota_code"), + "aws_servicequotas_service_quota": FormattedIdentifierFromParametersNoIdentifierFields("/", "service_code", "quota_code"), // ses // @@ -2501,7 +2500,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{ "aws_sns_topic": config.TemplatedStringAsIdentifier("name", "arn:aws:sns:{{ .setup.configuration.region }}:{{ .setup.client_metadata.account_id }}:{{ .external_name }}"), // SNS Topic Policy can be imported using the topic ARN: // arn:aws:sns:us-west-2:0123456789012:my-topic - "aws_sns_topic_policy": FormattedIdentifierFromProvider("", "arn"), + "aws_sns_topic_policy": FormattedIdentifierFromParametersNoIdentifierFields("", "arn"), // SNS Topic Subscriptions can be imported using the subscription arn that // contains a random substring in the end. "aws_sns_topic_subscription": config.IdentifierFromProvider, @@ -2966,8 +2965,8 @@ func getPermissionSetId(tfstate map[string]any) (string, error) { return strings.Split(arn, "/")[2], nil } -// FormattedIdentifierFromProvider is a helper function to construct Terraform -// IDs that use elements from the parameters in a certain string format. +// FormattedIdentifierFromParametersNoIdentifierFields is a helper function to construct Terraform +// IDs that use elements from the parameters joined by some separator string. // It should be used in cases where all information in the ID is gathered from // the spec and not user defined like name. For example, zone_id:vpc_id. // @@ -2975,8 +2974,8 @@ func getPermissionSetId(tfstate map[string]any) (string, error) { // But that would remove them from spec.initProvider, which would be a breaking schema change for existing resources // that we don't have a good way to handle yet. // -// For new resources, prefer using FormattedIdentifierFromProviderWithIdentifierFields instead. -func FormattedIdentifierFromProvider(separator string, keys ...string) config.ExternalName { +// For new resources, prefer using FormattedIdentifierFromParameters instead. +func FormattedIdentifierFromParametersNoIdentifierFields(separator string, keys ...string) config.ExternalName { e := config.IdentifierFromProvider e.GetIDFn = func(_ context.Context, _ string, parameters map[string]interface{}, _ map[string]interface{}) (string, error) { vals := make([]string, len(keys)) @@ -2996,15 +2995,15 @@ func FormattedIdentifierFromProvider(separator string, keys ...string) config.Ex return e } -// FormattedIdentifierFromProviderWithIdentifierFields is a helper function to construct Terraform -// IDs that use elements from the parameters in a certain string format. +// FormattedIdentifierFromParameters is a helper function to construct Terraform +// IDs that use elements from the parameters joined by some separator string. // It should be used in cases where all information in the ID is gathered from // the spec and not user defined like name. For example, zone_id:vpc_id. // This function sets the keys as IdentifierFields, which means that they are always required, even for observe-only // resources. Because the id is constructed exclusively from the keys, omitting them (even if the external name // annotation is set) leaves the provider unable to find the terraform id to use to observe the resource. -func FormattedIdentifierFromProviderWithIdentifierFields(separator string, keys ...string) config.ExternalName { - e := FormattedIdentifierFromProvider(separator, keys...) +func FormattedIdentifierFromParameters(separator string, keys ...string) config.ExternalName { + e := FormattedIdentifierFromParametersNoIdentifierFields(separator, keys...) e.IdentifierFields = append(e.IdentifierFields, keys...) return e } diff --git a/config/externalnamenottested.go b/config/externalnamenottested.go index f68fda432d..fa70351616 100644 --- a/config/externalnamenottested.go +++ b/config/externalnamenottested.go @@ -189,7 +189,7 @@ var ExternalNameNotTestedConfigs = map[string]config.ExternalName{ // securityhub // // imported using the AWS account ID - "aws_securityhub_organization_admin_account": FormattedIdentifierFromProvider("", "admin_account_id"), + "aws_securityhub_organization_admin_account": FormattedIdentifierFromParametersNoIdentifierFields("", "admin_account_id"), // imported using the AWS account ID // no Terraform argument specifies the AWS account ID and // Terraform resource ID is the AWS account ID for the resource @@ -210,7 +210,7 @@ var ExternalNameNotTestedConfigs = map[string]config.ExternalName{ // // imported using the service ID and instance ID: // 0123456789/i-0123 - "aws_service_discovery_instance": FormattedIdentifierFromProvider("/", "service_id", "instance_id"), + "aws_service_discovery_instance": FormattedIdentifierFromParametersNoIdentifierFields("/", "service_id", "instance_id"), // elasticache // @@ -224,7 +224,7 @@ var ExternalNameNotTestedConfigs = map[string]config.ExternalName{ "aws_elasticache_global_replication_group": config.IdentifierFromProvider, // ElastiCache user group associations can be imported using the user_group_id and user_id: // userGoupId1,userId - "aws_elasticache_user_group_association": FormattedIdentifierFromProvider(",", "user_group_id", "user_id"), + "aws_elasticache_user_group_association": FormattedIdentifierFromParametersNoIdentifierFields(",", "user_group_id", "user_id"), // ecs // @@ -241,14 +241,14 @@ var ExternalNameNotTestedConfigs = map[string]config.ExternalName{ // guardduty // // aws_guardduty_invite_accepter can be imported using the member GuardDuty detector ID - "aws_guardduty_invite_accepter": FormattedIdentifierFromProvider("", "detector_id"), + "aws_guardduty_invite_accepter": FormattedIdentifierFromParametersNoIdentifierFields("", "detector_id"), // GuardDuty IPSet can be imported using the primary GuardDuty detector ID and IPSet ID // 00b00fd5aecc0ab60a708659477e9617:123456789012 "aws_guardduty_ipset": config.IdentifierFromProvider, // GuardDuty Organization Admin Account can be imported using the AWS account ID - "aws_guardduty_organization_admin_account": FormattedIdentifierFromProvider("", "admin_account_id"), + "aws_guardduty_organization_admin_account": FormattedIdentifierFromParametersNoIdentifierFields("", "admin_account_id"), // GuardDuty Organization Configurations can be imported using the GuardDuty Detector ID - "aws_guardduty_organization_configuration": FormattedIdentifierFromProvider("", "detector_id"), + "aws_guardduty_organization_configuration": FormattedIdentifierFromParametersNoIdentifierFields("", "detector_id"), // GuardDuty PublishingDestination can be imported using the master GuardDuty detector ID and PublishingDestinationID // a4b86f26fa42e7e7cf0d1c333ea77777:a4b86f27a0e464e4a7e0516d242f1234 "aws_guardduty_publishing_destination": config.IdentifierFromProvider, @@ -284,7 +284,7 @@ var ExternalNameNotTestedConfigs = map[string]config.ExternalName{ // j-123456ABCDEF/ig-15EK4O09RZLNR "aws_emr_instance_group": config.IdentifierFromProvider, // EMR Managed Scaling Policies can be imported via the EMR Cluster identifier - "aws_emr_managed_scaling_policy": FormattedIdentifierFromProvider("", "cluster_id"), + "aws_emr_managed_scaling_policy": FormattedIdentifierFromParametersNoIdentifierFields("", "cluster_id"), // EMR studios can be imported using the id "aws_emr_studio": config.IdentifierFromProvider, // EMR studio session mappings can be imported using the id, e.g., studio-id:identity-type:identity-id @@ -299,7 +299,7 @@ var ExternalNameNotTestedConfigs = map[string]config.ExternalName{ // // Firewall Manager administrator account association can be imported using the account ID // TODO: account_id parameter is not `Required` in TF schema. But we use this field in id construction. So, please mark as required this field while configuration - "aws_fms_admin_account": FormattedIdentifierFromProvider("", "account_id"), + "aws_fms_admin_account": FormattedIdentifierFromParametersNoIdentifierFields("", "account_id"), // Firewall Manager policies can be imported using the policy ID "aws_fms_policy": config.IdentifierFromProvider, @@ -331,32 +331,32 @@ var ExternalNameNotTestedConfigs = map[string]config.ExternalName{ // pinpoint // // Pinpoint ADM Channel can be imported using the application-id - "aws_pinpoint_adm_channel": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_adm_channel": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // Pinpoint APNs Channel can be imported using the application-id - "aws_pinpoint_apns_channel": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_apns_channel": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // Pinpoint APNs Sandbox Channel can be imported using the application-id - "aws_pinpoint_apns_sandbox_channel": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_apns_sandbox_channel": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // Pinpoint APNs VoIP Channel can be imported using the application-id - "aws_pinpoint_apns_voip_channel": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_apns_voip_channel": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // Pinpoint APNs VoIP Sandbox Channel can be imported using the application-id - "aws_pinpoint_apns_voip_sandbox_channel": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_apns_voip_sandbox_channel": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // Pinpoint Baidu Channel can be imported using the application-id - "aws_pinpoint_baidu_channel": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_baidu_channel": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // Pinpoint Email Channel can be imported using the application-id - "aws_pinpoint_email_channel": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_email_channel": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // Pinpoint Event Stream can be imported using the application-id - "aws_pinpoint_event_stream": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_event_stream": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // Pinpoint GCM Channel can be imported using the application-id - "aws_pinpoint_gcm_channel": FormattedIdentifierFromProvider("", "application_id"), + "aws_pinpoint_gcm_channel": FormattedIdentifierFromParametersNoIdentifierFields("", "application_id"), // quicksight // // A QuickSight data source can be imported using the AWS account ID, and data source ID name separated by a slash (/) // 123456789123/my-data-source-id - "aws_quicksight_data_source": FormattedIdentifierFromProvider("/", "aws_account_id", "data_source_id"), + "aws_quicksight_data_source": FormattedIdentifierFromParametersNoIdentifierFields("/", "aws_account_id", "data_source_id"), // QuickSight Group membership can be imported using the AWS account ID, namespace, group name and member name separated by / // 123456789123/default/all-access-users/john_smith - "aws_quicksight_group_membership": FormattedIdentifierFromProvider("/", "aws_account_id", "namespace", "group_name", "member_name"), + "aws_quicksight_group_membership": FormattedIdentifierFromParametersNoIdentifierFields("/", "aws_account_id", "namespace", "group_name", "member_name"), // redshift //