Terraform не может запустить службу докеров

Я впервые использую Terraform и Packer. Я пытаюсь создать AWS AMI для CentOS со встроенным Docker. Как видно из моего сценария упаковщика ниже, все, что я делаю, - это запускаю несколько yum команд, как описано в документации докера, чтобы установить докер.

{
    "builders": [
    {
        "type": "amazon-ebs",
        "profile": "digital",
        "source_ami": "ami-061b1560",
        "instance_type": "t2.micro",
        "ssh_username": "centos",
        "ami_name": "centos-docker {{timestamp}}"
    }
],

"provisioners": [{
    "type": "shell",
    "inline": [
        "sleep 30",
        "sudo yum install -y yum-utils device-mapper-persistent-data lvm2",
        "sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo",
        "sudo yum makecache fast",
        "sudo yum install docker-ce"
    ]
}]

}

Затем я использую AMI, созданный приведенным выше сценарием, в моем сценарии terraform и добавляю local-exec Provisioners для запуска службы docker.

provider "aws" {
   profile = "digital"
   region = "eu-west-1" 
}

resource "aws_instance" "chat-server" {
    ami = "ami-XXXXXX" 
    instance_type = "t2.micro"

    provisioner "local-exec" {
        command = "sudo systemctl start docker"
    }
}

Когда я запускаю terraform apply, он зависает вокруг команды, в которой пытается запустить службу докеров.

aws_instance.chat-server: Creating...
  ami:                          "" => "ami-609f6919"
  associate_public_ip_address:  "" => "<computed>"
  availability_zone:            "" => "<computed>"
  ebs_block_device.#:           "" => "<computed>"
  ephemeral_block_device.#:     "" => "<computed>"
  instance_state:               "" => "<computed>"
  instance_type:                "" => "t2.micro"
  ipv6_address_count:           "" => "<computed>"
  ipv6_addresses.#:             "" => "<computed>"
  key_name:                     "" => "<computed>"
  network_interface.#:          "" => "<computed>"
  network_interface_id:         "" => "<computed>"
  placement_group:              "" => "<computed>"
  primary_network_interface_id: "" => "<computed>"
  private_dns:                  "" => "<computed>"
  private_ip:                   "" => "<computed>"
  public_dns:                   "" => "<computed>"
  public_ip:                    "" => "<computed>"
  root_block_device.#:          "" => "<computed>"
  security_groups.#:            "" => "<computed>"
  source_dest_check:            "" => "true"
  subnet_id:                    "" => "<computed>"
  tenancy:                      "" => "<computed>"
  volume_tags.%:                "" => "<computed>"
  vpc_security_group_ids.#:     "" => "<computed>"
aws_instance.chat-server: Still creating... (10s elapsed)
aws_instance.chat-server: Still creating... (20s elapsed)
aws_instance.chat-server: Still creating... (30s elapsed)
aws_instance.chat-server: Provisioning with 'local-exec'...
aws_instance.chat-server (local-exec): Executing: /bin/sh -c "sudo 
systemctl start docker"
Password:aws_instance.chat-server: Still creating... (40s elapsed)
aws_instance.chat-server: Still creating... (50s elapsed)
aws_instance.chat-server: Still creating... (1m0s elapsed)
.
.
.
aws_instance.chat-server: Still creating... (9m0s elapsed)
aws_instance.chat-server: Still creating... (9m10s elapsed)

Interrupt received.
Please wait for Terraform to exit or data loss may occur.
Gracefully shutting down...
stopping apply operation...

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Что я здесь делаю не так?


person Suhas    schedule 06.08.2017    source источник


Ответы (1)


Вы используете неправильный провайдер, вам следует использовать remote-exec.

person Rickard von Essen    schedule 06.08.2017