Monitor services in azure - azure

The error message is:
There are some problems with the configuration, described below. The Terraform configuration must be valid before initialization so that Terraform can determine which modules and providers need to be installed.
Here's what I'm doing:
Written a terraform script in azvm.tf to create a VM.
Defined the variables resourcegroup, location, and pub_key in the variables.tf file, and call those variables in the azvm.tf file using string interpolation syntax.
Created a VM with the following features:
a) Ubuntu 18.04 server
b) VM name : any custom name
c) Admin_username : Any custom name
d) disable password authentication
e) size : Standard DS1_v2
f) Allow traffic for ssh, http, https
g) use public ssh key generated in the above step
With help of vi command we created variables.tf file as:
variable "resourcegroup"
{
default = "user-pbtwiiiuofyu"
}
variable "location"
{
default = ["East US"]
}
variable "pub_key"
{
default = ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDH7+uZHdf3SXSfz3Z80FCahr1Bt2t2u+RBlgE/QPN5Qy/CdrpcNH/8oncuDLKW5r+Ie+J5yNVwJz96gdLAQPNMmAYEPGjNct63kQp8hZPlWFdQIEyvHZwwP4YWf5vyRjozQ1PZN/0WyBjqTYmJh3z6haFxqnmIf6a9G8JldjtTPuF2oAnHaUDpqD4qBy/+OSN7CX1Lowny83NLNFoTgmm2npU+RIS2FDYpf1z30tejZSO0V3Z+iT3Xddlzh2NwunzOPv9avzwrLbSSvdbugcXTSPURMLgXwCapH9oHt4RCB/2mgsrRcLQb14FKG9UVBwzh07v2w8fDAHLnv2g4bpnhIyZMpX3zLO9mtQ4ix9DpyqPMqLV7b1uTSyj9t3UEcfprGWRPDJgkpGXEzP0iQgrGlfpctL/6/Hy009123uzb4ugXwndPbuQnPtj45PX2D4zEOFPrlvFBofazuGp65wxdzlzZpGsgqxiZQbdFCU4eQV2Y2kBPj/uv/3DOI2x27ML6i9D/shiVz/sSpryjKRHIl9bU7rU4vClgED/1NuhhTGLk5qPFOjsvvHpIORu5zFKNmeGFHW6e0TJnJMsckszseQuyjqUMkBoFV0NIOyS/mGLrxxzOTpzQyM9duat4T3kGLjjy+ozpHRaahXO79I91pDP66enitmj861kS6G5chQ== root#6badb6ae71d1"]
}
And vi command we created azvm.tf file as
az vm create -n Myuyuuy5Vm -g var.resourcegroup --ssh-key-values var.pub_key
We have another similar task but less easy in compare to it i.e.-
Write a terraform script in azmonitor.tf to create a storage account,
storage container, storage blob to monitor and send log reports
everyday.
Define the variables resourcegroup and location in the variables.tf
file, and call those variables in the azmonitor.tf file using string
interpolation syntax
variables.tf as-
variable "resourcegroup"
{
default = "user-pbtwiiiuofyu"
}
variable "location"
{
default = ["East US"]
}
azmonitor.tf we had created as-
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = var.resourcegroup
location = var.location
}
resource "azurerm_storage_account" "example" {
name = "sa123321123"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.location
sku = "Standard_LRS"
}
resource "azurerm_storage_container" "example" {
name = "sc123321123"
resource_group_name = azurerm_resource_group.example.name
account_key = azurerm_storage_account.eample.name
public_access = "blob"
}
resource "azurerm_storage_blob" "example" {
name = "sb123321123"
resource_group_name = azurerm_resource_group.example.name
account_key = azurerm_storage_account.eample.name
source = azurerm_storage_container.name
}

