Terraform + Azure playground limits

Cannot create resource groups or using default resource group as data source for Terraform. Please help.

Here is link to video to showing the issue: Loom | Free Screen & Video Recording Software | Loom

You’ve got your data resource group wrong, should be something like:

data "azurerm_resource_group" "existing" {
  name = "ODL-azure-1185863"
}

Also it helps to paste code as text here in code blocks, rather than have us type things from pictures or videos.

Hi Al,

I greatly appreciate your help. I was able to move forward, but now I have this error:

module.network.azurerm_virtual_network.vnet: Creating…
module.network.azurerm_virtual_network.vnet: Creation complete after 7s [id=/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267/providers/Microsoft.Network/virtualNetworks/acctvnet]
module.network.azurerm_subnet.subnet_count[0]: Creating…
module.network.azurerm_subnet.subnet_count[0]: Creation complete after 6s [id=/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267/providers/Microsoft.Network/virtualNetworks/acctvnet/subnets/subnet1]
module.linuxservers.data.azurerm_resource_group.vm[0]: Reading…
module.linuxservers.random_id.vm_sa: Creating…
module.linuxservers.random_id.vm_sa: Creation complete after 0s [id=lflg5aS1]
module.linuxservers.data.azurerm_resource_group.vm[0]: Read complete after 1s [id=/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267]
module.linuxservers.azurerm_network_security_group.vm[0]: Creating…
module.linuxservers.azurerm_public_ip.vm[0]: Creating…
module.linuxservers.azurerm_network_security_group.vm[0]: Creation complete after 4s [id=/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267/providers/Microsoft.Network/networkSecurityGroups/myvm-nsg]
module.linuxservers.azurerm_public_ip.vm[0]: Creation complete after 7s [id=/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267/providers/Microsoft.Network/publicIPAddresses/myvm-pip-0]
module.linuxservers.azurerm_network_interface.vm[0]: Creating…
module.linuxservers.azurerm_network_interface.vm[0]: Creation complete after 2s [id=/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267/providers/Microsoft.Network/networkInterfaces/myvm-nic-0]
module.linuxservers.azurerm_network_interface_security_group_association.test[0]: Creating…
module.linuxservers.azurerm_virtual_machine.vm_linux[0]: Creating…
module.linuxservers.azurerm_network_interface_security_group_association.test[0]: Creation complete after 1s [id=/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267/providers/Microsoft.Network/networkInterfaces/myvm-nic-0|/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267/providers/Microsoft.Network/networkSecurityGroups/myvm-nsg]
module.linuxservers.azurerm_virtual_machine.vm_linux[0]: Still creating… [10s elapsed]

│ Error: Code=“RequestDisallowedByPolicy” Message=“Resource ‘osdisk-myvm-0’ was disallowed by policy. Policy identifiers: ‘[{"policyAssignment":{"name":"azure8922-1188267-PolicyDefinition-ODL-azure-1188267","id":"/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267/providers/Microsoft.Authorization/policyAssignments/azure8922-1188267-PolicyDefinition-ODL-azure-1188267"},"policyDefinition":{"name":"azure8922-1188267-PolicyDefinition","id":"/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/providers/Microsoft.Authorization/policyDefinitions/azure8922-1188267-PolicyDefinition"}}]’. Target: ‘/subscriptions/b2aec48f-6dad-4d57-ad25-dad521fe74a4/resourceGroups/ODL-azure-1188267/providers/Microsoft.Compute/disks/osdisk-myvm-0’.”

│ with module.linuxservers.azurerm_virtual_machine.vm_linux[0],
│ on .terraform\modules\linuxservers\main.tf line 59, in resource “azurerm_virtual_machine” “vm_linux”:
│ 59: resource “azurerm_virtual_machine” “vm_linux” {

Here is my main.tf

terraform {
required_providers {
azurerm = {
source = “hashicorp/azurerm”
version = “3.11.0”
}
}
}

Configure the Microsoft Azure Provider

provider “azurerm” {

skip_provider_registration = true # This is only required when the User, Service Principal, or Identity running Terraform lacks the permissions to register Azure Resource Providers.

features {}
}

Use default resource group

data “azurerm_resource_group” “azure_terraform_provider_rg” {
name = var.azure_rg
}

module “network” {
source = “Azure/network/azurerm”
resource_group_name = data.azurerm_resource_group.azure_terraform_provider_rg.name
subnet_prefixes = [“10.0.1.0/24”]
subnet_names = [“subnet1”]
use_for_each = false
}

output “linux_vm_public_name” {
value = module.linuxservers.public_ip_dns_name
}

module “linuxservers” {
source = “Azure/compute/azurerm”
resource_group_name = data.azurerm_resource_group.azure_terraform_provider_rg.name
vm_os_simple = “UbuntuServer”
public_ip_dns = [“linuxpublicazurevm023”] // change to a unique name per datacenter region
vnet_subnet_id = module.network.vnet_subnets[0]
vm_size = “Standard_D2s_v3”
availability_set_enabled = false
depends_on = [module.network]
}

Please help.

Thank you,

John Kennedy

Please reformat your post using Code Blocks </>, then I have a chance of understanding it. Thanks.

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.11.0"
    }
  }
}

# Configure the Microsoft Azure Provider
provider "azurerm" {
  #   skip_provider_registration = true # This is only required when the User, Service Principal, or Identity running Terraform lacks the permissions to register Azure Resource Providers.
  features {}
}

# Use default resource group
data "azurerm_resource_group" "azure_terraform_provider_rg" {
  name = var.azure_rg
}

module "network" {
  source              = "Azure/network/azurerm"
  resource_group_name = data.azurerm_resource_group.azure_terraform_provider_rg.name
  subnet_prefixes     = ["10.0.1.0/24"]
  subnet_names        = ["subnet1"]
  use_for_each        = false
}

output "linux_vm_public_name" {
  value = module.linuxservers.public_ip_dns_name
}

module "linuxservers" {
  source                   = "Azure/compute/azurerm"
  resource_group_name      = data.azurerm_resource_group.azure_terraform_provider_rg.name
  vm_os_simple             = "UbuntuServer"
  public_ip_dns            = ["linuxpublicazurevm023"] // change to a unique name per datacenter region
  vnet_subnet_id           = module.network.vnet_subnets[0]
  vm_size                  = "Standard_D2s_v3"
  availability_set_enabled = false
  depends_on               = [module.network]
}

Resource ‘osdisk-myvm-0’ was disallowed by policy

You have to specify Standard SSD or Standard HDD disks. I think it default to Premium SSD and that is not allowed in the policy.

I had to change the storage type to StandardSSD_LRS and everything up and running.

Thank you for your help.