Skip to content
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

Closed
ghost opened this issue Jan 26, 2018 · 3 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ecs Issues and PRs that pertain to the ecs service.

Comments

@ghost
Copy link

ghost commented Jan 26, 2018

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.

@radeksimko radeksimko added service/ecs Issues and PRs that pertain to the ecs service. enhancement Requests to existing resources that expand the functionality or scope. labels Jan 27, 2018
@Ancient123
Copy link

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.

@bflad
Copy link
Contributor

bflad commented Jul 1, 2019

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 yamldecode() and yamlencode() built-in functions. In the case of this resource, we just need to decode the YAML and ensure its encoded as JSON which is the ECS API requirement. The typing of elements must match ECS requirements.

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

@ghost
Copy link
Author

ghost commented Nov 3, 2019

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!

@ghost ghost locked and limited conversation to collaborators Nov 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ecs Issues and PRs that pertain to the ecs service.
Projects
None yet
Development

No branches or pull requests

3 participants