So as mentioned above, you're using a mix of Terraform and Az CLI here - this is not right. You should use one or the other.
It seems you've been tasked to create a Linux VM using Terraform. You need a 'main' Terraform file for your main code/terraform objects and then a 'variable' Terraform file for your variables. Technically, Terraform will flatten every Terraform file that are in the same directory when you do a Terraform init/plan - this means you could put everything in just one single .tf file.
However, for the purpose of the tutorial, it's a good practice to split both so they can be managed easily. This is the Terraform code that you would want to use - it will help you create a Linux VM.
For simplicity, I'm putting a sample here that links back to the variables in your variables.tf
terraform {
required_version = "= 0.14.10" //change this accordingly
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.55.0"
}
}
}
resource "azurerm_resource_group" "example" {
name = var.resourcegroup
location = var.location
}
resource "azurerm_virtual_network" "example" {
name = "example-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
name = "internal"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_network_interface" "example" {
name = "example-nic"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.example.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_linux_virtual_machine" "example" {
name = "example-machine"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
size = "Standard_DS1_v2"
admin_username = "Admin_username"
network_interface_ids = [
azurerm_network_interface.example.id,
]
admin_ssh_key {
username = "adminuser"
public_key = file("~/.ssh/id_rsa.pub") //put your public key here
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
}
Once you're done with validating the code above, you'll need two more objects,
The azurerm_network_security_group that will help you create the rules to allow inbound connectivity to the VM
The azurerm_subnet_network_security_group_association that will help you attach the subnet to the NSG.
Once you have the complete code, then you can run a terraform init to initialise the modules, followed by terraform plan to verify your plan and finally terraform apply to deploy the VM.
For the blob part:
variable.tf
variable "resourcegroup" {
default = "user-pbtwiiiuofyu"
}
variable "location" {
default = "East US"
}
azmonitor.tf
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = var.resourcegroup
location = var.location
}
resource "azurerm_storage_account" "example" {
name = "examplestoracc"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_container" "example" {
name = "content"
storage_account_name = azurerm_storage_account.example.name
container_access_type = "private"
}
resource "azurerm_storage_blob" "example" {
name = "my-awesome-content.zip"
storage_account_name = azurerm_storage_account.example.name
storage_container_name = azurerm_storage_container.example.name
type = "Block"
source = "./some-local-file.zip"
}

Related

get the subnetid from subnets of type map(object)

