hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.76k stars 9.11k forks source link

[Bug]: `aws_apigatewayv2_api.body` overrides `aws_apigatewayv2_api.name` #33389

Open garysassano opened 1 year ago

garysassano commented 1 year ago

Terraform Core Version

1.5.2

AWS Provider Version

4.65.0

Affected Resource(s)

I have the same issue described HERE but for HTTP API.

Expected Behavior

Creating an aws_apigatewayv2_api resource with body argument updates only the body of the APIGatewayV2, without overriding the name.

Actual Behavior

The name argument of the aws_apigatewayv2_api resource gets overridden by the info.title field specified within the OAS30 definition if present, otherwise it defaults to Imported on {date/time}.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

{
  "//": {
    "metadata": {
      "backend": "local",
      "stackName": "root",
      "version": "0.17.0"
    },
    "outputs": {
      "root": {
        "Default": {
          "cloud.TestRunner": {
            "TestFunctionArns": "WING_TEST_RUNNER_FUNCTION_ARNS"
          }
        }
      }
    }
  },
  "data": {
    "aws_region": {
      "Region": {
        "//": {
          "metadata": {
            "path": "root/Default/Region",
            "uniqueId": "Region"
          }
        }
      }
    }
  },
  "output": {
    "WING_TEST_RUNNER_FUNCTION_ARNS": {
      "value": "[]"
    }
  },
  "provider": {
    "aws": [
      {
      }
    ]
  },
  "resource": {
    "aws_apigatewayv2_api": {
      "cloudApi_api_2B334D75": {
        "//": {
          "metadata": {
            "path": "root/Default/Default/cloud.Api/api/api",
            "uniqueId": "cloudApi_api_2B334D75"
          }
        },
        "body": "{\"openapi\":\"3.0.1\",\"servers\":[{\"url\":\"https://xxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/{basePath}\",\"variables\":{\"basePath\":{\"default\":\"\"}}}],\"paths\":{\"/$default\":{\"x-amazon-apigateway-any-method\":{\"isDefaultRoute\":true,\"x-amazon-apigateway-integration\":{\"payloadFormatVersion\":\"1.0\",\"type\":\"http_proxy\",\"httpMethod\":\"ANY\",\"uri\":\"https://example.com/\",\"connectionType\":\"INTERNET\"}}}},\"x-amazon-apigateway-importexport-version\":\"1.0\"}",
        "name": "customname",
        "protocol_type": "HTTP"
      }
    },
    "aws_apigatewayv2_stage": {
      "cloudApi_api_stage_BBB283E4": {
        "//": {
          "metadata": {
            "path": "root/Default/Default/cloud.Api/api/stage",
            "uniqueId": "cloudApi_api_stage_BBB283E4"
          }
        },
        "api_id": "${aws_apigatewayv2_api.cloudApi_api_2B334D75.id}",
        "auto_deploy": true,
        "name": "$default"
      }
    }
  },
  "terraform": {
    "backend": {
      "local": {
        "path": "./terraform.tfstate"
      }
    },
    "required_providers": {
      "aws": {
        "source": "aws",
        "version": "4.65.0"
      }
    }
  }
}

Steps to Reproduce

terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

garysassano commented 1 year ago

To clarify, I think it's fine that aws_apigatewayv2_api.body overrides aws_apigatewayv2_api.name, but ONLY IF you specified a value for info.title inside your OAS30 definition, otherwise aws_apigatewayv2_api.name should remain unchanged.