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

`azapi_resource` uses `registry.terraform.io/hashicorp/azapi`

Open erelado opened this issue 2 years ago • 4 comments

Hello everyone, While using the resource azapi_resource inside a module, I have noticed that it requires registry.terraform.io/hashicorp/azapi, which obviously does not exist (azure/azapi and not hashicorp/azapi).

Parent module

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

provider "azapi" {
}
provider "azurerm" {
  features {}
}

module "app_service" {
  count                   = 2
  source                  = "../../modules/azure_appservices"
  resource_group_name     = var.resource_group_name
  resource_group_location = var.resource_group_location
  Common_tags             = var.Common_tags
  connection_strings      = var.connection_strings
  appsettings             = var.appsettings
  random_value            = var.random_value
  application_names       = var.application_names
  name                    = "testdan-${count.index}"
}

Child module

/* [Additional code...] */

resource "azapi_resource" "siteextension1" {

  type = "Microsoft.ContainerRegistry/registries@2020-11-01-preview"
  name = "AspNetCoreRuntime.5.0.x64"
  parent_id = azurerm_windows_web_app.example1.id
  }

/* [Additional code...] */

Running the terraform providers command reveals this odd behavior, which prevents the option to succeed with terraform init.

.
├── provider[registry.terraform.io/azure/azapi]
├── provider[registry.terraform.io/hashicorp/azurerm]
└── module.app_service
    ├── provider[registry.terraform.io/hashicorp/azurerm]
    └── provider[registry.terraform.io/hashicorp/azapi]

erelado avatar Oct 12 '22 06:10 erelado

Hi @E-RELevant ,

Thank you for taking time to report this issue!

Please add the following config in your tf files before running terraform init. It tells terraform which azapi provider it should download.

terraform {
  required_providers {
    azapi = {
      source = "azure/azapi"
    }
  }
}

ms-henglu avatar Oct 12 '22 06:10 ms-henglu

Hi @E-RELevant ,

Thank you for taking time to report this issue!

Please add the following config in your tf files before running terraform init. It tells terraform which azapi provider it should download.

terraform {
  required_providers {
    azapi = {
      source = "azure/azapi"
    }
  }
}

My apologies for not mentioning it earlier, since it seems obvious that I do. This section is included, but it does not work. I've updated the original comment with the relevant information.

erelado avatar Oct 12 '22 07:10 erelado

yes, it seems required that the azapi source is specified in every (child) module where the azapi provider is used. I was expecting that specifying the source was only required in the root module.

cveld avatar Oct 12 '22 19:10 cveld

yes, it seems required that the azapi source is specified in every (child) module where the azapi provider is used. I was expecting that specifying the source was only required in the root module.

Can't count/foreach be used with azapi then? I find it quite odd.

erelado avatar Oct 17 '22 06:10 erelado

You can use count/foreach with azapi. It works well.

The requirement for having a provider constraint in each module is documented here.

jkroepke avatar Oct 31 '22 10:10 jkroepke

I'll close this issue, but feel free to reopen it if there's further question.

ms-henglu avatar Feb 17 '23 05:02 ms-henglu