Skip to content

fix: implement schema patches to fix ECS Service PlatformVersion default#2979

Open
AviorSchreiber wants to merge 1 commit intohashicorp:mainfrom
AviorSchreiber:main
Open

fix: implement schema patches to fix ECS Service PlatformVersion default#2979
AviorSchreiber wants to merge 1 commit intohashicorp:mainfrom
AviorSchreiber:main

Conversation

@AviorSchreiber
Copy link

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request
  • The resources and data sources in this provider are generated from the CloudFormation schema, so they can only support the actions that the underlying schema supports. For this reason submitted bugs should be limited to defects in the generation and runtime code of the provider. Customizing behavior of the resource, or noting a gap in behavior are not valid bugs and should be submitted as enhancements to AWS via the CloudFormation Open Coverage Roadmap.

Closes #2122

Rollback Plan

If a change needs to be reverted, we will publish an updated version of the library.

Changes to Security Controls

No changes to security controls. This PR only modifies the schema generation process.

Description

This PR implements a generic schema patching mechanism to fix incorrect default values in CloudFormation schemas before they are cached and used for code generation.

Problem

The awscc_ecs_service resource incorrectly sets platform_version to "LATEST" by default, even for EC2 launch type services where this attribute should be null. This is because the upstream CloudFormation schema includes "default": "LATEST" for the PlatformVersion property.

Solution

Implement a schema patching mechanism that:

  • Applies RFC 6902 JSON Patch operations to CloudFormation schemas after download but before caching
  • Uses the existing evanphx/json-patch library (already an indirect dependency)
  • Supports remove operations (extensible for future operations)
  • Is configured via schema_patches blocks in all_schemas.hcl

Changes

New files:

  • internal/provider/generators/schema/patches.go - Patch application logic
  • internal/provider/generators/schema/patches_test.go - Comprehensive tests

Modified files:

  • internal/provider/generators/schema/main.go - Extended ResourceSchema struct with SchemaPatches field
  • internal/provider/all_schemas.hcl - Added patch configuration for aws_ecs_service
  • internal/provider/schemas.go - Updated go:generate directive to include patches.go
  • go.mod - Promoted evanphx/json-patch to direct dependency

Usage

To add patches for other resources with similar issues:

resource_schema "aws_ecs_service" {
  cloudformation_type_name = "AWS::ECS::Service"

  schema_patches {
    operation {
      action    = "remove"
      json_path = "/properties/PlatformVersion/default"
    }
  }
}

@AviorSchreiber
Copy link
Author

Hi guys,
Any update on this?

@YakDriver
Copy link
Member

YakDriver commented Feb 4, 2026

Thank you for this contribution @AviorSchreiber! The implementation is well-designed and thoroughly tested - the generic patching mechanism using RFC 6902 is a solid approach.

However, this issue should be fixed upstream in the AWS CloudFormation schema rather than worked around in the provider. As discussed in #2122, a service ticket has been opened with AWS to correct the schema's default value for PlatformVersion.

We prefer to wait for the upstream fix rather than introduce schema patching, as it adds maintenance overhead and technical debt that would need to be carried until AWS resolves the issue on their end. If AWS is unable or unwilling to fix the issue, we can take this approach as an alternative.

I appreciate the effort you put into this PR, and please feel free to contribute to other issues in the future!

}
}

err = os.WriteFile(dst, []byte(schemaStr), 0644)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = os.WriteFile(dst, []byte(schemaStr), 0644)
err = os.WriteFile(dst, []byte(schemaStr), 0644) //nolint:mnd

Const would be better if there are other uses in schema but if not suppression is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The platform version must be null when specifying an EC2 launch type

3 participants