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.81k stars 9.16k forks source link

aws_apigatewayv2_deployment - Provider produced inconsistent final plan #14271

Open warrenstephens opened 4 years ago

warrenstephens commented 4 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Affected Resource(s)

Terraform Configuration Files

I had just added this chunk to a previously working set of terraform files. However, I am new to apigateway2.


resource "aws_apigatewayv2_deployment" "armadillo_api_deployment" {
  api_id      = aws_apigatewayv2_api.armadillo_http_api.id
  description = "Armadillo API deployment - ${terraform.workspace}"

  triggers = {
    redeployment = sha1(join(",", list(
      jsonencode(aws_apigatewayv2_integration.armadillo_integration),
      jsonencode(aws_apigatewayv2_route.armadillo_api_route),
    )))
  }

  lifecycle {
    create_before_destroy = true
  }
}

Debug Output

Panic Output

Expected Behavior

Actual Behavior

Output from terraform:

Error: Provider produced inconsistent final plan

When expanding the plan for
aws_apigatewayv2_deployment.armadillo_api_deployment to include new values
learned so far during apply, provider "registry.terraform.io/-/aws" produced
an invalid new value for .triggers["redeployment"]: was
cty.StringVal("985a4bdac94be5e769df3735cd90a02e1f7a4af8"), but now
cty.StringVal("d43f38eea6199121d964495325a814c9961442bf").

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Steps to Reproduce

  1. terraform apply

Important Factoids

provider 2.70.0

References

ewbankkit commented 4 years ago

@warrenstephens Thanks for raising this issue. It may be worth trying only attributes of aws_apigatewayv2_integration.armadillo_integration that change as triggers rather than the resource as a whole.

KevinD-87 commented 3 years ago

I had the same issue and the suggestion to only include the integration resources worked. I had to keep the routes as a depends_on reference though, so everything deployed nicely:

Not working with inconsistent final plan during deployments:

resource "aws_apigatewayv2_deployment" "deployment_http" {
  api_id = aws_apigatewayv2_api.apigw_http.id

  triggers = {
    redeployment = sha1(join(",", tolist([
      jsonencode(aws_apigatewayv2_api.apigw_http),
      jsonencode(aws_apigatewayv2_route.gateway_route_post),
      jsonencode(aws_apigatewayv2_integration.integration_mylambda),
    ])))
  }

  depends_on = [
    aws_apigatewayv2_api.apigw_http,
    aws_apigatewayv2_route.gateway_route_post,
    aws_apigatewayv2_integration.integration_mylambda,
  ]

  lifecycle {
    create_before_destroy = true
  }
}

Working:

resource "aws_apigatewayv2_deployment" "deployment_http" {
  api_id = aws_apigatewayv2_api.apigw_http.id

  triggers = {
    redeployment = sha1(join(",", tolist([
      jsonencode(aws_apigatewayv2_integration.integration_mylambda),
    ])))
  }

  depends_on = [
    aws_apigatewayv2_api.apigw_http,
    aws_apigatewayv2_route.gateway_route_post,
    aws_apigatewayv2_integration.integration_mylambda,
  ]

  lifecycle {
    create_before_destroy = true
  }
}
github-actions[bot] commented 5 months ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

Woody1193 commented 4 months ago

This issue is also occurring on both v5.22 and v5.52.

Woody1193 commented 4 months ago

@KevinD-87 I tried that exact solution as well but it didn't fix the issue for me:

resource "aws_apigatewayv2_deployment" "alb_connection" {
  api_id      = data.aws_apigatewayv2_api.gateway.id
  description = "Deployment of ${var.api_gateway_name} for ${local.full_name}"

  triggers = {
    redeployment = sha1(join(",", tolist([
      jsonencode(aws_apigatewayv2_integration.alb_connection),
    ])))
  }

  lifecycle {
    create_before_destroy = true
  }

  depends_on = [
    aws_apigatewayv2_integration.alb_connection,
    aws_apigatewayv2_route.alb_connection,
    aws_apigatewayv2_authorizer.alb_connection,
  ]
}

This implies that the problem is related to the resources that changed as I had an integration change as well.