Difference between revisions of "Terraform resource: aws ecs task definition"

From wikieduonline
Jump to navigation Jump to search
 
(65 intermediate revisions by 4 users not shown)
Line 1: Line 1:
* https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition
+
<code>aws_ecs_task_definition</code> ([https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition ref]): [[container_definitions]]
 +
 
 +
== Attributes ==
 +
* <code>[[family]] =</code> (required) is a name for your task definition
 +
* <code>[[container_definitions]]:</code>  <code>[[name]], [[image]], [[cpu =|cpu]], [[memory]], [[essential]], [[portMappings]]</code>
 +
* <code>[[environment]] = </code>
 +
* <code>[[secrets]] = </code>
 +
* <code>[[dependsOn =]]</code>
 +
* <code>[[portMappings]] = </code>
 +
* <code>[[task_role_arn]] = </code><ref>https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#task_role_arn</ref>
 +
* <code>[[execution_role_arn]] = </code><ref>https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#execution_role_arn</ref>
 +
* <code>[[revision]] = </code> https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#revision
 +
* <code>[[volume]] = </code>
 +
* <code>[[cpu =]]</code>
 +
* <code>[[cpu_architecture]] = </code>
 +
* <code>[[Terraform resource: aws ecs task definition, memory|memory =]]</code>
 +
* <code>[[requires_compatibilities]]</code>: [[EC2]], [[Fargate]]. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#requires_compatibilities
 +
