1

Relatively new to terraform. I am able to spin up servers but I am struggling with the bootstrapping. I have been trying variations of my shell script in user_data but nothing seems to work:

provider "aws" {
  profile =                 var.profile
  region =                  var.aws_region
}

resource "aws_instance" "Test_1" {
  ami = var.amis_ubuntu_18_04
  instance_type = var.instance_type_t2_micro
  subnet_id = var.public_subnets
  associate_public_ip_address = true

  security_groups = ["*****************"]
  
  user_data=<<EOF
  #!/bin/bash 
  sudo mkdir /var/test1
  EOF
  
  key_name = var.Keypair


  tags = {
    Name = "Test 1"
    Environment = var.environment_tag
    Owner = "Me"
    project = "Test 1"
  }
}
0

1 Answer 1

2

Your indentation is incorrect in the user_data. If you want to keep it you need to use -EOF, not EOF:

resource "aws_instance" "Test_1" {
  ami = var.amis_ubuntu_18_04
  instance_type = var.instance_type_t2_micro
  subnet_id = var.public_subnets
  associate_public_ip_address = true

  security_groups = ["*****************"]
  
  user_data=<<-EOF
  #!/bin/bash 
  sudo mkdir /var/test1
  EOF
  
  key_name = var.Keypair


  tags = {
    Name = "Test 1"
    Environment = var.environment_tag
    Owner = "Me"
    project = "Test 1"
  }
}
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.