user_data不会在地形应用程序之后运行



我正在使用Terraform来打开一个Ec2实例,我想在那里执行一些命令。我在aws_instance资源的user_data中放入了一个bash文件,但该文件没有执行。

...
resource "aws_instance" "master" {
ami           = lookup(var.amis, var.region)
instance_type = var.master_instance_type
key_name      = "id_rsa_sdtd"
security_groups = [aws_security_group.SDTD_VPC_Security_Group.id]
subnet_id = aws_subnet.SDTD_VPC_Subnet.id
iam_instance_profile = "k8s-cluster-iam-master-role"
user_data = file("./master_config.sh")
}
...

地形图

...
+ tenancy                      = (known after apply)
+ user_data                    = "def16ed029e3ecb79f09f750c548beed53d7f60d"
+ volume_tags                  = (known after apply)
...

我的bash文件

#!/bin/bash
# Install kubeadm and Docker
sudo apt update && sudo apt -y upgrade
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo bash -c 'echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list'
sudo apt update
sudo apt install -y docker-ce kubelet kubeadm kubectl
...

您的问题中没有任何词语确认master_config.sh尚未执行。

下面的行并不意味着它还没有被执行。如果它不起作用,你肯定应该在评论中看到一个日志/var/log/cloud-init-output.log+ user_data = "def16ed029e3ecb79f09f750c548beed53d7f60d"

从我脑海中浮现的解决方案来看:

  • 使用以下格式的完整路径,而不是简单的file("./master_config.sh")。也许你包得不对
resource "aws_instance" "..." {
user_data = "${file("/../../master_config.sh")}"
...
}
  • 我建议您将templates_file用于此类活动,然后在配置中引用它
data "template_file" "user_data" {
template = "${file("/../../master_config.sh")}"
...
}

resource "aws_instance" "master" {
user_data = "${data.template_file.user_data.rendered}"
...
}

相关内容

  • 没有找到相关文章

最新更新