github.com/hugorut/terraform@v1.1.3/website/docs/language/upgrade-guides/0-8.mdx (about) 1 --- 2 page_title: Upgrading to Terraform 0.8 3 description: Upgrading to Terraform v0.8 4 --- 5 6 # Upgrading to Terraform v0.8 7 8 Terraform v0.8 is a major release and thus includes some backwards 9 incompatibilities that you'll need to consider when upgrading. This guide is 10 meant to help with that process. 11 12 The goal of this guide is to cover the most common upgrade concerns and 13 issues that would benefit from more explanation and background. The exhaustive 14 list of changes will always be the 15 [Terraform Changelog](https://github.com/hugorut/terraform/blob/main/CHANGELOG.md). 16 After reviewing this guide, we recommend reviewing the Changelog to check on 17 specific notes about the resources and providers you use. 18 19 ## Newlines in Strings 20 21 Newlines are no longer allowed in strings unless it is a heredoc or an 22 interpolation. This improves the performance of IDE syntax highlighting 23 of Terraform configurations and simplifies parsing. 24 25 **Behavior that no longer works in Terraform 0.8:** 26 27 ``` 28 resource "null_resource" "foo" { 29 value = "foo 30 bar" 31 } 32 ``` 33 34 **Valid Terraform 0.8 configuration:** 35 36 ``` 37 resource "null_resource" "foo" { 38 value = "foo\nbar" 39 40 value2 = <<EOF 41 foo 42 bar 43 EOF 44 45 # You can still have newlines within interpolations. 46 value3 = "${lookup( 47 var.foo, var.bar)}" 48 } 49 ``` 50 51 **Action:** Use heredocs or escape sequences when you have a string with newlines. 52 53 ## Math Order of Operations 54 55 Math operations now follow standard mathematical order of operations. 56 Prior to 0.8, math ordering was simply left-to-right. With 0.8, `*`, `/`, and 57 `%` are done before `+`, `-`. 58 59 Some examples are shown below: 60 61 ``` 62 ${1+5*2} => 11 (was 12 in 0.7) 63 ${4/2*5} => 10 (was 10 in 0.7) 64 ${(1+5)*2} => 12 (was 12 in 0.7) 65 ``` 66 67 **Action:** Use parantheses where necessary to be explicit about ordering. 68 69 ## Escaped Variables in Templates 70 71 The `template_file` resource now requires that any variables specified 72 in an inline `template` attribute are now escaped. This _does not affect_ 73 templates read from files either via `file()` or the `filename` attribute. 74 75 Inline variables must be escaped using two dollar signs. `${foo}` turns into 76 `$${foo}`. 77 78 This is necessary so that Terraform doesn't try to interpolate the values 79 before executing the template (for example using standard Terraform 80 interpolations). In Terraform 0.7, we had special case handling to ignore 81 templates, but this would cause confusion and poor error messages. Terraform 82 0.8 requires explicitly escaping variables. 83 84 **Behavior that no longer works in Terraform 0.8:** 85 86 ``` 87 data "template_file" "foo" { 88 template = "${foo}" 89 90 vars { foo = "value" } 91 } 92 ``` 93 94 **Valid Terraform 0.8 template:** 95 96 ``` 97 data "template_file" "foo" { 98 template = "$${foo}" 99 100 vars { foo = "value" } 101 } 102 ``` 103 104 **Action:** Escape variables in inline templates in `template_file` resources. 105 106 ## Escape Sequences Within Interpolations 107 108 Values within interpolations now only need to be escaped once. 109 110 The exact behavior prior to 0.8 was inconsistent. In many cases, users 111 just added `\` until it happened to work. The behavior is now consistent: 112 single escape any values that need to be escaped. 113 114 For example: 115 116 ``` 117 ${replace(var.foo, "\\", "\\\\")} 118 ``` 119 120 This will now replace `\` with `\\` throughout `var.foo`. Note that `\` and 121 `\\` are escaped exactly once. Prior to 0.8, this required double the escape 122 sequences to function properly. 123 124 A less complicated example: 125 126 ``` 127 ${replace(var.foo, "\n", "")} 128 129 ``` 130 131 This does what you expect by replacing newlines with empty strings. Prior 132 to 0.8, you'd have to specify `\\n`, which could be confusing. 133 134 **Action:** Escape sequences within interpolations only need to be escaped 135 once. 136 137 ## New Internal Graphs 138 139 The core graphs used to execute Terraform operations have been changed to 140 support new features. These require no configuration changes and should work 141 as normal. 142 143 They were tested extensively during 0.7.x behind experimental 144 flags and using the shadow graph. However, it is possible that there 145 are still edge cases that aren't properly handled. 146 147 While we believe it will be unlikely, if you find that something is not 148 working properly, you may use the `-Xlegacy-graph` flag on any Terraform 149 operation to use the old code path. 150 151 This flag will be removed prior to 0.9 (the next major release after 0.8), 152 so please report any issues that require this flag so we can make sure 153 they become fixed. 154 155 ~> **Warning:** Some features (such as `depends_on` referencing modules) 156 do not work on the legacy graph code path. Specifically, any features 157 introduced in Terraform 0.8 won't work with the legacy code path. These 158 features will only work with the new, default graphs introduced with 159 Terraform 0.8.