I need to fetch the subnetid from azurerm_subnet data resource as subnet is used in dynamic block of azurerm_virtual_network as map(object) type
resource "azurerm_virtual_network" "example" {
name = "example-vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
dynamic "subnet" {
for_each = var.subnets
content {
name = subnet.value.name
address_prefix = subnet.value.address_prefix
security_group = azurerm_network_security_group.example[subnet.key].id
}
}
}
Fetch the second subnetid to attach it to storage account
resource "azurerm_storage_account" "example" {
count = length(var.subnets)
name = "storageaccountname"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "GRS"
network_rules {
default_action = "Deny"
virtual_network_subnet_ids = ["${data.azurerm_subnet.subnetid.id}"]
}
}
Please can any one help to solve as i want to declare subnet in azurerm_virtual_network as dynamic block and get the subnet if from the data resource and please find my terraform.tfvars as below
subnets = {
subnet1 = {
name = "subnet1"
address_prefix = "10.0.0.0/24"
}
subnet2 = {
name = "subnet2"
address_prefix = "10.0.1.0/24"
}
subnet3 = {
name = "subnet3"
address_prefix = "10.0.2.0/24"
}
}
IMPORTANT
count = length(var.subnets) in resource "azurerm_storage_account" "example" {} is still there in your question which is logically incorrect as I have stated in the comments.
Answer
With your comments, I am assuming that you want to use id of subnet2 in network_rules of resource "azurerm_storage_account" "example" {}. With your current approach where creating subnets within the virtual network resource you have to use splat expressions and locals to make a map out of the set object and then can directly refer wherever is required.
While doing referencing even with locals and splat expressions it is still required to use the name of the subnet as it is not possible for terraform to know what you want without any data.
resource "azurerm_virtual_network" "example" {
name = "example-vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
dynamic "subnet" {
for_each = var.subnets
content {
name = subnet.value.name
address_prefix = subnet.value.address_prefix
# security_group = azurerm_network_security_group.example[subnet.key].id ## I have ignored it as no relevant code is shared###
}
}
}
locals {
subnets = { for subnet in azurerm_virtual_network.example.subnet : subnet.name => subnet }
}
resource "azurerm_storage_account" "example" {
#count = length(var.subnets) ## Removed it too as logically incorrect with the current code ##
name = "storageaccountname"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "GRS"
network_rules {
default_action = "Deny"
virtual_network_subnet_ids = [local.subnets.subnet2.id]
}
You do not need a data source when referencing the attributes from one resource/module to another resource/module in the root module.
However, I suggest using azurerm_subnet resource for easier reference in spite of creating subnets in the virtual network resource itself because your might need Microsoft.Storage service_endpoints in your subnets for working with storage account with network_rules.

get ip addresses of azurerm_linux_virtual_machine_scale_set as output

Can I somehow get the internal IP addresses of the created VMs of an azurerm_linux_virtual_machine_scale_set with a fixed amount of instances as output variable?
I went through the documentation but didn't find any export related to the virtual machines created.
I tried to create the Internal IP address of the created vm in my environment and got the below results
The below script I have taken from this terraform URL and modified as per the requirement
locals {
first_public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+wWK73dCr+jgQOAxNsHAnNNNMEMWOHYEccp6wJm2gotpr9katuF/ZAdou5AaW1C61slRkHRkpRRX9FA9CYBiitZgvCCz+3nWNN7l/Up54Zps/pHWGZLHNJZRYyAB6j5yVLMVHIHriY49d/GZTZVNB8GoJv9Gakwc/fuEZYYl4YDFiGMBP///TzlI4jhiJzjKnEvqPFki5p2ZRJqcbCiF4pJrxUQR/RXqVFQdbRLZgYfJ8xGB878RENq3yQ39d8dVOkq4edbkzwcUmwwwkYVPIoDGsYLaRHnG+To7FvMeyO7xDVQkMKzopTQV8AuKpyvpqu0a9pWOMaiCyDytO7GGN you#me.com"
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "example-resourcesabc"
location = "West Europe"
}
resource "azurerm_virtual_network" "example" {
name = "example-networkabc"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_linux_virtual_machine_scale_set" "example" {
name = "vmssabc"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku = "Standard_F2"
instances = 3
admin_username = "adminuser"
admin_ssh_key {
username = "adminuser"
public_key = local.first_public_key
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}
network_interface {
name = "example"
primary = true
ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.internal.id
}
}
}
Run the following script
terraform init
terraform plan
terraform apply
When I open and check the virtual machine scale set i am able to see the 3 instances created
I opened the Vm instance, I am able to see the terraform created Private IP address

azurerm - Terraform not behaving as expected

I'm trying to create a Terraform project to create everything I need in an Azure subscription, so resource groups, vnets, subnets and VM's.
However when I've run this once and try again, it states that it cannot delete a subnet that is in use. I haven't changed anything about the subnet or the VM connected to it.
Error: creating/updating Virtual Network: (Name "" / Resource Group ""): network.VirtualNetworksClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InUseSubnetCannotBeDeleted" Message="Subnet build-agent is in use by /subscriptions/mysub/resourceGroups/myrg/providers/Microsoft.Network/networkInterfaces/mynic/ipConfigurations/internal and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet." Details=[]
terraform {
required_version = ">= 1.1.0"
backend "azurerm" {
}
required_providers {
azurerm = {
version = "=3.5.0"
source = "hashicorp/azurerm" # https://registry.terraform.io/providers/hashicorp/azurerm/latest
}
}
}
# Configure the Microsoft Azure Provider
provider "azurerm" {
features {}
}
locals {
name_suffix = "<mysuffix>"
}
resource "azurerm_resource_group" "rg-infra" {
name = "rg-${local.name_suffix}"
location = "UK South"
}
resource "azurerm_virtual_network" "vnet-mgmt" {
name = "vnet-${local.name_suffix}"
location = azurerm_resource_group.rg-infra.location
resource_group_name = azurerm_resource_group.rg-infra.name
address_space = ["<myiprange>"]
subnet {
name = "virtual-machines"
address_prefix = "<myiprange>"
}
subnet {
name = "databases"
address_prefix = "<myiprange>"
}
}
data "azurerm_virtual_network" "network" {
name = "vnet-${local.name_suffix}"
resource_group_name = azurerm_resource_group.rg-infra.name
}
resource "azurerm_subnet" "sb-ansible" {
name = "build-agent"
resource_group_name = azurerm_resource_group.rg-infra.name
virtual_network_name = data.azurerm_virtual_network.network.name
address_prefixes = ["<myiprange>"]
depends_on = [azurerm_virtual_network.vnet-mgmt]
}
data "azurerm_subnet" "prd-subnet" {
name = "build-agent"
virtual_network_name = data.azurerm_virtual_network.network.name
resource_group_name = azurerm_resource_group.rg-infra.name
depends_on = [azurerm_subnet.sb-ansible]
}
resource "azurerm_network_interface" "ni-ansible" {
name = "nic-ansible-${local.name_suffix}"
location = azurerm_resource_group.rg-infra.location
resource_group_name = azurerm_resource_group.rg-infra.name
ip_configuration {
name = "internal"
subnet_id = data.azurerm_subnet.prd-subnet.id
private_ip_address_allocation = "Dynamic"
}
lifecycle {
ignore_changes = ["ip_configuration"]
}
depends_on = [azurerm_subnet.sb-ansible]
}
resource "azurerm_linux_virtual_machine" "ansible-vm" {
name = "ansible-build-agent"
resource_group_name = azurerm_resource_group.rg-infra.name
location = azurerm_resource_group.rg-infra.location
size = "Standard_D2as_v4"
admin_username = "myadminuser"
network_interface_ids = [
azurerm_network_interface.ni-ansible.id,
]
admin_ssh_key {
username = "myadminuser"
public_key = ""
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
lifecycle {
ignore_changes = ["source_image_reference"]
}
depends_on = [azurerm_network_interface.ni-ansible]
}
Any help on why it's behaving like this, or a workaround would be greatly appreciated!
Many thanks
Turns out you can't mix nested subnets in the vnet block with an explicitly defined azurerm_subnet

Terraform: Can not parse "ip_configuration.0.subnet_id" as a resource id - invalid URI for request: Nested

Also for public ip id getting: "
Error: Can not parse "ip_configuration.0.public_ip_address_id" as a
resource id: Cannot parse Azure ID: parse
module.resource.azurerm_public_ip.primary.id: invalid URI for request
"
As the network is a nested module for the resource module, will you please suggest, where I'm missing?
main.tf file:
#Select provider
provider "azurerm" {
subscription_id = "xxxxxxxxxxxxxxxxxxxxxx"
version = "~> 2.2"
features {}
}
module "resource" {
source = "./modules/resource"
resource_group_name = "DevOpsPoc-primary"
location = "southeastasia"
}
module "network" {
source = "./modules/network"
virtual_network = "primaryvnet"
subnet = "primarysubnet"
address_space = "192.168.0.0/16"
address_prefix = "192.168.1.0/24"
public_ip = "backendvmpip"
location = "southeastasia"
primary_nic = "backendvmnic"
#vnet_subnet_id = element(module.network.vnet_subnets, 0)
primary_ip_conf = "backendvm"
}
resource module main.tf file:
resource "azurerm_resource_group" "primary" {
name = "var.resource_group_name"
location = "var.location"
tags = {
environment = "env"
}
}
network module main.tf file:
#Create Virtual Network in Primary Resource Group
resource "azurerm_virtual_network" "primary" {
name = "var.virtual_network"
resource_group_name = "module.resource.azurerm_resource_group.primary.name"
address_space = ["var.address_space"]
location = "module.resource.azurerm_resource_group.primary.location"
tags = {
environment = "env"
}
}
#Create Subnet in Virtual Network
resource "azurerm_subnet" "primary" {
name = "var.subnet"
resource_group_name = "module.resource.azurerm_resource_group.primary.name"
virtual_network_name = "module.resource.azurerm_virtual_network.primary.name"
address_prefix = "var.address_prefix"
# tags = {
# environment = "env"
# }
}
output "subnet_id"{
value = "module.resource.azurerm_subnet.primary.id"
}
#Create public IP address
resource "azurerm_public_ip" "primary" {
name = "var.public_ip"
location = "module.resource.azurerm_resource_group.primary.location"
resource_group_name = "module.resource.azurerm_resource_group.primary.name"
allocation_method = "Dynamic"
tags = {
environment = "env"
}
}
output "public_ip_id"{
value = "module.resource.azurerm_public_ip.id"
}
#Create Network Interface
resource "azurerm_network_interface" "primary" {
name = "var.primary_nic"
location = "module.resource.azurerm_resource_group.primary.location"
resource_group_name = "module.resource.azurerm_resource_group.primary.name"
ip_configuration {
name = "var.primary_ip_conf"
subnet_id = "module.resource.azurerm_subnet.primary.id"
private_ip_address_allocation = "Dynamic"
public_ip_address_id = "module.resource.azurerm_public_ip.primary.id"
}
tags = {
environment = "env"
}
}
There are some places need to be corrected in your codes:
You don't need double quotes"" in variables or expression refers to Interpolation Syntax. For example "var.virtual_network" should be var.virtual_network.
You can directly reference resources in the same main.tf file instead of from the module block. For example, change virtual_network_name = "module.resource.azurerm_virtual_network.primary.name" to virtual_network_name = azurerm_virtual_network.primary.name in the resource "azurerm_subnet" block.
The syntax for referencing module outputs is ${module.NAME.OUTPUT}, where NAME is the module name given in the header of the module configuration block and OUTPUT is the name of the output to reference. You can declare resource group name and location in module "network" instead of using it from the ./modules/network/main.tf file.
Here is the working code and you could get more references in this document:
main.tf file in the root directory
module "resource" {
source = "./modules/resource"
resource_group_name = "DevOpsPoc-primary"
location = "southeastasia"
}
module "network" {
source = "./modules/network"
resource_group_name = module.resource.RGname
location = module.resource.location
virtual_network = "primaryvnet"
subnet = "primarysubnet"
address_space = ["192.168.0.0/16"]
address_prefix = "192.168.1.0/24"
public_ip = "backendvmpip"
primary_nic = "backendvmnic"
#vnet_subnet_id = element(module.network.vnet_subnets, 0)
primary_ip_conf = "backendvm"
}
main.tf in the directory ./modules/resource
variable "resource_group_name" {}
variable "location" {}
resource "azurerm_resource_group" "primary" {
name = var.resource_group_name
location = var.location
}
output "RGname" {
value = "${azurerm_resource_group.primary.name}"
}
output "location" {
value = "${azurerm_resource_group.primary.location}"
}
main.tf in the directory ./modules/network and also declare the variables in the same directory.
#Create Virtual Network in Primary Resource Group
resource "azurerm_virtual_network" "primary" {
name = var.virtual_network
resource_group_name = var.resource_group_name
address_space = var.address_space
location = var.location
}
#Create Subnet in Virtual Network
resource "azurerm_subnet" "primary" {
name = var.subnet
resource_group_name = var.resource_group_name
virtual_network_name = azurerm_virtual_network.primary.name
address_prefix = var.address_prefix
}
output "subnet_id"{
value = azurerm_subnet.primary.id
}
#Create public IP address
resource "azurerm_public_ip" "primary" {
name = var.public_ip
location = var.location
resource_group_name = var.resource_group_name
allocation_method = "Dynamic"
}
output "public_ip_id"{
value = azurerm_public_ip.primary.id
}
#Create Network Interface
resource "azurerm_network_interface" "primary" {
name = var.primary_nic
location = var.location
resource_group_name = var.resource_group_name
ip_configuration {
name = var.primary_ip_conf
subnet_id = azurerm_subnet.primary.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.primary.id
}
}
I had a similar error when setting up an Azure App Service using Terraform.
module.app_service.azurerm_app_service.app_service: Creating...
│ Error: Cannot parse Azure ID: parse "27220": invalid URI for request
│
│ with module.app_service.azurerm_app_service.app_service,
│ on ../../../modules/azure/app-service/main.tf line 1, in resource "azurerm_app_service" "app_service":
│ 1: resource "azurerm_app_service" "app_service" {
Here's how I fixed it:
The issue was that I used the wrong value for the App Service Plan ID in my module.
I was using 27220 as the App Service Plan ID, instead of the actual value of the App Service Plan ID which of this format:
"/subscriptions/fec545cd-bead-43ba-84c6-5738cdc7e458/resourceGroups/MyDevRG/providers/Microsoft.Web/serverfarms/MyDevLinuxASP"
That's all

Creating Neo4j vm Terraform Message="Creating a virtual machine from Marketplace image requires Plan information in the request

Script i am using to create Vm from marketplace giving error
Error: Code="VMMarketplaceInvalidInput" Message="Creating a virtual machine from Marketplace image requires Plan information in the request. VM: '/subscriptions/bc8afca8-32ba-48ac-b418-77de827c2bc1/resourceGroups/NexxeNeo4j-rg/providers/Microsoft.Compute/virtualMachines/NexxeNeo4j4'."
provider "azurerm" {
subscription_id = "**************************************"
features {}
}
# Use existing resource group
data "azurerm_resource_group" "gepgroup1" {
name = "NexxeNeo4j-rg"
}
# Use Existing virtual network
data "azurerm_virtual_network" "gepnetwork1" {
name = "DEVRnD"
resource_group_name = "RnDdev"
}
# Use Existing subnet
data "azurerm_subnet" "gepsubnet" {
name = "subnet"
resource_group_name = "RnDdev"
virtual_network_name = data.azurerm_virtual_network.gepnetwork1.name
}
# Create public IPs NexxeNeo4j
resource "azurerm_public_ip" "geppublicip2" {
name = "NexxeNeo4jPublicIP"
location = "eastus"
resource_group_name = "NexxeNeo4j-rg"
allocation_method = "Dynamic"
tags = {
environment = "Dev-Direct"
}
}
# Create network interface NexxeNeo4j2
resource "azurerm_network_interface" "gepnic3" {
name = "NexxeNeo4jNIC"
location = "eastus"
resource_group_name = "NexxeNeo4j-rg"
ip_configuration {
name = "NexxeNeo4jConfiguration"
subnet_id = data.azurerm_subnet.gepsubnet.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.geppublicip2.id
}
tags = {
environment = "Dev-Direct"
}
}
# Create virtual machine NexxeNeo4j
resource "azurerm_virtual_machine" "gepvm4" {
name = "NexxeNeo4j"
location = "eastus"
resource_group_name = "NexxeNeo4j-rg"
network_interface_ids = [azurerm_network_interface.gepnic3.id]
vm_size = "Standard_DS3_v2"
plan {
  name= "neo4j_3_5_13_apoc"
  publisher= "neo4j"
product= "neo4j-enterprise-3_5"
    }
storage_os_disk {
name = "NexxeNeo4j_OsDisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
storage_image_reference {
publisher = "neo4j"
offer = "neo4j-enterprise-3_5"
sku = "neo4j_3_5_13_apoc"
version = "3.5.13"
}
os_profile {
computer_name = "NexxeNeo4j"
admin_username = "gep"
admin_password = "Nexxegep#07066"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
environment = "Dev-Direct"
}
}
You need to add PLAN block in your Terraform HCL script.
Something similar to
resource "azurerm_virtual_machine" "gepvm4" {
# ...
plan {
publisher = "neo4j"
name = "neo4j-enterprise-3_5"
product = "neo4j_3_5_13_apoc"
}
# ...
}
I tried your configuration file in the Azure cloud shell. It did work except I need to run these Powershell commands to accept legal terms before run terraform apply again.
Get-AzMarketplaceTerms -Publisher neo4j -Product neo4j-enterprise-3_5 -Name neo4j_3_5_13_apoc | Set-AzMarketplaceTerms -Accept -SubscriptionId <subscription-id>
I suggest removing terraform.tfstate terraform.tfstate.backup files and run terraform init, plan, apply again.

Resources