thilinistg
thilinistg

Reputation: 417

Credential Failure while executing Terraform execution plan

I'm trying to execute a sample terraform plan given below.

# Configure the Microsoft Azure Provider
provider "azurerm" {
  subscription_id = "..."
  client_id       = "..."
  client_secret   = "..."
  tenant_id       = "..."
}

    # Create a resource group
    resource "azurerm_resource_group" "production" {
        name     = "production"
        location = "West US"
    }

    # Create a virtual network in the web_servers resource group
    resource "azurerm_virtual_network" "network" {
      name                = "productionNetwork"
      address_space       = ["10.0.0.0/16"]
      location            = "West US"
      resource_group_name = "${azurerm_resource_group.production.name}"

      subnet {
        name           = "subnet1"
        address_prefix = "10.0.1.0/24"
      }

      subnet {
        name           = "subnet2"
        address_prefix = "10.0.2.0/24"
      }

      subnet {
        name           = "subnet3"
        address_prefix = "10.0.3.0/24"
      }
    }`enter code here`

I followed [1] to generate credentials via creating Active Directory application and used the correct subscription_id, client_id, client_secret, tenant_id in the above plan and executed 'terraform plan' against it. But I'm getting below error.

Error refreshing state: 1 error(s) occurred:

[1] https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/

Any idea on this?

Upvotes: 3

Views: 3367

Answers (1)

Vikram
Vikram

Reputation: 643

It seems like in terraform documentation, they haven't included the step of assigning role to the service principal. Follow these steps and it works.

1) Create the service principal through Azure CLI by following this link https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal-cli/ which assigns the role as well to the service principal 2) Go to Azure RM portal-->Active Directory -->App registration --> Create the key 3) Use the appropriate values from above in .tf file.

Then run the command terraform plan.

Upvotes: 2

Related Questions