* <code>[[network_mode]]</code> (optional) <code>none, [[bridge]], [[awsvpc]], and host</code> ([https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#network_mode ref])
 +
* <code>[[runtime_platform]]</code>
 +
 
 +
== Examples ==
 +
=== Official example ===
 +
{{terraform aws ecs task definition official example}}
 +
 
 +
 
 +
 
  
  
* <code>[[network_mode]]</code> (optional) https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#network_mode
+
=== Example myservice ===
:<code>none, bridge, awsvpc, and host</code>
+
resource "aws_ecs_task_definition" "mytask" {
 +
  [[family]] = "mytask"
 +
  container_definitions = [[jsonencode]]([
 +
    {
 +
      name      = "first"
 +
      image    = "service-first"
 +
      [[cpu]]      = 10
 +
      [[memory]]    = 512
 +
      essential = true
 +
      portMappings = [
 +
        {
 +
          containerPort = 80
 +
          hostPort      = 80
 +
        }
 +
      ]
 +
    },
 +
    {
 +
      name      = "second"
 +
      image    = "service-second"
 +
      cpu      = 10
 +
      memory    = 256
 +
      essential = true
 +
      portMappings = [
 +
        {
 +
          containerPort = 443
 +
          hostPort      = 443
 +
        }
 +
      ]
 +
    }
 +
  ])
 +
 +
  volume {
 +
    name      = "service-storage"
 +
    host_path = "/ecs/service-storage"
 +
  }
 +
 +
  placement_constraints {
 +
    type      = "memberOf"
 +
    expression = "attribute:ecs.availability-zone in [us-west-2a, us-west-2b]"
 +
  }
 +
}
  
 +
=== Official aws_ecs_service example ===
 +
{{terraform_aws_ecs_service_official_example}}
  
* <code>[[requires_compatibilities]]</code>: [[EC2]], [[Fargate]]. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#requires_compatibilities
+
 
 +
 
 +
{{terraform_aws_ecs_task_definition_official_example}}
 +
 
 +
== Errors ==
 +
* <code>[[ECS Task Definition container definitions is invalid]]</code>
 +
* <code>[[Error: ClientException: Invalid Compatibilities]]</code>
 +
* <code>[[Essential container in task exited]]</code>
 +
* [[Exit code: 2]]
  
 
== Related ==
 
== Related ==
* [[Error: ClientException: Invalid Compatibilities]]
+
* [[AWS ECS task definitions]]
 +
* [[Terraform resource]]: <code>[[aws_secretsmanager_secret_version]]</code>
 +
* <code>[[aws ecs register-task-definition]]</code>
 +
* <code>[[aws ecs describe-task-definition]]</code>
 +
* <code>[[aws ecs run-task]]</code>
  
 
== See also ==
 
== See also ==
 +
* {{aws_ecs_task_definition}}
 +
* {{AWS ECS tasks}}
 
* {{Terraform ECS}}
 
* {{Terraform ECS}}
* {{terraform plan}}
 
* {{Terraform aws resources}}
 
  
 
[[Category:Terraform]]
 
[[Category:Terraform]]

Latest revision as of 11:36, 5 June 2023

aws_ecs_task_definition (ref): container_definitions

Attributes[edit]

Examples[edit]

Official example[edit]

resource "aws_ecs_task_definition" "service" {
 family = "service"
 container_definitions = jsonencode([
   {
     name      = "first"
     image     = "service-first"
     cpu       = 10
     memory    = 512
     essential = true
     portMappings = [
       {
         containerPort = 80
         hostPort      = 80
       }
     ]
   },
   {
     name      = "second"
     image     = "service-second"
     cpu       = 10
     memory    = 256
     essential = true
     portMappings = [
       {
         containerPort = 443
         hostPort      = 443
       }
     ]
   }
 ])

 volume {
   name      = "service-storage"
   host_path = "/ecs/service-storage"
 }

 placement_constraints {
   type       = "memberOf"
   expression = "attribute:ecs.availability-zone in [us-west-2a, us-west-2b]"
 }
}



Example myservice[edit]

resource "aws_ecs_task_definition" "mytask" {
 family = "mytask"
 container_definitions = jsonencode([
   {
     name      = "first"
     image     = "service-first"
     cpu       = 10
     memory    = 512
     essential = true
     portMappings = [
       {
         containerPort = 80
         hostPort      = 80
       }
     ]
   },
   {
     name      = "second"
     image     = "service-second"
     cpu       = 10
     memory    = 256
     essential = true
     portMappings = [
       {
         containerPort = 443
         hostPort      = 443
       }
     ]
   }
 ])

 volume {
   name      = "service-storage"
   host_path = "/ecs/service-storage"
 }

 placement_constraints {
   type       = "memberOf"
   expression = "attribute:ecs.availability-zone in [us-west-2a, us-west-2b]"
 }
}

Official aws_ecs_service example[edit]

resource "aws_ecs_service" "mongo" {
 name            = "mongodb"
 cluster         = aws_ecs_cluster.foo.id
 task_definition = aws_ecs_task_definition.mongo.arn
 desired_count   = 3
 iam_role        = aws_iam_role.foo.arn
 depends_on      = [aws_iam_role_policy.foo]

 ordered_placement_strategy {
   type  = "binpack"
   field = "cpu"
 }

 load_balancer {
   target_group_arn = aws_lb_target_group.foo.arn
   container_name   = "mongo"
   container_port   = 8080
 }

 placement_constraints {
   type       = "memberOf"
   expression = "attribute:ecs.availability-zone in [us-west-2a, us-west-2b]"
 }
}


resource "aws_ecs_task_definition" "service" {
 family = "service"
 container_definitions = jsonencode([
   {
     name      = "first"
     image     = "service-first"
     cpu       = 10
     memory    = 512
     essential = true
     portMappings = [
       {
         containerPort = 80
         hostPort      = 80
       }
     ]
   },
   {
     name      = "second"
     image     = "service-second"
     cpu       = 10
     memory    = 256
     essential = true
     portMappings = [
       {
         containerPort = 443
         hostPort      = 443
       }
     ]
   }
 ])

 volume {
   name      = "service-storage"
   host_path = "/ecs/service-storage"
 }

 placement_constraints {
   type       = "memberOf"
   expression = "attribute:ecs.availability-zone in [us-west-2a, us-west-2b]"
 }
}

Errors[edit]

Related[edit]

See also[edit]

  • https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#task_role_arn
  • https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#execution_role_arn
  • Advertising: