Terraform Provider Access Properties

Question about about access properties in a Terraform provider block. Is it possible to call them in something else? For example, if I have the following:

provider "azurerm" {
  subscription_id = "some_di"
  features {}
}

Is it possible to get to the subscription_id value through something like azurerm.subscription_id?

Hi @donwlewis,

Terraform doesn’t expose the provider configuration values directly for use elsewhere. There are two alternatives here, depending on whether it’s a value you set or whether it’s something the provider determined itself:

  • If it’s a value you set, like in the example you showed here, you can factor the value out into a local value so you can use it in multiple places:

    locals {
      azure_subscription_id = "some_id"
    }
    
    provider "azurerm" {
      subscription_id = local.azure_subscription_id
    }
    
    # (and local.azure_subscription_id anywhere else
    # you need it, too.)
    
  • If it’s a value the provider determines for itself, the provider developer can choose to expose certain values via Data Sources.

    I don’t know the Azure provider well enough to have ready examples from that provider, but for example in the AWS provider there is aws_region which can retrieve the region the provider configuration is associated with, even if it was determined implicitly by a means such as the AWS_DEFAULT_REGION environment variable.

    Not all provider-selected settings are exposed via data sources in this way. Sometimes that’s an intentional decision on the part of the provider development team, such as the common decision not to expose whatever authentication credentials the provider is using. However, if you do need something that isn’t exposed this way, you can open a feature request with the provider developer to see if they would consider adding it.