hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.71k stars 9.55k forks source link

Unexpected EOF in user data #4706

Closed toddrosner closed 8 years ago

toddrosner commented 8 years ago

Periodically I receive the following error when destroying a stack. The user data is good, and if I run the destroy again, the error doesn't happen.

Error refreshing state: 2 error(s) occurred:

Any ideas?

toddrosner commented 8 years ago

This has now happened once during a plan apply.

Error applying plan:

2 error(s) occurred:

jen20 commented 8 years ago

Hi @toddrosner! Could you post a small example of the configuration which is exhibiting this problem? Presumably the templates are referenced by some resource which is being destroyed? Either way this is definitely a bug we should fix - thanks for reporting!

toddrosner commented 8 years ago

Hey @jen20

I have a few launch configs similar to the one below that call the user data

/*
  Adapters instances
*/

resource "aws_launch_configuration" "adapters" {
  image_id = "${lookup(var.amis, var.aws_region)}"
  instance_type = "m4.xlarge"
  iam_instance_profile = "${aws_iam_instance_profile.instance-profile.id}"
  key_name = "${lookup(var.aws_key_name, var.aws_region)}"
  security_groups = ["${aws_security_group.adapters.id}"]
  ebs_optimized = true
  user_data = "${template_file.userdata.rendered}"
  root_block_device {
    volume_type = "standard"
    volume_size = 50
    delete_on_termination = true
  }
  lifecycle {
    #create_before_destroy = true
  }
  depends_on = ["aws_internet_gateway.implementation", "aws_route53_zone.implementation", "aws_instance.saltmaster0", "aws_instance.saltmaster1"]
}

Then there's the VPN instance that calls the vpnuserdata

/*
  VPN instance
*/

resource "aws_instance" "vpn" {
  count = 1
  ami = "${lookup(var.vpn_amis, var.aws_region)}"
  instance_type = "t2.small"
  iam_instance_profile = "${aws_iam_instance_profile.instance-profile.id}"
  key_name = "${lookup(var.aws_key_name, var.aws_region)}"
  security_groups = ["${aws_security_group.vpn.id}"]
  subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
  associate_public_ip_address = true
  source_dest_check = false
  user_data = "${template_file.vpnuserdata.rendered}"
  tags {
    Implementation = "${var.implementation}"
    Project = "${var.project}"
    Customer = "${var.customer}"
    Environment = "${var.environment}"
    Role = "vpn"
    Name = "${var.customer}-${var.implementation}-${var.project}-vpn-${var.environment}"
  }
  depends_on = ["aws_internet_gateway.implementation"]
}

resource "aws_eip" "vpn" {
  instance = "${aws_instance.vpn.id}"
  vpc = true
  depends_on = ["aws_instance.vpn", "aws_internet_gateway.implementation"]
}

Then there's the template file

# Template for initial configuration scripts

resource "template_file" "userdata" {
  template = "userdata.tpl"
  vars {
    aws_account_name = "${var.aws_account_name}"
    aws_region = "${var.aws_region}"
    environment = "${var.environment}"
    customer = "${var.customer}"
    domain = "${var.domain}"
    implementation = "${var.implementation}"
    project = "${var.project}"
    vpc_cidr = "${var.vpc_cidr}"
    saltmaster0_private_ip = "${var.saltmaster0_private_ip}"
    saltmaster1_private_ip = "${var.saltmaster1_private_ip}"
    ad_dc0_ip = "${var.ad_dc0_ip}"
    ad_dc1_ip = "${var.ad_dc1_ip}"
  }
}

resource "template_file" "vpnuserdata" {
  template = "vpnuserdata.tpl"
  vars {
    aws_account_name = "${var.aws_account_name}"
    aws_region = "${var.aws_region}"
    environment = "${var.environment}"
    customer = "${var.customer}"
    domain = "${var.domain}"
    implementation = "${var.implementation}"
    project = "${var.project}"
    vpc_cidr = "${var.vpc_cidr}"
    openvpn_password = "${var.openvpn_password}"
  }
}

Fairly straight forward and nothing unusual, so I can't really see what would cause the issue. As previously mentioned, the user data has no problem 9 out of 10 times, but periodically I received the EOF errors.

toddrosner commented 8 years ago

This issue seems to be resolved with recent versions.

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.