Skip to content

aws_api_gateway_resource update to path_part requires applying twice to update attribute path #42904

Open
@lucastonelli

Description

@lucastonelli

Terraform and AWS Provider Version

Terraform v1.9.8
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v5.86.1
+ provider registry.terraform.io/hashicorp/awscc v1.28.0
+ provider registry.terraform.io/integrations/github v5.45.0
+ provider registry.terraform.io/jianyuan/sentry v0.14.3
+ provider registry.terraform.io/kreuzwerker/docker v3.0.2

Your version of Terraform is out of date! The latest version
is 1.12.1. You can update by downloading from https://www.terraform.io/downloads.html

Affected Resource(s) or Data Source(s)

  • aws_api_gateway_resource

Expected Behavior

Apply the following resources:

resource "aws_api_gateway_rest_api" "main" {
  name                         = "example"
  disable_execute_api_endpoint = true

  endpoint_configuration {
    types = ["EDGE"]
  }
}

resource "aws_api_gateway_resource" "main" {
  rest_api_id = aws_api_gateway_rest_api.main.id
  parent_id   = aws_api_gateway_rest_api.main.root_resource_id
  path_part   = "foo"
}

resource "aws_api_gateway_resource" "copy" {
  rest_api_id = aws_api_gateway_rest_api.main.id
  parent_id   = aws_api_gateway_rest_api.main.root_resource_id
  path_part   = join("", [replace(aws_api_gateway_resource.main.path, "/", ""), "-copy"])
}

You'll end up with two resources:

  • /foo
  • /foo-copy

Then change the path_part from aws_api_gateway_resource.main to bar. Apply the changes and you'll see that resource aws_api_gateway_resource.copy is being modified and its path_parth is /bar-copy.

You end up with two resources:

  • /bar
  • /bar-copy

Right after applying the previous change, apply again, you'll have nothing to change.

Actual Behavior

Apply the following resources:

resource "aws_api_gateway_rest_api" "main" {
  name                         = "example"
  disable_execute_api_endpoint = true

  endpoint_configuration {
    types = ["EDGE"]
  }
}

resource "aws_api_gateway_resource" "main" {
  rest_api_id = aws_api_gateway_rest_api.main.id
  parent_id   = aws_api_gateway_rest_api.main.root_resource_id
  path_part   = "foo"
}

resource "aws_api_gateway_resource" "copy" {
  rest_api_id = aws_api_gateway_rest_api.main.id
  parent_id   = aws_api_gateway_rest_api.main.root_resource_id
  path_part   = join("", [replace(aws_api_gateway_resource.main.path, "/", ""), "-copy"])
}

You'll end up with two resources:

  • /foo
  • /foo-copy

Then change the path_part from aws_api_gateway_resource.main to bar. Apply the changes and you'll see that resource aws_api_gateway_resource.copy is not being modified, even tough there's a dependency from aws_api_gateway_resource.main.

You end up with two resources:

  • /bar
  • /foo-copy

Right after applying the previous change, apply again, without changing anything, then you'll see aws_api_gateway_resource.copy will be modified to have path_part set to bar-copy.

You end up with two resources:

  • /bar
  • /bar-copy

Relevant Error/Panic Output

Sample Terraform Configuration

Click to expand configuration
resource "aws_api_gateway_rest_api" "main" {
  name                         = "example"
  disable_execute_api_endpoint = true

  endpoint_configuration {
    types = ["EDGE"]
  }
}

resource "aws_api_gateway_resource" "main" {
  rest_api_id = aws_api_gateway_rest_api.main.id
  parent_id   = aws_api_gateway_rest_api.main.root_resource_id
  path_part   = "foo"
}

resource "aws_api_gateway_resource" "copy" {
  rest_api_id = aws_api_gateway_rest_api.main.id
  parent_id   = aws_api_gateway_rest_api.main.root_resource_id
  path_part   = join("", [replace(aws_api_gateway_resource.main.path, "/", ""), "-copy"])
}

Steps to Reproduce

  1. Apply the configuration;
  2. Modify path_part from aws_api_gateway_resource.main to bar;
  3. Apply the changes;
  4. Don't change anything, apply again.

Debug Logging

Click to expand log output

GenAI / LLM Assisted Development

n/a

Important Facts and References

The previous issue was mistakenly closed as the provided sample configuration was not followed, mistakenly fixing the problem, which, in fact, still exists.

Would you like to implement a fix?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.needs-triageWaiting for first response or review from a maintainer.service/apigatewayIssues and PRs that pertain to the apigateway service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions