skip to Main Content

Just wondering if can someone able to assist to share some insights and lead me where to troubleshoot and fix the error below I just came across when I ran my Terraform Apply. I have TF code where the variable is set to default: "00000000-0000-0000-0000-000000000000". The intention is, If specified, identifies the landing zone resource deployment and correct placement in the Management Group hierarchy in our Azure environment.

Scripts for variable:

variable "subscription_id_landingzones" {
  type        = string
  description = "If specified, identifies the landing zone resource deployment and correct placement in the Management Group hierarchy."
  default     = "00000000-0000-0000-0000-000000000000"

    validation {
      condition     = can(regex("^[a-z0-9-]{36}$", var.subscription_id_landingzones)) || var.subscription_id_landingzones == ""
      error_message = "Value must be a valid Subscription ID (GUID)."
    }
}

locals {
   subscription_id_landingzones     = var.subscription_id_landingzones
}

provider "azurerm" {
skip_provider_registration = "true"
subscription_id = local.subscription_id_landingzones
   features {}
   alias = "landingzones"
}

Error Messages:

Error: populating Resource Provider cache: listing Resource Providers: loading results: unexpected status 404 (404 Not Found) with error: SubscriptionNotFound: The subscription ‘00000000-0000-0000-0000-000000000000’ could not be found.

troubleshoot RBAC permissions, secrets expiry and terraform files

2

Answers


  1. Chosen as BEST ANSWER

    in the Management Group, the SP has got Contributor role access. This role will also get inherited by the Subcriptions under that Management Group. I also tried to renew the client secret, eventhough it's not expired yet and updated the SP client secrets in the service connection config. FYI, I am using Azure Devops here. I re-ran the pipeline then and it's the same error.


  2. Unexpected status 404 (404 Not Found) with error: SubscriptionNotFound

    The issue mentioned is due to is either related to wrong subscription ID or User doesn’t have any RBAC permissions as per the requirement.

    As per Q&ADoc it seems the user doesn’t have necessary RBAC permission to read the subscription and if you’re using SP the check with the environment variables defined and updated the secret if it expires and create a new secret accordingly and update it.

    My RBAC permissions

    enter image description here

    Configuration:

    variable "subscription_id_landingzones" {
      type        = string
      description = "If specified, identifies the landing zone resource deployment and correct placement in the Management Group hierarchy."
      default     = "98bccad1-xxxx-xxxx-xxxx-78dfd797ff89"
    
      validation {
        condition     = can(regex("^[a-z0-9-]{36}$", var.subscription_id_landingzones)) || var.subscription_id_landingzones == ""
        error_message = "Value must be a valid Subscription ID (GUID)."
      }
    }
    
    locals {
      subscription_id_landingzones = var.subscription_id_landingzones
    }
    
    provider "azurerm" {
      skip_provider_registration = "true"
      subscription_id            = local.subscription_id_landingzones
      features {}
      alias = "landingzones"
    }
    
    resource "azurerm_resource_group" "example" {
      provider = azurerm.landingzones
      name     = "vinay-resources"
      location = "East US"
    }
    
    resource "azurerm_storage_account" "example" {
      provider                = azurerm.landingzones
      name                    = "evinayyysstorageacct"
      resource_group_name     = azurerm_resource_group.example.name
      location                = azurerm_resource_group.example.location
      account_tier            = "Standard"
      account_replication_type = "LRS"
    }
    

    Deployment:

    enter image description here

    enter image description here

    Refer:

    https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/overview

    azurerm_storage_account | Resources | hashicorp/azurerm | Terraform | Terraform Registry

    Difference between various contributor roles available in Azure and how to use it effectively? – Stack Overflow by User Sridevi – Stack Overflow

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search