Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template_cloudinit_config adding headers in rendered user-data #12204

Closed
jonaskint opened this issue Feb 23, 2017 · 2 comments
Closed

template_cloudinit_config adding headers in rendered user-data #12204

jonaskint opened this issue Feb 23, 2017 · 2 comments

Comments

@jonaskint
Copy link

jonaskint commented Feb 23, 2017

Terraform Version

Terraform v0.8.7

Affected Resource(s)

  • template_cloudinit_config

Terraform Configuration Files

data "template_file" "controller" {
  template = "${file("${path.module}/template/controller_user_data.yml")}"

  vars {
    CA_PEM               = "${base64encode(var.ca-key)}"
    CA_CERT              = "${base64encode(var.ca-cert)}"
    ETCD_ENDPOINT        = "https://${var.etcd_endpoint}:2379"
    ETCD_DNS             = "${var.etcd_endpoint}"
    POD_NETWORK          = "172.16.0.0/16"
    K8S_VER              = "v1.5.2_coreos.0"
    HYPERKUBE_IMAGE_REPO = "quay.io/coreos/hyperkube"
    DNS_SERVICE_IP       = "172.17.0.10"
    SERVICE_IP_RANGE     = "172.17.0.0/24"
    NETWORK_PLUGIN       = "cni"
    REGION               = "${var.region}"
  }
}

data "template_cloudinit_config" "controller" {
  gzip          = false
  base64_encode = false

  part {
    content = "${data.template_file.controller.rendered}"
  }
}

resource "aws_instance" "controller" {
  ami           = "${var.ami}"
  instance_type = "${var.instance_type}"
  count         = "${var.count}"

  subnet_id = "${element(var.subnet_ids, count.index)}"

  # Prevent terraform booboos where the etcd cluster gets deleted. Now we need to delete them manually.
  //  disable_api_termination              = "true"
  disable_api_termination = "false"

  instance_initiated_shutdown_behavior = "stop"

  key_name             = "${var.key_name}"
  user_data            = "${data.template_cloudinit_config.controller.rendered}"
  security_groups      = ["${aws_security_group.controller.id}"]
  iam_instance_profile = "${aws_iam_instance_profile.controller.id}"

  root_block_device {
    volume_size           = 40
    volume_type           = "gp2"
    delete_on_termination = true
  }

  tags {
    Name        = "${var.name}-controller${count.index}"
    Environment = "${var.environment}"
    Region      = "${var.region}"
    Os          = "ContainerLinux"
  }

  lifecycle {
    create_before_destroy = true
    ignore_changes        = ["security_groups", "user_data"]
  }
}

Expected Behavior

Content of user-data through AWS console

#cloudconfig
...

Actual Behavior

Actual content of user-data through AWS console

Content-Type: multipart/mixed; boundary="MIMEBOUNDARY"
MIME-Version: 1.0
--MIMEBOUNDARY
Content-Transfer-Encoding: 7bit
Content-Type: text/plain
Mime-Version: 1.0

#cloud-config
...

Steps to Reproduce

Had an oversized user-data file that was being used through a simple 'template_file' data resource and because of the AWS limit in the api, I started using 'template_cloudinit_config' data resource to make it more compact. After the apply, I noticed the node was stuck during initialisation and I could not retrieve the user-data through the AWS console.

So I did a second apply with gzip and base64 turned off and the half of my user-data file in order to trouble shoot the 'template_cloudinit_config' resource and noticed the extra headers in the user-data through the AWS console (vm didn't come up either and was stuck during init).

Important Factoids

AWS ec2 instance

@jonaskint
Copy link
Author

jonaskint commented Apr 17, 2017

I've been reading through the code from builtin/providers/template/datasource_clopudinit_config.go and I was wondering why the Content-Type is being set 2 times. One time in the multipart writer and one time in the headers. Is this related?

@ghost
Copy link

ghost commented Apr 9, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants