0

Following is .tf script

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")
  }
 }

This is a terraform file and in user_data = file("test.sh") the test sh looks like this

#! /bin/sh

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

Expected result : it should launch a instance with docker already installed , but unfortunately every time I run the script docker is not getting installed and I have to do it manually

Can anybody help me where I am lacking ?

1 Answer 1

1

Your user_data is inside the tags:

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

It should be outside:

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"
  }
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.