Terraform Version
Terraform v0.11.3
+ provider.aws v1.14.1
Affected Resource(s)
aws_ecs_task_definition
Terraform Configuration Files
(n/a)
Debug Output
(n/a)
Panic Output
(n/a)
Expected Behavior
Would like to be able to define task definition content in either JSON or YAML format.
Actual Behavior
When specified as YAML receiving Error creating Task Definition: InvalidDocumentContent: JSON not well-formed. at Line: 1, Column: 3 which confirms the resource documentation which states content should be JSON.
Steps to Reproduce
create a TF config with an aws_ecs_task_definition resource with task_definition content defined in YAML.
run terraform apply
Important Factoids
(n/a)
It would be nice to be able to pass a file in YAML format, such as a docker-compose formatted file as you can with the ECS compose command. If there is a means to do this already, documentation on the task definition page or pointing this ticket to the proper direction would be appreciated.
Similar to #3810
Hi @Spechal 👋 Thanks for submitting this feature request.
Taking a look at the AWS SDK and the API documentation, it looks like it only supports JSON as the input: https://docs.aws.amazon.com/sdk-for-go/api/service/ecs/#RegisterTaskDefinitionInput
// A list of container definitions in JSON format that describe the different
// containers that make up your task.
//
// ContainerDefinitions is a required field
ContainerDefinitions []*ContainerDefinition `locationName:"containerDefinitions" type:"list" required:"true"`
In #3810 we enabled YAML support for that SSM resource because AWS had implemented the support in the API: https://docs.aws.amazon.com/sdk-for-go/api/service/ssm/#CreateDocumentInput
// A valid JSON or YAML string.
//
// Content is a required field
Content *string `min:"1" type:"string" required:"true"`
// Specify the document format for the request. The document format can be either
// JSON or YAML. JSON is the default format.
DocumentFormat *string `type:"string" enum:"DocumentFormat"`
Due to the complexity of maintenance, we will not likely implement our own conversion of YAML to JSON in the AWS provider.
If you have an AWS support plan, I would suggest opening a feature request through that channel so they can prioritize supporting both formats in the API. If/when that feature is implemented, we'll gladly get it into Terraform. 👍
@Spechal Terraform v0.12.2 added yamldecode function.
https://www.terraform.io/docs/configuration/functions/yamldecode.html
This means we can now write it like this:
main.tf
```main.tf
resource "aws_ecs_task_definition" "test" {
family = "test"
container_definitions = jsonencode(yamldecode(file("test.yaml")))
}
test.yaml
```test.yaml
- name: test
image: nginx:latest
essential: true
memoryReservation: 50
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
@Spechal Terraform v0.12.2 added
yamldecodefunction.https://www.terraform.io/docs/configuration/functions/yamldecode.html
This means we can now write it like this:
main.tf
```main.tf
resource "aws_ecs_task_definition" "test" {
family = "test"
container_definitions = jsonencode(yamldecode(file("test.yaml")))
}