skip to Main Content

I’m trying to get some resource ID’s from resources that were deployed by another terraform pipeline, by using a data block. For example, subnet ID’s for usage in a storage account block in azure.
But, I’m getting the same kind of error on all 4 data blocks that I’m trying:

data "azurerm_subnet" "data_subnet" {
  name = "DataSubnet"
  virtual_network_name = "vnet-${var.lztri}-${var.env}-${var.loc}${var.stage != "" ? "-" : ""}${var.stage}-01"
  resource_group_name = "rg-${var.lztri}-network-${var.env}${var.stage != "" ? "-" : ""}${var.stage}-${var.loc}"
}
 Error: Subnet: (Name "DataSubnet" / Virtual Network Name "vnet-phr-dev-weu-01" / Resource Group "rg-phr-network-dev-weu") was not found
 
   with data.azurerm_subnet.data_subnet,
   on main.tf line 12, in data "azurerm_subnet" "data_subnet":
   12: data "azurerm_subnet" "data_subnet" {

But if I look for the ‘not found’ resources, I’m able to find them in the portal.

2

Answers


  1. Chosen as BEST ANSWER

    Got this issue solved, in the azure devops console I got the errors, saying the resources were not found, but I executed that piece of code locally on my laptop, got the same error, but with an piece of extra info; it showed the subscriptionID where it was trying to find the resources. And this was wrong, this was the subscription of the SPN, not of the deployment. So I had to specify the subscription ID in the provider and it worked!


  2. Could you make sure you’re using an up-to-date AzureRm provider version?

    Also, could you check if the Service Principal you’re using to authenticate Terraform has enough privileges to see those resources?

    You want to scope the Terraform run to the correct one if you have multiple subscriptions.

    Without knowing more about your TF setup it’s hard to give you more detailed suggestions.

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