Here is my main.tf file. Terraform init does not throw any errors, but when I try to apply , I get errors.
Azure Provider source and version being used
terraform {
required_providers {
azurerm = {
source = “hashicorp/azurerm”
version = “=2.46.0”
}
}
}
Configure the Microsoft Azure Provider
provider “azurerm” {
features {}
subscription_id = "####
tenant_id = “####”
}
locals {
azure_location = “East US”
}
resource “azurerm_resource_group” “primary_vnet_resource_group” {
name = “vnet-prod-002-eastus-001”
location = local.azure_location
}
resource “azurerm_virtual_network” “primary_vnet_virtual_network” {
name = “vnet_primary_eastus-001”
location = local.azure_location
resource_group_name = “azurerm_resource_group.primary_vnet_resource_group.name”
address_space = [“10.0.0.0/16”]
}
resource “azurerm_subnet” “aks-subnet” {
name = “snet-aks-prod-002-eastus-001”
location = local.azure_location
virtual_network_name = “primary_vnet_virtual_network.name”
resource_group_name = “azurerm_resource_group.primary_vnet_resource_group.name”
address_prefixes = [“10.0.1.0/24”]
}
resource “azurerm_subnet” “application-subnet” {
name = “snet-app-prod-002-eastus-001”
location = local.azure_location
virtual_network_name = “primary_vnet_virtual_network.name”
resource_group_name = “azurerm_resource_group.primary_vnet_resource_group.name”
address_prefixes = [“10.0.2.0/24”]
}
resource “azurerm_subnet” “postgres-subnet” {
name = “snet-postgres-prod-002-eastus-001”
location = local.azure_location
virtual_network_name = “primary_vnet_virtual_network.name”
resource_group_name = “azurerm_resource_group.primary_vnet_resource_group.name”
address_prefixes = [“10.0.3.0/24”]
}
And here are the errors:
azurerm_resource_group.primary_vnet_resource_group: Creating…
azurerm_subnet.aks-subnet: Creating…
azurerm_virtual_network.primary_vnet_virtual_network: Creating…
azurerm_subnet.application-subnet: Creating…
azurerm_subnet.postgres-subnet: Creating…
azurerm_resource_group.primary_vnet_resource_group: Creation complete after 1s [id=/subscriptions/256bc5b8-144d-4384-9286-e869fb7ce2c9/resourceGroups/vnet-prod-002-eastus-001]
╷
│ Error: Error Creating/Updating Virtual Network “vnet_primary_eastus-001” (Resource Group “azurerm_resource_group.primary_vnet_resource_group.name”): network.VirtualNetworksClient#CreateOrUpdate: Failure sending request: StatusCode=404 – Original Error: Code=“ResourceGroupNotFound” Message=“Resource group ‘azurerm_resource_group.primary_vnet_resource_group.name’ could not be found.”
│
│ with azurerm_virtual_network.primary_vnet_virtual_network,
│ on main.tf line 29, in resource “azurerm_virtual_network” “primary_vnet_virtual_network”:
│ 29: resource “azurerm_virtual_network” “primary_vnet_virtual_network” {
│
╵
╷
│ Error: Error Creating/Updating Subnet “snet-aks-prod-002-eastus-001” (Virtual Network “primary_vnet_virtual_network.name” / Resource Group “azurerm_resource_group.primary_vnet_resource_group.name”): network.SubnetsClient#CreateOrUpdate: Failure sending request: StatusCode=404 – Original Error: Code=“ResourceGroupNotFound” Message=“Resource group ‘azurerm_resource_group.primary_vnet_resource_group.name’ could not be found.”
│
│ with azurerm_subnet.aks-subnet,
│ on main.tf line 36, in resource “azurerm_subnet” “aks-subnet”:
│ 36: resource “azurerm_subnet” “aks-subnet” {
│
╵
╷
│ Error: Error Creating/Updating Subnet “snet-app-prod-002-eastus-001” (Virtual Network “primary_vnet_virtual_network.name” / Resource Group “azurerm_resource_group.primary_vnet_resource_group.name”): network.SubnetsClient#CreateOrUpdate: Failure sending request: StatusCode=404 – Original Error: Code=“ResourceGroupNotFound” Message=“Resource group ‘azurerm_resource_group.primary_vnet_resource_group.name’ could not be found.”
│
│ with azurerm_subnet.application-subnet,
│ on main.tf line 44, in resource “azurerm_subnet” “application-subnet”:
│ 44: resource “azurerm_subnet” “application-subnet” {
│
╵
╷
│ Error: Error Creating/Updating Subnet “snet-postgres-prod-002-eastus-001” (Virtual Network “primary_vnet_virtual_network.name” / Resource Group “azurerm_resource_group.primary_vnet_resource_group.name”): network.SubnetsClient#CreateOrUpdate: Failure sending request: StatusCode=404 – Original Error: Code=“ResourceGroupNotFound” Message=“Resource group ‘azurerm_resource_group.primary_vnet_resource_group.name’ could not be found.”
│
│ with azurerm_subnet.postgres-subnet,
│ on main.tf line 52, in resource “azurerm_subnet” “postgres-subnet”:
│ 52: resource “azurerm_subnet” “postgres-subnet” {
│
╵
azureuser@vm-velero-testing-prod-003:/terraform-testing$ sudo vim main.tf
azureuser@vm-velero-testing-prod-003:/terraform-testing$ cat main.tf
We strongly recommend using the required_providers block to set the
Azure Provider source and version being used
terraform {
required_providers {
azurerm = {
source = “hashicorp/azurerm”
version = “=2.46.0”
}
}
}
Configure the Microsoft Azure Provider
provider “azurerm” {
features {}
subscription_id = “256bc5b8-144d-4384-9286-e869fb7ce2c9”
tenant_id = “8c91e3f4-7f37-4334-9f70-fae3f5235c18”
}
locals {
azure_location = “East US”
}
resource “azurerm_resource_group” “primary_vnet_resource_group” {
name = “vnet-prod-002-eastus-001”
location = local.azure_location
}
resource “azurerm_virtual_network” “primary_vnet_virtual_network” {
name = “vnet_primary_eastus-001”
location = local.azure_location
resource_group_name = “azurerm_resource_group.primary_vnet_resource_group.name”
address_space = [“10.0.0.0/16”]
}
resource “azurerm_subnet” “aks-subnet” {
name = “snet-aks-prod-002-eastus-001”
location = local.azure_location
virtual_network_name = “primary_vnet_virtual_network.name”
resource_group_name = “azurerm_resource_group.primary_vnet_resource_group.name”
address_prefixes = [“10.0.1.0/24”]
}
resource “azurerm_subnet” “application-subnet” {
name = “snet-app-prod-002-eastus-001”
location = local.azure_location
virtual_network_name = “primary_vnet_virtual_network.name”
resource_group_name = “azurerm_resource_group.primary_vnet_resource_group.name”
address_prefixes = [“10.0.2.0/24”]
}
resource “azurerm_subnet” “postgres-subnet” {
name = “snet-postgres-prod-002-eastus-001”
location = local.azure_location
virtual_network_name = “primary_vnet_virtual_network.name”
resource_group_name = “azurerm_resource_group.primary_vnet_resource_group.name”
address_prefixes = [“10.0.3.0/24”]
}