fix: implement schema patches to fix ECS Service PlatformVersion default#2979
fix: implement schema patches to fix ECS Service PlatformVersion default#2979AviorSchreiber wants to merge 1 commit intohashicorp:mainfrom
Conversation
|
Hi guys, |
|
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 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) |
There was a problem hiding this comment.
| 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.
Community Note
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_serviceresource incorrectly setsplatform_versionto"LATEST"by default, even for EC2 launch type services where this attribute should benull. This is because the upstream CloudFormation schema includes"default": "LATEST"for thePlatformVersionproperty.Solution
Implement a schema patching mechanism that:
evanphx/json-patchlibrary (already an indirect dependency)removeoperations (extensible for future operations)schema_patchesblocks inall_schemas.hclChanges
New files:
internal/provider/generators/schema/patches.go- Patch application logicinternal/provider/generators/schema/patches_test.go- Comprehensive testsModified files:
internal/provider/generators/schema/main.go- ExtendedResourceSchemastruct withSchemaPatchesfieldinternal/provider/all_schemas.hcl- Added patch configuration foraws_ecs_serviceinternal/provider/schemas.go- Updatedgo:generatedirective to includepatches.gogo.mod- Promotedevanphx/json-patchto direct dependencyUsage
To add patches for other resources with similar issues: