@@ -272,17 +272,17 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{
272272 // API Gateway domain names can be imported using their name
273273 "aws_api_gateway_domain_name" : config .IdentifierFromProvider ,
274274 // aws_api_gateway_gateway_response can be imported using REST-API-ID/RESPONSE-TYPE
275- "aws_api_gateway_gateway_response" : FormattedIdentifierFromProvider ( "/ " , "rest_api_id" , "response_type" ),
275+ "aws_api_gateway_gateway_response" : apiGatewayFormattedIdentifier ( "aggr " , "rest_api_id" , "response_type" ),
276276 // aws_api_gateway_integration can be imported using REST-API-ID/RESOURCE-ID/HTTP-METHOD
277- "aws_api_gateway_integration" : FormattedIdentifierFromProvider ( "/ " , "rest_api_id" , "resource_id" , "http_method" ),
277+ "aws_api_gateway_integration" : apiGatewayFormattedIdentifier ( "agi " , "rest_api_id" , "resource_id" , "http_method" ),
278278 // aws_api_gateway_integration_response can be imported using REST-API-ID/RESOURCE-ID/HTTP-METHOD/STATUS-CODE
279- "aws_api_gateway_integration_response" : FormattedIdentifierFromProvider ( "/ " , "rest_api_id" , "resource_id" , "http_method" , "status_code" ),
279+ "aws_api_gateway_integration_response" : apiGatewayFormattedIdentifier ( "agir " , "rest_api_id" , "resource_id" , "http_method" , "status_code" ),
280280 // aws_api_gateway_method can be imported using REST-API-ID/RESOURCE-ID/HTTP-METHOD
281- "aws_api_gateway_method" : FormattedIdentifierFromProvider ( "/ " , "rest_api_id" , "resource_id" , "http_method" ),
281+ "aws_api_gateway_method" : apiGatewayFormattedIdentifier ( "agm " , "rest_api_id" , "resource_id" , "http_method" ),
282282 // aws_api_gateway_method_response can be imported using REST-API-ID/RESOURCE-ID/HTTP-METHOD/STATUS-CODE
283- "aws_api_gateway_method_response" : FormattedIdentifierFromProvider ( "/ " , "rest_api_id" , "resource_id" , "http_method" , "status_code" ),
283+ "aws_api_gateway_method_response" : apiGatewayFormattedIdentifier ( "agmr " , "rest_api_id" , "resource_id" , "http_method" , "status_code" ),
284284 // aws_api_gateway_method_settings can be imported using REST-API-ID/STAGE-NAME/METHOD-PATH
285- "aws_api_gateway_method_settings" : FormattedIdentifierFromProvider ( "/ " , "rest_api_id" , "stage_name" , "method_path" ),
285+ "aws_api_gateway_method_settings" : apiGatewayFormattedIdentifier ( " " , "rest_api_id" , "stage_name" , "method_path" ),
286286 // aws_api_gateway_model can be imported using REST-API-ID/NAME
287287 "aws_api_gateway_model" : config .IdentifierFromProvider ,
288288 // aws_api_gateway_request_validator can be imported using REST-API-ID/REQUEST-VALIDATOR-ID
@@ -294,7 +294,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{
294294 // aws_api_gateway_rest_api_policy can be imported by using the REST API ID
295295 "aws_api_gateway_rest_api_policy" : FormattedIdentifierFromProvider ("" , "rest_api_id" ),
296296 // aws_api_gateway_stage can be imported using REST-API-ID/STAGE-NAME
297- "aws_api_gateway_stage" : FormattedIdentifierFromProvider ( "/ " , "rest_api_id" , "stage_name" ),
297+ "aws_api_gateway_stage" : apiGatewayFormattedIdentifier ( "ags " , "rest_api_id" , "stage_name" ),
298298 // AWS API Gateway Usage Plan can be imported using the id
299299 "aws_api_gateway_usage_plan" : config .IdentifierFromProvider ,
300300 // AWS API Gateway Usage Plan Key can be imported using the USAGE-PLAN-ID/USAGE-PLAN-KEY-ID
@@ -3376,6 +3376,51 @@ func apiGatewayAccount() config.ExternalName {
33763376 return e
33773377}
33783378
3379+ // apiGatewayFormattedIdentifier configures external name for API Gateway
3380+ // v1 resources where the Terraform internal ID format differs from the import
3381+ // format. GetExternalNameFn reads tfstate fields directly (e.g.,
3382+ // tfstate["rest_api_id"]) and joins them with "/" separators. GetIDFn reads
3383+ // parameters and joins them with "-" separators, optionally adding a prefix.
3384+ // This ensures consistent values to prevent external name oscillation.
3385+ func apiGatewayFormattedIdentifier (prefix string , keys ... string ) config.ExternalName {
3386+ e := config .IdentifierFromProvider
3387+ e .GetExternalNameFn = func (tfstate map [string ]interface {}) (string , error ) {
3388+ vals := make ([]string , len (keys ))
3389+ for i , key := range keys {
3390+ val , ok := tfstate [key ]
3391+ if ! ok {
3392+ return "" , errors .Errorf ("parameter %q cannot be empty" , key )
3393+ }
3394+ s , ok := val .(string )
3395+ if ! ok {
3396+ return "" , errors .Errorf ("parameter %q must be a string" , key )
3397+ }
3398+ vals [i ] = s
3399+ }
3400+ return strings .Join (vals , "/" ), nil
3401+ }
3402+ e .GetIDFn = func (_ context.Context , _ string , parameters map [string ]interface {}, _ map [string ]interface {}) (string , error ) {
3403+ vals := make ([]string , len (keys ))
3404+ for i , key := range keys {
3405+ val , ok := parameters [key ]
3406+ if ! ok {
3407+ return "" , errors .Errorf ("parameter %q cannot be empty" , key )
3408+ }
3409+ s , ok := val .(string )
3410+ if ! ok {
3411+ return "" , errors .Errorf ("parameter %q must be a string" , key )
3412+ }
3413+ vals [i ] = s
3414+ }
3415+ id := strings .Join (vals , "-" )
3416+ if prefix != "" {
3417+ return prefix + "-" + id , nil
3418+ }
3419+ return id , nil
3420+ }
3421+ return e
3422+ }
3423+
33793424// fullARNTemplate builds a templated string for constructing a terraform id component which is an ARN, which includes
33803425// the aws partition, service, region, account id, and resource. This is by far the most common form of ARN.
33813426// e.g. arn:aws:ec2:ap-south-1:123456789012:instance/i-1234567890ab
0 commit comments