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

Bug Report: management Terraform workspace erroring out after 6.1.0 upgrade #1144

Closed
c4milo opened this issue Sep 30, 2024 · 10 comments
Closed
Assignees

Comments

@c4milo
Copy link
Contributor

c4milo commented Sep 30, 2024

Screenshot 2024-09-30 at 2 53 34 PM
@c4milo
Copy link
Contributor Author

c4milo commented Sep 30, 2024

It seems the data source was introduced in #968, @matt-FFFFFF, any idea?

@c4milo c4milo changed the title Bug Report: management subscription Terraform workspace erroring out after 6.1.0 upgrade Bug Report: management Terraform workspace erroring out after 6.1.0 upgrade Sep 30, 2024
@matt-FFFFFF
Copy link
Member

Looks like you need to set up auth for the AzAPI provider?

@c4milo
Copy link
Contributor Author

c4milo commented Sep 30, 2024

ohh, @matt-FFFFFF is that a new requirement? we didn't have a provider block for it before. We use managed identities from our TFC workers.

@matt-FFFFFF
Copy link
Member

It's not new, AzAPI has been in the module for a while. It usually takes the same auth configuration as AzureRM, and it doesn't need a provider block like AzureRM does.

It is used for MG diag settings too so you could test with that.

Managed identity will work, but you need to configure AzAPI to use it. In this case you'll need to add a provider block. See here: https://registry.terraform.io/providers/Azure/azapi/latest/docs#use_msi

@matt-FFFFFF matt-FFFFFF self-assigned this Sep 30, 2024
@c4milo
Copy link
Contributor Author

c4milo commented Sep 30, 2024

Thanks a lot for the pointer @matt-FFFFFF! Here is how we fixed it, FWIW:

Before

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.84"
    }
  }
}

# Define the provider configuration
provider "azurerm" {
  features {}

  use_cli                    = false
  tenant_id                  = var.tenant_id
  subscription_id            = var.subscription_id_management
  skip_provider_registration = true
}

After

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.84"
    }

    azapi = {
      source  = "azure/azapi"
      version = "~> 1.15"
    }
  }
}

provider "azapi" {
  use_cli                    = false
  tenant_id                  = var.tenant_id
  subscription_id            = var.subscription_id_management
  skip_provider_registration = true
}

# Define the provider configuration
provider "azurerm" {
  features {}

  use_cli                    = false
  tenant_id                  = var.tenant_id
  subscription_id            = var.subscription_id_management
  skip_provider_registration = true
}

Terraform Cloud variables for the management workspace (workload identity):

Screenshot 2024-09-30 at 4 48 14 PM

@c4milo c4milo closed this as completed Sep 30, 2024
@matt-FFFFFF
Copy link
Member

Nice - yeah for workload identity federation (OIDC) all you need is tenant and client id.

@matt-FFFFFF
Copy link
Member

Also unless you have explicit resources in your root module you don't need the required provider entry. Terraform will get it from the loaded modules.

@c4milo
Copy link
Contributor Author

c4milo commented Sep 30, 2024

@matt-FFFFFF, we don't have explicit azapi resources, no. However, for some reason, Terraform didn't seem to pick them up, hence the error in the screenshot above. It worked once we explicitly configured it, as shown in the comment above.

@matt-FFFFFF
Copy link
Member

Fair enough. Glad it's working

@c4milo
Copy link
Contributor Author

c4milo commented Sep 30, 2024

Thanks to you 🙏🏻

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