Terraform remote state question

here are my 3 config files in question. It is not reading the remote state variable. It should put the vnet in a resource group called ‘network.RG’ but instead it creates a resource group called ‘data.terraform_remote_state.network.outputs.quan_netwk’ and put the new vnet there. What is going on here?

vnet.tf
#Remote State pulling data from bastion resource group state
data "terraform_remote_state" "network" {
backend = "azurerm"
config = {
storage_account_name = "terraformstatetracking"
container_name       = "bastionresourcegroups"
key                  = "terraform.terraformstate"
  }
}

#creating virtual network and putting that network in resource group created by 
bastion.tf file
module "quannetwork" {
source              = "Azure/network/azurerm"
resource_group_name = "data.terraform_remote_state.network.outputs.quan_netwk"
location            = "centralus"
vnet_name           = "quan"
address_space       = "10.0.0.0/16"
subnet_prefixes     = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
subnet_names        = ["subnet1", "subnet2", "subnet3"]

tags                = {
                        environment = "quan"
                        costcenter  = "it"
                      }
}

terraform {
backend "azurerm" {
storage_account_name  = "terraformstatetracking"
container_name        = "quannetwork"
key                   = "terraform.terraformstate"
  }
}

outputs.tf
output "quan_netwk" {
description = "Quan Network Resource Group"
value       = "${azurerm_resource_group.network.id}"
}


resourcegroups.tf
# Create a resource group
#Bastion
resource "azurerm_resource_group" "cm" {
name     = "${var.prefix}cm.RG"
location = "${var.location}"
tags     = "${var.tags}"
}

#Bastion1
resource "azurerm_resource_group" "network" {
name     = "${var.prefix}network.RG"
location = "${var.location}"
tags     = "${var.tags}"
}

#bastion2
resource "azurerm_resource_group" "storage" {
name     = "${var.prefix}storage.RG"
location = "${var.location}"
tags     = "${var.tags}"
}

terraform {
backend "azurerm" {
storage_account_name  = "terraformstatetracking"
container_name        = "bastionresourcegroups"
key                   = "terraform.terraformstate"
  }
}

Hi @rjohnson318,

If you’re using Terraform 0.12, accessing variables no longer requires quotes or string interpolation. For your resource group, you can remove the quotes around data.terraform_remote_state.network.outputs.quan_netwk. This will allow it to access the data source instead of passing it as a name.

## Terraform 0.12 syntax
module "quannetwork" {
  ## omitted for clarity
  resource_group_name = data.terraform_remote_state.network.outputs.quan_netwk
}

Thanks for the reply @joatmon08. I am using Terraform v0.12.6. I made those changes and I have these errors:

The first error I can understand the name is too long I can go back and shorten everything to make it less than 80 characters. The second error I do not understand it only has letters,periods,underscores and an equals sign.

Error: "name" may not exceed 80 characters in length

 on .terraform/modules/quannetwork/Azure-terraform-azurerm-network- 
564155f/main.tf line 2, in resource "azurerm_resource_group" "network":
2: resource "azurerm_resource_group" "network" {



Error: "name" may only contain alphanumeric characters, dash, underscores, 
parentheses and periods

on .terraform/modules/quannetwork/Azure-terraform-azurerm-network-564155f/main.tf 
line 2, in resource "azurerm_resource_group" "network":
2: resource "azurerm_resource_group" "network" {

i fixed it. It was an oversight in my code.
in my outputs.tf file changed value = "${azurerm_resource_group.network.id}" to value ="${azurerm_resource_group.network.name}"