github.com/posener/terraform@v0.11.0-beta1.0.20171103235147-645df36af025/website/upgrade-guides/0-11.html.markdown (about)

     1  ---
     2  layout: "downloads"
     3  page_title: "Upgrading to Terraform 0.11"
     4  sidebar_current: "upgrade-guides-0-11"
     5  description: |-
     6    Upgrading to Terraform v0.11
     7  ---
     8  
     9  # Upgrading to Terraform v0.11
    10  
    11  Terraform v0.11 is a major release and thus includes some changes that
    12  you'll need to consider when upgrading. This guide is intended to help with
    13  that process.
    14  
    15  The goal of this guide is to cover the most common upgrade concerns and
    16  issues that would benefit from more explanation and background. The exhaustive
    17  list of changes will always be the
    18  [Terraform Changelog](https://github.com/hashicorp/terraform/blob/master/CHANGELOG.md).
    19  After reviewing this guide, we recommend reviewing the Changelog to check on
    20  specific notes about the resources and providers you use.
    21  
    22  This guide focuses on changes from v0.10 to v0.11. Each previous major release
    23  has its own upgrade guide, so please consult the other guides (available
    24  in the navigation) if you are upgrading directly from an earlier version.
    25  
    26  ## Interactive Approval in `terraform apply`
    27  
    28  Terraform 0.10 introduced a new mode for `terraform apply` (when run without
    29  an explicit plan file) where it would show a plan and prompt for approval
    30  before proceeding, similar to `terraform destroy`.
    31  
    32  Terraform 0.11 adopts this as the default behavior for this command, which
    33  means that for interactive use in a terminal it is not necessary to separately
    34  run `terraform plan -out=...` to safely review and apply a plan.
    35  
    36  The new behavior also has the additional advantage that, when using a backend
    37  that supports locking, the state lock will be held throughout the refresh,
    38  plan, confirmation and apply steps, ensuring that a concurrent execution
    39  of `terraform apply` will not invalidate the execution plan.
    40  
    41  A consequence of this change is that `terraform apply` is now interactive by
    42  default unless a plan file is provided on the command line. When
    43  [running Terraform in automation](/guides/running-terraform-in-automation.html)
    44  it is always recommended to separate plan from apply, but if existing automation
    45  was running `terraform apply` with no arguments it may now be necessary to
    46  update it to either generate an explicit plan using `terraform plan -out=...`
    47  or to run `terraform apply -auto-approve` to bypass the interactive confirmation
    48  step. The latter should be done only in unimportant environments.
    49  
    50  **Action:** For interactive use in a terminal, prefer to use `terraform apply`
    51  with out an explicit plan argument rather than `terraform plan -out=tfplan`
    52  followed by `terraform apply tfplan`.
    53  
    54  **Action:** Update any automation scripts that run Terraform non-interactively
    55  so that they either use separated plan and apply or override the confirmation
    56  behavior using the `-auto-approve` option.
    57  
    58  ## Relative Paths in Module `source`
    59  
    60  Terraform 0.11 introduces full support for module installation from
    61  [Terraform Registry](https://registry.terraform.io/) as well as other
    62  private, in-house registries using concise module source strings like
    63  `hashicorp/consul/aws`.
    64  
    65  As a consequence, module source strings like `"child"` are no longer
    66  interpreted as relative paths. Instead, relative paths must be expressed
    67  explicitly by beginning the string with either `./` (for a module in a child
    68  directory) or `../` (for a module in the parent directory).
    69  
    70  **Action:** Update existing module `source` values containing relative paths
    71  to start eith either `./` or `../` to prevent misinterpretation of the source
    72  as a Terraform Registry module.
    73  
    74  ## Interactions Between Providers and Modules
    75  
    76  Prior to Terraform 0.11 there were several limitations in deficiencies in
    77  how providers interact with child modules, such as:
    78  
    79  * Ancestor module provider configurations always overrode the associated
    80    settings in descendent modules.
    81  
    82  * There was no well-defined mechanism for passing "aliased" providers from
    83    an ancestor module to a descendent, where the descendent needs access to
    84    multiple provider instances.
    85  
    86  Terraform 0.11 changes some of the details of how each resource block is
    87  associated with a provider configuration, which may change how Terraform
    88  interprets existing configurations. This is notably true in the following
    89  situations:
    90  
    91  * If the same provider is configured in both an ancestor and a descendent
    92    module, the ancestor configuration no longer overrides attributes from
    93    the descendent and the descendent no longer inherits attributes from
    94    its ancestor. Instead, each configuration is entirely distinct.
    95  
    96  * Only unaliased provider configurations can be automatically inherited from
    97    ancestor modules. Aliased providers must be passed explicitly using
    98    [the new `providers` attribute](/docs/modules/usage.html#providers-within-modules).
    99  
   100  * When a module containing its own `provider` blocks is removed from its
   101    parent module, Terraform will no longer attempt to associate it with
   102    another provider of the same name in a parent module, since that would
   103    often cause undesirable effects such as attempting to refresh resources
   104    in the wrong region. Instead, the resources in the module resources must be
   105    explicitly destroyed _before_ removing the module, so that the provider
   106    configuration is still available: `terraform destroy -target=module.example`.
   107  
   108  The recommended design pattern moving forward is to place all explicit
   109  `provider` blocks in the root module of the configuration, and to pass
   110  providers explicitly to child modules so that the associations are obvious
   111  from configuration:
   112  
   113  ```hcl
   114  provider "aws" {
   115    region = "us-east-1"
   116    alias  = "use1"
   117  }
   118  
   119  provider "aws" {
   120    region = "us-west-1"
   121    alias  = "usw1"
   122  }
   123  
   124  module "example-use1" {
   125    source = "./example"
   126  
   127    providers = {
   128      "aws": "aws.use1",
   129    }
   130  }
   131  
   132  module "example-usw1" {
   133    source = "./example"
   134  
   135    providers = {
   136      "aws": "aws.usw1",
   137    }
   138  }
   139  ```
   140  
   141  With the above configuration, any `aws` provider resources in the module
   142  `./example` will use the us-east-1 provider configuration for
   143  `module.example-use1` and the us-west-1 provider configuration for
   144  `module.example-usw1`.
   145  
   146  When only default (non-aliased) providers are in use, automatic inheritance
   147  to child modules is still supported.
   148  
   149  **Action**: In existing configurations where both a descendent module and
   150  one of its ancestor modules both configure the same provider, copy any
   151  settings from the ancestor into the descendent because provider configurations
   152  now inherit only as a whole, rather than on a per-argument basis.
   153  
   154  **Action**: In existing configurations where a descendent module inherits
   155  _aliased_ providers from an ancestor module, use
   156  [the new `providers` attribute](/docs/modules/usage.html#providers-within-modules)
   157  to explicitly pass those aliased providers.
   158  
   159  **Action**: Consider refactoring existing configurations so that all provider
   160  configurations are set in the root module and passed explicitly to child
   161  modules.
   162  
   163  ## Error Checking for Output Values
   164  
   165  Prior to Terraform 0.11, if an error occured when evaluating the `value`
   166  expression within an `output` block then it would be silently ignored and
   167  the empty string used as the result. This was inconvenient because it made it
   168  very hard to debug errors within output expressions.
   169  
   170  To give better feedback, Terraform now halts and displays an error message
   171  when such errors occur, similar to the behavior for expressions elsewhere
   172  in the configuration.
   173  
   174  Unfortunately, this means that existing configurations may have erroneous
   175  outputs lurking that will become fatal errors after upgrading to Terraform 0.11.
   176  The prior behavior is no longer available; to apply such a configuration with
   177  Terraform 0.11 will require adjusting the configuration to avoid the error.
   178  
   179  **Action:** If any existing output value expressions contain errors, change these
   180  expressions to fix the error.