С помощью Terraform, следуя документам здесь и там , я пытаюсь создать шаблон для экземпляра ec2 со спецификацией gpu с эластичным логическим выводом и графикой.
ЭтоМой код для ресурса шаблона запуска aws:
resource "aws_launch_template" "elastic_ec2" {
name_prefix = "DeepLearning"
description = "Deep Learning"
disable_api_termination = true
ebs_optimized = true
image_id = "ami-0d9d11b8557309342"
instance_initiated_shutdown_behavior = "terminate"
instance_type = "t3.medium"
key_name = "${local.pem_key_name}"
block_device_mappings {
device_name = "/dev/sda1"
}
capacity_reservation_specification {
capacity_reservation_preference = "open"
}
credit_specification {
cpu_credits = "standard"
}
elastic_gpu_specifications {
type = "eg1.medium"
}
elastic_inference_accelerator {
type = "eia1.medium"
}
iam_instance_profile {
name = "my-right-profile"
}
instance_market_options {
market_type = "spot"
}
monitoring {
enabled = true
}
network_interfaces {
associate_public_ip_address = true
}
placement {
availability_zone = "${var.main_location}"
}
tag_specifications {
resource_type = "instance"
tags = {
Environment = "${local.environment}"
}
}
}
resource "aws_instance" "web" {
ami = "${aws_launch_template.elastic_ec2.image_id}"
instance_type = "${aws_launch_template.elastic_ec2.instance_type}"
key_name = "${local.pem_key_name}"
iam_instance_profile = "${aws_iam_instance_profile.ec2_profile.name}"
tags = {
Environment = "${local.environment}"
App = "${local.app_name}"
}
}
Конечно, это политики, используемые для развертывания экземпляра в соответствии со спецификациями документа здесь :
resource "aws_iam_role" "ec2_exec_role" {
name = "ec2_exec"
path = "/"
description = "Allows Lambda Function to call AWS services on your behalf."
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": [
"ec2.amazonaws.com",
"ecs-tasks.amazonaws.com"
]
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}
resource "aws_iam_instance_profile" "ec2_profile" {
name = "${local.environment}_ec2_profile"
role = "${aws_iam_role.ec2_exec_role.name}"
}
resource "aws_iam_policy" "ec2_policy" {
name = "${local.environment}_ec2_policy"
description = "Ec2 main polify for ${local.environment} environment"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"elastic-inference:Connect",
"iam:List*",
"iam:Get*",
"ec2:Describe*",
"ec2:Get*",
"ecs:RegisterTaskDefinition",
"ecs:RunTask"
],
"Resource": [
"arn:aws:ec2:${var.main_location}::*",
"arn:aws:elastic-inference:${var.main_location}:${data.aws_caller_identity.current.account_id}:*",
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/ecs-ei-task-role",
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/ecsTaskExecutionRole"
]
}
]
}
EOF
}
resource "aws_iam_policy_attachment" "ec2_attachment" {
name = "${local.environment}_ec2__attachment"
roles = ["${aws_iam_role.ec2_exec_role.name}"]
policy_arn = "${aws_iam_policy.ec2_policy.arn}"
}
У меня нет ошибок при развертывании кода terraform с помощью команд terraform plan
и terraform apply
. У меня есть шаблон экземпляра и мой экземпляр ec2, но я вижу, что в моем экземпляре нет прикрепленного к нему идентификатора Elastic Inference Accelerator. Какая правильная конфигурация мне нужна, используя terraform, чтобы правильно прикрепить все спецификации упругого вывода