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

How to find status/error log on the data template_file. #20514

Closed
sampcoug opened this issue Feb 28, 2019 · 10 comments
Closed

How to find status/error log on the data template_file. #20514

sampcoug opened this issue Feb 28, 2019 · 10 comments
Labels

Comments

@sampcoug
Copy link

sampcoug commented Feb 28, 2019

Terraform Version

Terraform v0.11.11

Terraform Configuration Files

data "template_file" "ct" {
  count = "${var.count}"
  depends_on  = ["data.template_file.etcd_discovery_url"]
  template = "${file("container-linux-config_igntion2.2.0.tpl")}"
  vars {
    hostname = "${var.hostname}"
    shortname = "${var.shortname}"
    docker_repo = "${var.docker_repo}"
    message = "${var.message}"
    etcd_discovery_url = "${file("${var.etcd_discovery_token_file_path}")}",
  }
}

Debug Output

Crash Output

Terraform runs successfully

Expected Behavior

The template file should get loaded during the Terraform run and complete the configuration desired.

Actual Behavior

Terraform run completed but template_file failed to run and there are no errors to see what went wrong.

Steps to Reproduce

Please list the full steps required to reproduce the issue, for example:

  1. Create a data template file with the configuration below:
systemd:
  units:
    - name: update-engine.service         #disable autoupdates that result in autoreboot
      mask: true
    - name: locksmithd.service            #disable autoupdates that result in autoreboot
      mask: true
  1. Add the piece below to your terraform script to include the template file:
data "template_file" "ct" {
  count = "${var.count}"
  depends_on  = ["data.template_file.etcd_discovery_url"]
  template = "${file("container-linux-config_igntion2.2.0.tpl")}"
  vars {
    hostname = "${var.hostname}"
    shortname = "${var.shortname}"
    docker_repo = "${var.docker_repo}"
    message = "${var.message}"
    etcd_discovery_url = "${file("${var.etcd_discovery_token_file_path}")}",
  }
}
  1. terraform init
  2. terraform plan
  3. terraform apply

Additional Context

@sampcoug
Copy link
Author

Found a way to enable verbose logging but still not understanding why the template_file failed to run.
https://www.terraform.io/docs/configuration/environment-variables.html

@mildwonkey
Copy link
Contributor

Hi @sampcoug, I formatted your comment so it's a bit easier to read, but did not change any of the content.

It would help if you could update this with the rest of your terraform configuration files so we can see how you are using the rendered template. The output from terraform plan/apply would be helpful, too.

@mildwonkey mildwonkey added the waiting-response An issue/pull request is waiting for a response from the community label Mar 1, 2019
@sampcoug
Copy link
Author

sampcoug commented Mar 1, 2019

Hi @mildwonkey , thank you so much for your response. Below is my terraform configuration file(main.tf).

#Specify the provider
provider "google" {
  project = "xxx"
  #region  = "xxx"
  #zone    = "xxx"
}


terraform {
  backend "gcs" {
    bucket  = "xxx"
    prefix  = "xxx"
    credentials = "xxx"
  }
}

data "template_file" "ct" {
  count = "${var.count}"
  depends_on  = ["data.template_file.etcd_discovery_url"]
  template = "${file("xxx.tpl")}"
  vars {
    hostname = "${var.xxx}"
    shortname = "${var.xxx}"
    shortnamexxx = "${var.xxx}"
    shortnametxxxe = "${var.xxx}"
    docker_repo = "${var.xxx}"
    gcp_region = "${var.xxx}"
    message = "${var.xxx}"
    etcd_discovery_url = "${file("${var.xxx}")}",
  }
}

data "ct_config" "service" {
  pretty_print = true
  platform = "gce"
  content      = "${data.template_file.ct.rendered}"
}

data "template_file" "etcd_discovery_url" {
    template = "${file("/dev/null")}"
}

resource "null_resource" "etcd" {
  provisioner "local-exec" {
    command = "curl https://discovery.etcd.io/new?size=${var.count} > ${var.etcd_discovery_token_file_path}"
  }
}



#Create a new instance
resource "google_compute_instance" "vm_instance1" {
name         = "${var.xxx}"
machine_type = "${var.machine_type}"
zone         = "xxx"



  boot_disk {
    initialize_params {
      image = "coreos-cloud/coreos-stable-1911-4-0-v20181127"
    }
  }

  network_interface {
    #network = "xxx"
    subnetwork = "xxx"
    access_config = {
      // Ephemeral IP
    }
  }
}

#Create a new instance
resource "google_compute_instance" "vm_instance2" {
name         = "${var.env_prefix}"
machine_type = "${var.machine_type}"
zone         = "xxx"



  boot_disk {
    initialize_params {
      image = "coreos-cloud/coreos-stable-1911-4-0-v20181127"
    }
  }

  network_interface {
    #network = "xxx"
    subnetwork = "xxx"
    access_config = {
      // Ephemeral IP
    }
  }

}

@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Mar 1, 2019
@mildwonkey
Copy link
Contributor

Tip: you can use triple backticks before and after your text to format it as code blocks :)

@sampcoug
Copy link
Author

sampcoug commented Mar 1, 2019

Ah.. I was wondering how you were formatting. I will remember for next time. Tx!

@mildwonkey
Copy link
Contributor

Thank you for the additional information!

Based on the configuration you shared, I am not certain what you expect to happen with the template_files. You have three data sources, but none of them are referenced in your resources. Is there something missing from the configuration you've shared?

If not, here is an example of how to use the ct_config data source from the terraform-provider-ctdocumentation:

resource "aws_instance" "worker" {
  user_data = "${data.ct_config.worker.rendered}"
}

@sampcoug
Copy link
Author

sampcoug commented Mar 1, 2019

Thanks! Eyeballing at my configs again, I noticed that I am missing the following user_data reference on my "google_compute_instance" resource.

user_data = "${element(data.ct_config.service.*.rendered, count.index)}"

Something like this may be? I will try and see hows it works.

resource "google_compute_instance" "vm_instance1" {
name         = "${var.xxx}"
machine_type = "${var.machine_type}"
zone         = "xxx"
user_data = "${element(data.ct_config.service.*.rendered, count.index)}"

@sampcoug
Copy link
Author

sampcoug commented Mar 1, 2019

I am getting the following error when I run terraform plan.

Error: google_compute_instance.vm_instance1: : invalid or unknown key: user_data
Error: google_compute_instance.vm_instance2: : invalid or unknown key: user_data

Similar setup has worked for me for AWS.
According to the documentation online: https://www.terraform.io/docs/providers/template/index.html
This config should be cloud provider agnostic? Any ideas?

@mildwonkey
Copy link
Contributor

The user_data attribute is provider-specific, and not available for google_compute_instance: https://www.terraform.io/docs/providers/google/r/compute_instance.html

I'm going to close this issue, since we answered your specific question about rendering templates.

If you need further help with your configuration, you can open a new issue, but it's generally better to use one of the community forums where there are far more people ready to help.

Cheers!

@ghost
Copy link

ghost commented Mar 29, 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 Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants