So I am trying to connect Terraform to Azure Gov but it seems like the environment in the code is not being read. Or I am just way off with this any help will be greatly appreciated.
Here is the code, very basic just trying to get it to connect and store something in the statefile.
terraform {
backend "azurerm" {
#resource_group_name = "terraform-test"
storage_account_name = "terraformstate01"
container_name = "tstate01"
key = "terraform.tfstate"
access_key = "ACCESS_KEY_GOES_HERE"
}
}
# Configure the Azure provider
provider "azurerm" {
# The "feature" block is required for AzureRM provider 2.x.
# If you are using version 1.x, the "features" block is not allowed.
version = "2.76.0"
environment = "usgovernment"
features {}
}
resource "azurerm_resource_group" "state-demo-secure" {
name = "state-demo"
location = "usgovvirginia"
}
What is going on here also attached is the error I get when running Terraform init.
Initializing the backend...
╷
│ Error: Failed to get existing workspaces: containers.Client#ListBlobs: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthenticationFailed" Message="Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:c5022f4e-c01e-0002-51f4-74a3d7000000\nTime:2021-07-09T18:55:41.1228617Z"```
As mentioned by Ken W MSFT in comments section, you need to set the Cloud Environment before calling the .tf file instead of calling it in azurerm provider.
If its public then there is no requirement to do so , but as you are trying to use exclusive clouds which are private you need to set the environment as required using azure CLI or azure powershell before working in that cloud.
Commands for CLI:
Command for Powershell:
Reference:
Azure Provider: Authenticating via the Azure CLI | Guides | hashicorp/azurerm | Terraform Registry