hashicorp / terraform-provider-rancher

Terraform Rancher provider
https://www.terraform.io/docs/providers/rancher/
Mozilla Public License 2.0
35 stars 33 forks source link

rendered_docker_compose differs from original one #101

Open M1strall opened 4 years ago

M1strall commented 4 years ago

Hi there, It seems I've caught an issue with some interpolation of docker-compose that is done by rancher provider. I'm getting docker-compose.yml row: tag: "{{.ImageName}}/{{.Name}}/{{.ID}}" replaced with: tag: <no value>/<no value>/<no value>

To comment, this expression is not supposed to be interpolated, but preserved "as is", since this is a Splunk-driver expression.

Terraform Version

Terraform v0.11.14

Affected Resource(s)

docker-compose.yml

Terraform Configuration Files

resource "rancher_stack" "my-api" {
  name = "my-api"
  description = "API Stack"
  environment_id = "${var.rancher_environment_id}"
  start_on_create = "true"
  finish_upgrade = "true"
  docker_compose = "${file("${path.module}/docker-compose-api.yml")}"
  rancher_compose = "${file("${path.module}/rancher-compose-api.yml")}"
  scope = "user"

docker-compose.yml

version: '2'
services:
  my-api:
   #part of compose ommited for breavity
     logging:
       driver: splunk
       options:
        #some splunk env variables
         splunk-token: ${TOKEN_SPLUNK}
         splunk-url: 'https://input.mysplunk.com'
         tag: "{{.ImageName}}/{{.Name}}/{{.ID}}"

Expected Behavior

Docker-compose.yml should've been applied "as specified" for Rancher stack

Actual Behavior

Actually applied docker compose (showing up in rendered_docker_compose: "" => "" in diff) looks like this:

version: '2'
services:
  my-api:
   #part of compose ommited for breavity
     logging:
       driver: splunk
       options:
        #some splunk env variables
         splunk-token: ${TOKEN_SPLUNK}
         splunk-url: 'https://input.mysplunk.com'
         tag: <no value>/<no value>/<no value>

Steps to Reproduce

  1. terraform apply
raphink commented 4 years ago

I don't see why that would happen, as we do not interpolate this string. Is it the Rancher export action that causes it to be interpreted maybe?

greenu commented 4 years ago

Try to use go template's raw string:

tag: "{{`{{.ImageName}}`}}/{{`{{.Name}}`}}/{{`{{.ID}}`}}"