-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept YAML documents for container_definitions argument of aws_ecs_task_definition resource #3153
Comments
Also providing a translation layer from HCL/Terraform to the YAML syntax so we don't have to break out of the standard (terraform) syntax to deal with ECS tasks anymore. |
Hi folks 👋 Available in Terraform 0.12.2 and later, there is now native support for a subset of YAML's functionality in Terraform configurations via the As a contrived example with multi-line heredoc syntax, given this configuration: terraform {
required_providers {
aws = ">= 2.7.0"
}
required_version = ">= 0.12.2"
}
provider "aws" {
region = "us-east-2"
}
resource "aws_ecs_task_definition" "example" {
family = "3153example"
container_definitions = jsonencode(yamldecode(<<TASK
- name: sleep
image: busybox
cpu: 10
command:
- sleep
- "360"
memory: 10
essential: true
TASK
))
} Successfully applies with: $ terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_ecs_task_definition.example will be created
+ resource "aws_ecs_task_definition" "example" {
+ arn = (known after apply)
+ container_definitions = jsonencode(
[
+ {
+ command = [
+ "sleep",
+ "360",
]
+ cpu = 10
+ essential = true
+ image = "busybox"
+ memory = 10
+ name = "sleep"
},
]
)
+ family = "3153example"
+ id = (known after apply)
+ network_mode = (known after apply)
+ revision = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
aws_ecs_task_definition.example: Creating...
aws_ecs_task_definition.example: Creation complete after 1s [id=3153example]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Hope this helps! For further feature requests or bug reports with the new general YAML configuration handling within in Terraform, please open an issue upstream in Terraform Core, where it is implemented: https://github.com/hashicorp/terraform/issues |
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! |
This issue was originally opened by @justindisney as hashicorp/terraform#17212. It was migrated here as a result of the provider split. The original body of the issue is below.
The current Terraform documentation says that the
container_definitions
argument must be "provided as a single valid JSON document":https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html#container_definitions
However, AWS documentation says that ContainerDefinitions can also be declared in YAML:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinitions.html
Since YAML is typically tidier than JSON, and offers useful things like comments, it would be helpful if Terraform could leverage YAML documents for
container_definitions
, and even better if it could treat the YAML file as a template with variable replacement upon rendering.The text was updated successfully, but these errors were encountered: