简体   繁体   中英

Terraform aws task definition Container.image contains invalid characters

I'M developing an aws infrastucture with terraform,

1.-I create a frontend repo

resource "aws_ecr_repository" "frontend" { name = "${var.env}-frontend" }

2.-I create a task-definition

resource "aws_ecs_task_definition" "mambaml" { family = "${var.env}-mambaml-service" container_definitions = "${file("task-definitions/service.json")}" .... }

3.-service.json file

[ { "name": "frontend", "image": "${aws_ecr_repository.frontend.repository_url}:latest", "cpu": 1, "memory": 256, "essential": true, "portMappings": [ { "containerPort": 80, "hostPort": 80 } ] }, ]

After that I'm reciving the error

"ClientException: Container.image contains invalid characters. status code: 400, request id: 46e50fc0-71d9-4b15-b029-ecd9c91d59eb"

This is the ouput for $aws_ecr_repository.frontend.repository_url

-111111111.dkr.ecr.us-west-1.amazonaws.com/production-frontend

¿Any idea?

I found a better solution

Data field for resource to consume

data "template_file" "app" {
  template = file("terraform/templates/app.json")
  vars = {
    tf_env = "${terraform.workspace}"
    }
  }

*JSON CODE BELOW

[
  {
    "name": "app",
    "image": "image",
    "cpu": 1024,
    "memory": 2048,
    "networkMode": "vpc",
    "environment": [
            {"name": "PNI_API_HOSTNAME", "value": "app.${tf_env}.com"},
            {"name": "NODE_ENV", "value": "${tf_env}"}
        ],
    "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "app",
          "awslogs-region": "us-east-1",
          "awslogs-stream-prefix": "ecs"
        }
    },
    "portMappings": [
      {
        "containerPort": 3000,
        "hostPort": 3000
      }
    ]
  }
]

doing the above allows you to have variables in JSON since JSON won't let you add them in without defining it beforehand.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM