2017-01-14 70 views
3

我正在嘗試使用Terraform設置ECS羣集,但我無法弄清楚如何在承載服務的ECS實例上使Terraform自動提供一個EBS卷,卷。如何將EBS卷添加到Terraform中的ECS實例

在我的配置我有:

resource "aws_ecs_task_definition" "name" { 
    family = "name" 
    container_definitions = "${file("task-definitions/name.json")}" 

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

resource "aws_ecs_service" "name" { 
    name = "name" 
    cluster = "${aws_ecs_cluster.main.id}" 
    task_definition = "${aws_ecs_task_definition.name.arn}" 
    desired_count = 1 
    iam_role = "${aws_iam_role.ecs_service_role.arn}" 
    depends_on = ["aws_iam_role_policy.ecs_service_role_policy"] 

    load_balancer { 
    elb_name = "${aws_elb.name.id}" 
    container_name = "name" 
    container_port = 8000 
    } 
} 

,並在task-definitions/name.json我:

"mountPoints": [ 
    { 
    "sourceVolume": "name-storage", 
    "containerPath": "/var/lib/cassandra" 
    } 
] 

如何真正得到上承載該服務實例的音量?

回答

0

在Docker容器內部安裝一個卷是其他配置EBS存儲的其他內容。您複製了ECS服務/任務設置的配置,但未複製您的ECS實例(應該是正常的EC2實例)的設置。如果您使用標準ECS優化的Amazon Machine Image,則某些標準EBS卷會在安裝時自動創建。

問題仍然存在,您希望在使用ECS時在Docker容器中安裝卷。在很多情況下,這是不需要的和/或有其他更好的解決方案。 ECS構建的前提是任何容器都可以在羣集中的任何實例上運行,如果您需要來自容器外部的特定數據,則此前提可能不成立。

相關問題