terraform-azurerm-caf icon indicating copy to clipboard operation
terraform-azurerm-caf copied to clipboard

Bug report: Missing required azurerm.vhub provider configuration?

Open sheeeng opened this issue 2 years ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Community Note

  • Please vote on this issue by adding a :thumbsup: reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Version of the module you are using

5.6.2

Rover Version

No response

Terraform Version

1.3.1

AzureRM Provider Version

3.25.0

Affected Resource(s)/Data Source(s)

azurerm_XX

Terraform Files

provider "azurerm" {
  alias = "vhub"
}

module "caf" {
  source  = "aztfmod/caf/azurerm"
  version = "5.5.0"

  global_settings = var.global_settings
  resource_groups = var.resource_groups
}

Terraform Configuration Files

# https://github.com/aztfmod/terraform-azurerm-caf/blob/main/examples/apim/101-api/configuration.tfvars

global_settings = {
  default_region = "region_norwayeast"
  regions = {
    region_norwayeast = "norwayeast"
  }
}

resource_groups = {
  resource_group_apimanagement = {
    name   = "alpha-dev"
    region = "norwayeast"
  }
}

Expected Behaviour

  • The terraform init should work properly.

Actual Behaviour

  • The terraform init failed with below error message.
│ Error: Missing required provider configuration
│ 
│   on main.tf line 22:
│   22: module "caf" {
│ 
│ The child module requires an additional configuration for provider hashicorp/azurerm, with the local name "azurerm.vhub".
│ 
│ Refer to the module's documentation to understand the intended purpose of this additional provider configuration, and then add an entry for
│ azurerm.vhub in the "providers" meta-argument in the module block to choose which provider configuration the module should use for that
│ purpose.

Steps to Reproduce

Important Factoids

No response

References

sheeeng avatar Oct 08 '22 18:10 sheeeng

Having the exact same problem also with only this main.tf (I'd expect that at least it init) :

main.tf :

provider "azurerm" {
  alias = "vhub"
}

module "caf" {
  source  = "aztfmod/caf/azurerm"
  version = "5.6.2"
  
  global_settings = var.global_settings
  resource_groups = var.resource_groups
}

tfvars :

global_settings = {
  default_region = "francecentral"
  regions = {
    region1 = "francecentral"
  }
}

resource_groups = {
  test = {
    name = "test_rg"
  }
}

lombare avatar Oct 10 '22 07:10 lombare

Found the regression point. The suggested workaround at #1338 did not work.

diff --git a/main.tf b/main.tf
index b6dc9c9..cd4f1cc 100644
--- a/main.tf
+++ b/main.tf
@@ -1,6 +1,10 @@
+provider "azurerm" {
+  alias = "vhub"
+}
+
 module "caf" {
   source  = "aztfmod/caf/azurerm"
-  version = "5.4.8"
+  version = "5.5.0"
 
   global_settings = var.global_settings
   resource_groups = var.resource_groups

sheeeng avatar Oct 11 '22 08:10 sheeeng

I'm not sure if my fix is really the "fix" yet, but I was finally able get a successful tf init by doing the following in my main.tf:

terraform {
    required_providers {
        azurerm = {
            source = "hashicorp/azurerm"
        }
    } 
}

provider "azurerm" {
    features {}
}

module "caf" {
    source = "aztfmod/caf/azurerm"
    version = "5.6.1"

    global_settings = var.global_settings
    resource_groups = var.resource_groups
    providers = {
        azurerm.vhub = azurerm
    }
}

jasonfare avatar Oct 13 '22 21:10 jasonfare

Thanks for sharing the workaround, @jasonfare!

It's seems like Cloud Adoption Framework is only compatible with AzureRM provider version 2. 😞

provider "azurerm" {
  features {}
}

module "caf" {
  source  = "aztfmod/caf/azurerm"
  version = "~> 5.6.2"

  providers = {
    azurerm.vhub = azurerm
  }

  global_settings = var.global_settings
  resource_groups = var.resource_groups
}

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 2.99" # "~> 3.27.0" # TODO: AzureRM version 3 does not work.
    }
  }
  required_version = ">= 1.3.1"
}

sheeeng avatar Oct 14 '22 08:10 sheeeng

Additional thing Because it dependent on 2.99.0 , we are not able to consume CAF module we get failure like these

│ Warning: Argument is deprecated
│
│   with module.example.module.api_management_custom_domain.azurerm_api_management_custom_domain.apim,
│   on ../modules/apim/api_management_custom_domain/module.tf line 1, in resource "azurerm_api_management_custom_domain" "apim":
│    1: resource "azurerm_api_management_custom_domain" "apim" {
│
│ `proxy` is deprecated and will be renamed to `gateway` in version 3.0 of the AzureRM provider
╵
╷
│ Error: Error in function call
│
│   on ../locals.tf line 319, in locals:
│  319:   object_id = coalesce(var.logged_user_objectId, var.logged_aad_app_objectId, try(data.azurerm_client_config.current.object_id, null), try(data.azuread_service_principal.logged_in_app.0.object_id, null))
│     ├────────────────
│     │ while calling coalesce(vals...)
│     │ data.azuread_service_principal.logged_in_app is empty tuple
│     │ data.azurerm_client_config.current.object_id is ""
│     │ var.logged_aad_app_objectId is null
│     │ var.logged_user_objectId is null
│
│ Call to function "coalesce" failed: no non-null, non-empty-string arguments.

Upon investigation on v2.99.0 , This piece of code generates empty value

data "azurerm_client_config" "current" {}


output logged_in_user_object_id {
  value = data.azurerm_client_config.current.object_id
}

provider "azurerm" {
  features {}
}


terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "2.99.0"
    }
  }
}

So since the result in emoty string the caf module "5.6.4" always fails on https://github.com/aztfmod/terraform-azurerm-caf/blob/main/locals.tf#L319 when tried to consume on stand alone manner..

sudhirpandey avatar Nov 28 '22 16:11 sudhirpandey

Roadmap: https://github.com/aztfmod/terraform-azurerm-caf/issues/1125

We are working on the provider upgrade and have already created a roadmap and a branch with the latest version of the provider. Note we also face some provider issues due to long running process failing (resources who need more than 1 hour to deploy). We are waiting for a provider upgrade before setting the target version for 5.7.0 https://github.com/hashicorp/terraform-provider-azurerm/issues/20867

Provider upgrade - (Preview non-production ready yet. Work in progress). you can check if the issue above is resolved. Note we take PR from the branch in-3.7.0 for the next preview. https://github.com/aztfmod/terraform-azurerm-caf/releases/tag/5.7.0-preview0

Now specifically to the issue with 2.99 and the object_id. There is a regression in 2.99 that is not able to pick the id of the principal running the Terraform deployment. So the workaround is to set this environment variable before you run the deployment:

For a user:

export TF_VAR_ logged_user_objectId=$(az ad signed-in-user show --query id -o tsv)

For other principals (MSI or Azure AD Apps, set the object_id

Open a new issue if the answer requires more details.

LaurentLesle avatar Apr 14 '23 00:04 LaurentLesle