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.86k stars 9.21k forks source link

[Bug]: aws_cloudformation_type doesn't support updates #38850

Open jfgordon2 opened 3 months ago

jfgordon2 commented 3 months ago

Terraform Core Version

1.5.7

AWS Provider Version

5.43.0

Affected Resource(s)

aws_cloudformation_type

Expected Behavior

When registering a new handler package, and setting the lifecycle to created_before_destroy, and the old version is the default version for that type, terraform should assume that I'm also updating the default version of the type to the newly created version before destroying the old version/

Expected order of events:

Actual Behavior

After creating the updated version, terraform apply fails during the destroy operation with the following error:

Error: deregistering CloudFormation Type (arn:aws:cloudformation:REGION:ACCOUNTID:type/resource/my::custom::type/00000001): CFNRegistryException: Version '00000001' is the default version and cannot be deregistered. Deregister the resource type 'my::custom::type' instead.
    status code: 400, request id: blah-blah-blah

It appears the current behavior is this:

Relevant Error/Panic Output Snippet

Error: deregistering CloudFormation Type (arn:aws:cloudformation:REGION:ACCOUNTID:type/resource/my::custom::type/00000001): CFNRegistryException: Version '00000001' is the default version and cannot be deregistered. Deregister the resource type 'my::custom::type' instead.
    status code: 400, request id: blah-blah-blah

Terraform Configuration Files

First, apply a new CF type:

resource "aws_cloudformation_type" "dashboard" {
  schema_handler_package = "s3://datadog-cloudformation-resources/datadog-dashboards-dashboard/datadog-dashboards-dashboard-2.0.0.zip"
  type                   = "RESOURCE"
  type_name              = "Datadog::Dashboards::Dashboard"

  lifecycle {
    create_before_destroy = true
  }
}

Then update with a different version:

resource "aws_cloudformation_type" "dashboard" {
  schema_handler_package = "s3://datadog-cloudformation-resources/datadog-dashboards-dashboard/datadog-dashboards-dashboard-2.0.1.zip"
  type                   = "RESOURCE"
  type_name              = "Datadog::Dashboards::Dashboard"

  lifecycle {
    create_before_destroy = true
  }
}

Steps to Reproduce

deploy a aws_cloudformation_type and then update it with a new package.

Debug Output

No response

Panic Output

No response

Important Factoids

Current workaround is to let the apply fail, then manually run the set-type-default-version command using the aws-cli, then re-apply terraform.

aws cloudformation set-type-default-version --region "us-west-2" --type "RESOURCE" --version-id "00000002" --type-name "my::custom::type"

References

No response

Would you like to implement a fix?

Yes

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

jfgordon2 commented 3 months ago

I'm not super great with go, but using the patterns around the code, I took a stab at the PR fix for this: #38855