hashicorp / terraform-provider-ignition

Terraform Ignition provider
https://www.terraform.io/docs/providers/ignition/
Mozilla Public License 2.0
38 stars 64 forks source link

Ignition template_file support #41

Closed julianxhokaxhiu closed 6 years ago

julianxhokaxhiu commented 6 years ago

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Terraform v0.11.7

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

data "template_file" "sonarqube_service" {
  template = <<EOF
    [Unit]
    Description=Sonarqube Container
    After=docker.service
    Requires=docker.service

    [Service]
    TimeoutStartSec=0
    Restart=always
    ExecStartPre=-/usr/bin/docker stop %n
    ExecStartPre=-/usr/bin/docker rm %n
    ExecStartPre=/usr/bin/docker pull sonarqube:alpine
    ExecStart=/usr/bin/docker run --rm
      --name sonarqube \
      -p 9000:${SONARQUBE_HTTPPORT} \
      -p 9092:9092 \
      -e SONARQUBE_JDBC_USERNAME=${SONARQUBE_JDBC_USERNAME} \
      -e SONARQUBE_JDBC_PASSWORD=${SONARQUBE_JDBC_PASSWORD} \
      -e SONARQUBE_JDBC_URL=${SONARQUBE_JDBC_URL} \
      sonarqube:alpine

    [Install]
    WantedBy=multi-user.target
  EOF

  vars {
    # DB
    SONARQUBE_JDBC_USERNAME = "foo"
    SONARQUBE_JDBC_PASSWORD = "bar"
    SONARQUBE_JDBC_URL      = "jdbc:postgresql://localhost/sonarqube"

    # HTTP
    SONARQUBE_HTTPPORT = "8080"
  }
}

data "ignition_systemd_unit" "sonarqube" {
  name = "sonarqube.service"
  content = "${data.template_file.sonarqube_service.rendered}"
}

data "ignition_config" "sonarqube" {
  systemd = [
    "${data.ignition_systemd_unit.sonarqube.id}",
  ]
}

Debug Output

Error: Error refreshing state: 1 error(s) occurred:

* data.ignition_systemd_unit.sonarqube: 1 error(s) occurred:

* data.ignition_systemd_unit.sonarqube: data.ignition_systemd_unit.sonarqube: invalid configuration:
error: invalid unit content: unexpected newline encountered while parsing option name

Expected Behavior

The ignition config should have been created. Systemd unit file is kept multiline for better readability.

Actual Behavior

The systemd unit file is not been accepted, instead the ignition provider expects the string to be one single line with \n characters inside of it.

Steps to Reproduce

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

  1. terraform apply
julianxhokaxhiu commented 6 years ago

After further investigations I found out this has nothing to do with your plugin, nor with terraform itself.

The issue is related to the fact that this line

ExecStart=/usr/bin/docker run --rm

is missing an ending \, and because of that the coreos systemd library that deserializes the unit returns that error.

All good :) Thanks and sorry for the noise.

I'll leave this issue here in case is helpful for someone else.