Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure backend and provider as a module: config error on tf12 #712

Closed
KevDBG opened this issue May 27, 2019 · 3 comments
Closed

Azure backend and provider as a module: config error on tf12 #712

KevDBG opened this issue May 27, 2019 · 3 comments

Comments

@KevDBG
Copy link

KevDBG commented May 27, 2019

Hello,

Terraform version: 0.11.14
Terragrunt version : 0.18.6

I try to create a module with provider and backend configuration for azure (to have a dry code). I give you my code to explain my context and the problem.

My project is ordered like that:

live
__project
____vnet
______terraform.tfvars
____terraform.tfvars
modules
__provider
____provider.tf

provider.tf:

provider "azurerm" {
  location = "${var.azure_location}"
}

terraform {
  # The configuration for this backend will be filled in by Terragrunt
  backend "azurerm" {}
}

terraform.tfvars in the project directory:

terragrunt = {
  remote_state {
    backend = "azurerm"
    config {
      storage_account_name         = "account"
      container_name               = "xxxxx-container"
      key                          = "xxx.terraform.tfstate"
    }
  }
  terraform {
    source = "${path_relative_from_include()}/../../modules//provider"

    extra_arguments "common_var" {
      commands = [
        "apply",
        "plan",
        "import",
        "push",
        "refresh"
      ]
      optional_var_files = [
        "${get_tfvars_dir()}/${path_relative_from_include()}/common.tfvars"
      ]
    }
  }

}

terraform.tfvars in the vnet directory:

terragrunt = {
  # Terragrunt will copy the Terraform configurations specified by the source parameter, along with any files in the
  # working directory, into a temporary folder, and execute your Terraform commands in that folder.

  # Include all settings from the root terraform.tfvars file
  include = {
    path = "${find_in_parent_folders()}"
  }
}

In terraform version: 0.11.14, it's works but i have a specific bug with Azurerm provider and the backend lock (it's fixed in version 0.12.0 -> hashicorp/terraform#17046).

So, i try the new stable terraform version 0.12, and now the problem is on terragrunt side. In the terragrunt documentation, it's said that we have to add a // in the module source directory, and we have a warning alert from terraform ->

"Terraform initialized in an empty directory" warning, but you can safely ignore it.)

But with the last terraform version, it's not a warning but an error. So the copy failed:

[terragrunt] 2019/05/27 11:03:34 Error with plan: [terragrunt] [/terraform/azure/live/XXXX] 2019/05/27 11:03:34 Initializing remote state for the azurerm backend
[terragrunt] [/terraform/azure/live/XXXX] 2019/05/27 11:03:34 Running command: terraform init -backend-config=storage_account_name=XXXXX -backend-config=container_name=XXXXX-state-container -backend-config=key=XXXX.terraform.tfstate -get=false -get-plugins=false -backend=false -from-module=file://terraform/azure/modules -no-color /terraform/azure/live/XXXX/.terragrunt-cache/sGJ15K7r-s1DuFOsQZYEdYvS-Ms/pW4UMbcl9y3ALw2i0wz42jRhujQ
Copying configuration from "file:/terraform/azure/modules"...

Error: Can't populate non-empty directory

The target directory
.terragrunt-cache/sGJ15K7r-s1DuFOsQZYEdYvS-Ms/pW4UMbcl9y3ALw2i0wz42jRhujQ is
not empty, so it cannot be initialized with the -from-module=... option.

Any ideas ? or change on terragrunt side ?

Many thanks,

@KevDBG
Copy link
Author

KevDBG commented May 27, 2019

I thinks it's related to #466 no ?

I just discover this issue...

@yorinasub17
Copy link
Contributor

Yup we haven't upgraded to be Terraform 12 compatible yet. You can follow that thread for the progress. There is one open discussion that needs to be resolved before we can get started on it. Sorry that I don't have a better answer here...

@yorinasub17
Copy link
Contributor

I am going to close this as duplicate.

@yorinasub17 yorinasub17 changed the title Azure backend and provider as a module Azure backend and provider as a module: config error on tf12 May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants