我正在AWS中定義一個任務,我已經使用aws_ecs_task_definition模塊作業了。我正在使用terraform模塊中的environtment var設定一些環境變數,但其中一些變數將通過AWS SSM提供。不使用AWS SSM的正常創建是:
environment : [
{
name : "user"/span>,
value : "name".
},
],
這就像一種魅力。
然后我嘗試:
environment : [
{
name : "user"/span>,
valueFrom : "my_env_var_name_in_ssm"。
},
],
但它并不作業。當我進入任務定義的用戶界面時,ENV變數不在那里,在用戶界面的json定義中也沒有。
然后我試著在 UI 中創建它們,任務完美地作業,我看到當你設定 valueFrom 時,ENV 變數在 json 定義的 secrets 部分下被創建。所以我試著在Terraform中復制它,例如:
secrets : [
{
name : "user"/span>,
valueFrom : "my_env_var_name_in_ssm"。
},
],
但是,它也沒有作業。任務定義json是:
{}。
"ipcMode": null,
"executionRoleArn": "arn",
"containerDefinitions": [
{
"dnsSearchDomains": null,
"environmentFiles": null,
"logConfiguration": null,
"entryPoint": null,
"portMappings": [/span>
{
"hostPort": 8080,
"協議": "tcp",
"containerPort": 8080
},
{
"hostPort": 8793,
"協議": "tcp",
"containerPort": 8793
}
],
"command": null,
"linuxParameters": null,
"cpu": 7,
"環境": []。
{>
"name": "name",
"值": "harcoded"
},
],
"resourceRequirements": null,
"ulimits": null,
"dnsServers": null,
"mountPoints": [],
"workingDirectory": null,
"secrets": null,
"dockerSecurityOptions": null,
"memory": null,
"memoryReservation": 128,
"volumesFrom": [],
"stopTimeout": null,
"image": "image_arn",
"startTimeout": null,
"firelensConfiguration": null,
" dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": null,
"readonlyRootFilesystem": null,
"dockerLabels": null,
"systemControls": null,
"privileged": null,
"name": "my-name"
}
],
"placementConstraints": [],/span>
"memory": null,
"taskRoleArn": "arn",
"compatibilities": [
"EC2"/span>
],
"taskDefinitionArn": "arn",
"family": "family-name",
"requireAttributes": [/span>
{>
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capacity.ecr-auth"
},
{>
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capacity.docker-remote-api.1.21"
},
{>
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capacity.task-iam-role"
},
{>
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capacity.execution-role-ecr-pull"
},
{>
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capacity.docker-remote-api.1.18"
},
{>
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capacity.task-eni"
}
],
"pidMode": null,
" requiresCompatibilities": [],
"networkMode": "awsvpc",
"cpu": null,
"修訂": 2,
"status": "ACTIVE" ,
"inferenceAccelerators": null,
"proxyConfiguration": null,
"卷": []
}
正如你所看到的,json回傳。"secrets": null,
當terraform運行一個container_definitions時,像這樣:
container_definitions = jsonencode(_span>
[
{
name = aws_ecs_cluster.cluster.name,
image = "${var.image_url}:latest"。
cpu = 7,
dnsSearchDomains = null,
network_configuration = "awsvpc"/span>,
entryPoint = null,
portMappings = [
{
hostPort = 8080。
protocol = "tcp"/span>。
containerPort = 8080
},
{
hostPort = 8793,
protocol = "tcp"/span>。
containerPort = 8793。
}
],
command : null,
linuxParameters : null,
environment : [
{
name : "name"/span>,
value : "harcoded".
},
],
secrets : [
{
name : "引數-名稱"。
valueFrom : "arn:aws:ssm:eu-west-2:11111111:parameter/my_env_var_name_in_ssm"。
},
],
resourceRequirements : null,
ulimits : null,
dnsServers : null,
mountPoints : null。
workingDirectory : null。
secrets : null。
dockerSecurityOptions : null。
memoryReservation : 128,
volumesFrom : [],
stopTimeout : null,
startTimeout : null,
firelensConfiguration : null。
dependsOn : null,
disableNetworking : null。
interactive : null,
健康檢查: null,
essential : true。
鏈接 : null。
hostname : null。
extraHosts : null。
pseudoTerminal : null,
user : null,
readonlyRootFilesystem : null。
dockerLabels : null,
systemControls : null,
privileged : null, privileged :
}
]
)
}
terraform apply作業正常,但secrets不在terraform執行的動作的輸出中,所以json定義顯示為空是正常的。那么我想真正的問題是如何在terraform中寫入它。
我如何使用AWS SSM作為Terraform中定義的AWS ECS任務的valueFrom?你可以看到json是
uj5u.com熱心網友回復:
你的任務定義有secrets兩次定義。一次是一個值,一次是null:
請看我從你發布的代碼中復制的這塊的第一行和最后一行:
。 secrets : [
{
name : "parameter-name"/span>,
valueFrom : "arn:aws:ssm:eu-west-2:11111111:parameter/my_env_var_name_in_ssm"。
},
],
resourceRequirements : null,
ulimits : null,
dnsServers : null,
mountPoints : null,
workingDirectory : null,
secrets : null,
你需要洗掉secrets : null這一行,因為它覆寫了先前的設定。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/325347.html
標籤:
上一篇:DynamoDB-如果不存在,則創建主鍵和屬性,否則獲得
下一篇:如何將專案添加到串列中?翩翩起舞
