terraform-provider-fastly icon indicating copy to clipboard operation
terraform-provider-fastly copied to clipboard

Unclear output of plan/apply during custom VCL

Open giorgiosironi opened this issue 7 years ago • 2 comments

Terraform Version

Terraform 0.11.7 Fastly Provider 0.1.4

Affected Resource(s)

fastly_service_v1

Terraform Configuration Files

{
  "resource": {
    "fastly_service_v1": {
      "fastly-cdn": {
        "domain": [
          {
            "name": "vcltest--cdn-gateway.elifesciences.org"
          }
        ],
        "name": "api-gateway--vcltest",
        "vcl": [
          {
            "content": "${file(\"gzip-by-regex.vcl\")}",
            "name": "gzip-by-regex"
          },
          {
            "content": "${file(\"main.vcl\")}",
            "main": true,
            "name": "main"
          }
        ],
        "force_destroy": true,
        "backend": {
          "name": "api-gateway--vcltest",
          "ssl_check_cert": true,
          "ssl_cert_hostname": "vcltest--gateway.elifesciences.org",
          "address": "vcltest--gateway.elifesciences.org",
          "use_ssl": true,
          "port": 443
        }
      }
    }
  }
}

Debug Output

https://gist.github.com/giorgiosironi/1886c616f69287cfc6a45fdf670240f3

Expected Behavior

A difference of the VCL files content should be shown? Not sure.

Actual Behavior

Terraform will perform the following actions:                                                                                     

  ~ fastly_service_v1.fastly-cdn
2018/05/11 14:53:32 [DEBUG] command: asking for input: "Do you want to perform these actions?"
      vcl.146061381.content:  "\n        if ((beresp.status == 200 || beresp.status == 404) && (beresp.http.content-type ~ \"(\\+json)\\s*(
$|;)\" || req.url ~ \"\\.(css|js|html|eot|ico|otf|ttf|json|svg)($|\\?)\" ) ) {\n          # always set vary to make sure uncompressed versi
ons dont always win\n          if (!beresp.http.Vary ~ \"Accept-Encoding\") {\n            if (beresp.http.Vary) {\n              set beres
p.http.Vary = beresp.http.Vary \", Accept-Encoding\";\n            } else {\n              set beresp.http.Vary = \"Accept-Encoding\";\n   
         }\n          }\n          if (req.http.Accept-Encoding == \"gzip\") {\n            set beresp.gzip = true;\n          }\n        }
\n        " => ""
      vcl.146061381.main:     "false" => "false"
      vcl.146061381.name:     "gzip-by-regex" => ""
      vcl.35407642.content:   "\n    sub vcl_recv {\n      #FASTLY recv\n\n      if (req.request != \"HEAD\" && req.request != \"GET\" && r
eq.request != \"FASTLYPURGE\") {\n        return(pass);\n      }\n\n      return(lookup);\n    }\n\n    sub vcl_fetch {\n      include \"gz
ip-by-regex\"\n\n      #FASTLY fetch\n\n      if ((beresp.status == 500 || beresp.status == 503) && req.restarts < 1 && (req.request == \"G
ET\" || req.request == \"HEAD\")) {\n        restart;\n      }\n\n      if (req.restarts > 0) {\n        set beresp.http.Fastly-Restarts = 
req.restarts;\n      }\n\n      if (beresp.http.Set-Cookie) {\n        set req.http.Fastly-Cachetype = \"SETCOOKIE\";\n        return(pass)
;\n      }\n\n      if (beresp.http.Cache-Control ~ \"private\") {\n        set req.http.Fastly-Cachetype = \"PRIVATE\";\n        return(pa
ss);\n      }\n\n      if (beresp.status == 500 || beresp.status == 503) {\n        set req.http.Fastly-Cachetype = \"ERROR\";\n        set
 beresp.ttl = 1s;\n        set beresp.grace = 5s;\n        return(deliver);\n      }\n\n      if (beresp.http.Expires || beresp.http.Surrog
ate-Control ~ \"max-age\" || beresp.http.Cache-Control ~ \"(s-maxage|max-age)\") {\n        # keep the ttl here\n      } else {\n        # 
apply the default ttl\n        set beresp.ttl = 3600s;\n      }\n\n      return(deliver);\n    }\n\n    sub vcl_hit {\n      #FASTLY hit\n\
n      if (!obj.cacheable) {\n        return(pass);\n      }\n      return(deliver);\n    }\n\n    sub vcl_miss {\n      #FASTLY miss\n    
  return(fetch);\n    }\n\n    sub vcl_deliver {\n      #FASTLY deliver\n      return(deliver);\n    }\n\n    sub vcl_error {\n      #FASTL
Y error\n    }\n\n    sub vcl_pass {\n      #FASTLY pass\n    }\n\n    sub vcl_log {\n      #FASTLY log\n    }" => ""
      vcl.35407642.main:      "true" => "false"
      vcl.35407642.name:      "main" => ""
      vcl.3971786474.content: "" => "053fc68844dddf1304514127ccac13fb253edc88"
      vcl.3971786474.main:    "" => "true"
      vcl.3971786474.name:    "" => "main"
      vcl.751199481.content:  "" => "82a663ca3ed1f63352fb1f3b348bd43fc9c34b7e"
      vcl.751199481.main:     "" => "false"
      vcl.751199481.name:     "" => "gzip-by-regex"

It seems the VCL snippets (one main and one not) are being removed and added again, which is fine. But I would expect to see what am I adding, this hash appears instead. In fact I see the full strings in the removed VCL snippets.

Not sure if anything can be done in a provider about the \n as it may be how Terraform shows multiline strings.

Steps to Reproduce

  1. terraform apply

Important Factoids

Requires a Fastly account with custom VCL enabled. I'm available to do a patch if someone can point me in the right direction.

giorgiosironi avatar May 11 '18 14:05 giorgiosironi

couple of things, as i have been doing a ton of TF and fastly work recently. It seems like you are importing existing resources from console to tf and want it to match what you currently have running?

So, the string it outputs is what the plan reads, since it pulling from a file, its not going to show the actual text of the file. Often i have found that, especially in the custom vcl, changes are due to spacing differences, or new lines at the begining or end of the file (and yes, the \n is the new line character). You see the current vcl, beasue its pulling the vcl text directly from the api, and not parsing a file to get it.

what i have been doing is when im first doing an import, to copy/paste the vcl from the console into a window of my text editor, and do a diff with my .vcl file. if the only changes are spacing, ill copy/paste the ouptut from the console to my vcl file, and it usually fixes the plan changes, or just ru apply at that point since it wont really change anything for the negative. Sometimes it doesnt though, so just understand when the spacing, or escaping done from the file > fastly, matters or not.

tenzone avatar May 12 '18 14:05 tenzone

It seems like you are importing existing resources from console to tf and want it to match what you currently have running?

No, the resources are existing because they were created with a slightly different Terraform configuration a few minutes before I ran into this.

So, the string it outputs is what the plan reads, since it pulling from a file, its not going to show the actual text of the file. Often i have found that, especially in the custom vcl, changes are due to spacing differences, or new lines at the begining or end of the file (and yes, the \n is the new line character). You see the current vcl, beasue its pulling the vcl text directly from the api, and not parsing a file to get it.

Makes sense, it could be a technical limitation. If this is a general Terraform behavior, it could make a string value that looks like an hash indistinguishable from the hash of a file's content, right?

giorgiosironi avatar May 13 '18 11:05 giorgiosironi

Closing as stale. Please open a new issue after testing with the latest Terraform provider if this is still an issue. Thanks.

Integralist avatar Sep 28 '22 14:09 Integralist