【问题标题】:unable to launch docker while creating instance with terraform script使用 terraform 脚本创建实例时无法启动 docker
【发布时间】:2021-06-19 20:13:14
【问题描述】:

以下是 .tf 脚本

resource "aws_instance" "zk" {
  ami           = var.ami_id_zk
  instance_type = var.instance_type
  count         = "1"
  vpc_security_group_ids=[aws_security_group.allow_ssh.id]
  key_name = var.key_name
  subnet_id = aws_subnet.public_1.id
  tags = {
    Name = "Zookeper"
  user_data = file("test.sh")
  }
 }

这是一个 terraform 文件,在 user_data = file("test.sh") 中,测试 sh 看起来像这样

#! /bin/sh

sudo apt-get update -y
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker

预期结果:它应该启动一个已安装 docker 的实例,但不幸的是,每次我运行脚本时,都没有安装 docker,我必须手动安装

谁能帮我解决我的不足?

【问题讨论】:

    标签: amazon-web-services docker terraform devops user-data


    【解决方案1】:

    您的user_data 在标签内

      tags = {
        Name = "Zookeper"
      user_data = file("test.sh")
      }
    

    应该在外面:

    resource "aws_instance" "zk" {
      ami           = var.ami_id_zk
      instance_type = var.instance_type
      count         = "1"
      vpc_security_group_ids=[aws_security_group.allow_ssh.id]
      key_name = var.key_name
      subnet_id = aws_subnet.public_1.id
    
      user_data = file("test.sh")
    
      tags = {
        Name = "Zookeper"
      }
     }
    

    【讨论】:

    • @NiladriDey 没问题。如果答案有帮助,我们将不胜感激。
    猜你喜欢
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 2021-12-12
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 2018-01-13
    相关资源
    最近更新 更多