Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Ubuntu-18.04-Missing-Resource-Invalid-block-definition #27

Closed
samhodgkinson opened this issue Sep 22, 2019 · 10 comments
Closed

Ubuntu-18.04-Missing-Resource-Invalid-block-definition #27

samhodgkinson opened this issue Sep 22, 2019 · 10 comments

Comments

@samhodgkinson
Copy link

Seems to be an issue with some of the terraform files when doing a validate.

Ubuntu-18.04
Terraform v0.12.9
azure-cli 2.0.73

The resource Type and Name are missing been surrounded by ""

Azure Automation accounts - Multiple

  • Error: Missing name for resource

    • azurerm_automation_account
    • All resource blocks must have 2 labels (type, name).
  • Error: Invalid block definition

    • azurerm_automation_account
    • Either a quoted string block label or an opening brace ("{") is expected here.

azurerm_log_analytics_solution - Multiple

  • Error: Missing name for resource

    • azurerm_log_analytics_solution
    • All resource blocks must have 2 labels (type, name).
  • Error: Invalid block definition

    • azurerm_log_analytics_solution
    • Either a quoted string block label or an opening brace ("{") is expected here.

azurerm_managed_disk - Multiple

  • Error: Missing name for resource
    -azurerm_managed_disk

    • All resource blocks must have 2 labels (type, name).
  • Error: Invalid block definition

    • azurerm_managed_disk
    • Either a quoted string block label or an opening brace ("{") is expected here.

azurerm_network_interface - Multiple

  • Error: Missing name for resource
    -azurerm_network_interface

    • All resource blocks must have 2 labels (type, name).
  • Error: Invalid block definition

    • azurerm_network_interface
    • Either a quoted string block label or an opening brace ("{") is expected here.

Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Invalid resource name
Error: Invalid resource name
Error: Invalid resource name
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Invalid resource name
Error: Invalid resource name
Error: Invalid resource name
Error: Invalid resource name
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error with terraform init

@andyt530
Copy link
Owner

Hi,

Could you post some of the debug output please using:

./az2tf.sh -s yoursub -r automation_account -v yes -d yes

This will help me see what's going on in your case.

@samhodgkinson
Copy link
Author

Please see below

python2.7 ../../scripts/az2tf.py -s 9acaa416-e542-46e1-855d-e207e2582998 -r automation_account -d yes 2>&1 | tee -a import.log
resource filter=automation_account
Debug=True
Get Access Token from CLI
Subscription: 9acaa416-e542-46e1-855d-e207e2582998
Found subscription 9acaa416-e542-46e1-855d-e207e2582998 proceeding ...

azurerm_automation_account 8

{
"name": "Automation",
"tags": {},
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Automation/automationAccounts/Automation",
"location": "westeurope",
"type": "Microsoft.Automation/AutomationAccounts",
"properties": {
"lastModifiedTime": "2019-07-23T01:33:45.853+00:00",
"creationTime": "2019-03-07T13:57:33.25+00:00"
}
}

File generated by py-az2tf see: https://github.com/andyt530/py-az2tf

resource azurerm_automation_account 123__Automation {
name = "Automation"
location = "westeurope"
resource_group_name = "123"
sku_name = "Basic"
tags = {
}
}

{
"name": "Automation2",
"tags": {},
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Automation/automationAccounts/Automation2",
"location": "West Europe",
"type": "Microsoft.Automation/AutomationAccounts",
"properties": {
"lastModifiedTime": "2019-07-23T01:33:45.853+00:00",
"creationTime": "2019-04-05T12:56:29.12+00:00"
}
}

File generated by py-az2tf see: https://github.com/andyt530/py-az2tf

resource azurerm_automation_account 123__Automation2 {
name = "Automation2"
location = "West Europe"
resource_group_name = "123"
sku_name = "Basic"
tags = {
}
}

{
"name": "Automation3",
"tags": {},
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Automation/automationAccounts/Automation3",
"location": "West Europe",
"type": "Microsoft.Automation/AutomationAccounts",
"properties": {
"lastModifiedTime": "2019-07-23T01:33:45.853+00:00",
"creationTime": "2019-04-05T12:57:47.927+00:00"
}
}

File generated by py-az2tf see: https://github.com/andyt530/py-az2tf

resource azurerm_automation_account 123__Automation3 {
name = "Automation3"
location = "West Europe"
resource_group_name = "123"
sku_name = "Basic"
tags = {
}
}

{
"name": "Automation4",
"tags": {},
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Automation/automationAccounts/Automation4",
"location": "West Europe",
"type": "Microsoft.Automation/AutomationAccounts",
"properties": {
"lastModifiedTime": "2019-07-23T01:33:45.853+00:00",
"creationTime": "2019-04-05T13:03:31.457+00:00"
}
}

File generated by py-az2tf see: https://github.com/andyt530/py-az2tf

resource azurerm_automation_account 123__Automation4 {
name = "Automation4"
location = "West Europe"
resource_group_name = "123"
sku_name = "Basic"
tags = {
}
}

{
"name": "Automation5",
"tags": {},
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Automation/automationAccounts/Automation5",
"location": "West Europe",
"type": "Microsoft.Automation/AutomationAccounts",
"properties": {
"lastModifiedTime": "2019-07-23T01:33:45.853+00:00",
"creationTime": "2019-04-05T13:10:29.907+00:00"
}
}

File generated by py-az2tf see: https://github.com/andyt530/py-az2tf

resource azurerm_automation_account 123__Automation5 {
name = "Automation5"
location = "West Europe"
resource_group_name = "123"
sku_name = "Basic"
tags = {
}
}

{
"name": "automation-NM",
"tags": {},
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Automation/automationAccounts/automation-NM",
"location": "westeurope",
"type": "Microsoft.Automation/AutomationAccounts",
"properties": {
"lastModifiedTime": "2019-07-23T01:33:45.853+00:00",
"creationTime": "2019-04-08T21:37:02.69+00:00"
}
}

File generated by py-az2tf see: https://github.com/andyt530/py-az2tf

resource azurerm_automation_account 123__automation-NM {
name = "automation-NM"
location = "westeurope"
resource_group_name = "123"
sku_name = "Basic"
tags = {
}
}

{
"name": "Kickstart",
"tags": {},
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/Kickstart/providers/Microsoft.Automation/automationAccounts/Kickstart",
"location": "westeurope",
"type": "Microsoft.Automation/AutomationAccounts",
"properties": {
"lastModifiedTime": "2019-07-23T01:33:45.853+00:00",
"creationTime": "2019-05-01T13:03:55+00:00"
}
}

File generated by py-az2tf see: https://github.com/andyt530/py-az2tf

resource azurerm_automation_account kickstart__Kickstart {
name = "Kickstart"
location = "westeurope"
resource_group_name = "Kickstart"
sku_name = "Basic"
tags = {
}
}

{
"name": "efewfefe",
"tags": {},
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Automation/automationAccounts/efewfefe",
"location": "uksouth",
"type": "Microsoft.Automation/AutomationAccounts",
"properties": {
"lastModifiedTime": "2019-07-23T01:33:46.57+00:00",
"creationTime": "2019-04-05T13:29:24.96+00:00"
}
}

File generated by py-az2tf see: https://github.com/andyt530/py-az2tf

resource azurerm_automation_account 123__efewfefe {
name = "efewfefe"
location = "uksouth"
resource_group_name = "123"
sku_name = "Basic"
tags = {
}
}

terraform init
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.

Error: Missing name for resource

on azurerm_automation_account.123__Automation.tf line 2:
2: resource azurerm_automation_account 123__Automation {

All resource blocks must have 2 labels (type, name).

Error: Invalid block definition

on azurerm_automation_account.123__Automation.tf line 2:
2: resource azurerm_automation_account 123__Automation {

Either a quoted string block label or an opening brace ("{") is expected here.

Error: Missing name for resource

on azurerm_automation_account.123__Automation2.tf line 2:
2: resource azurerm_automation_account 123__Automation2 {

All resource blocks must have 2 labels (type, name).

Error: Invalid block definition

on azurerm_automation_account.123__Automation2.tf line 2:
2: resource azurerm_automation_account 123__Automation2 {

Either a quoted string block label or an opening brace ("{") is expected here.

Error: Missing name for resource

on azurerm_automation_account.123__Automation3.tf line 2:
2: resource azurerm_automation_account 123__Automation3 {

All resource blocks must have 2 labels (type, name).

Error: Invalid block definition

on azurerm_automation_account.123__Automation3.tf line 2:
2: resource azurerm_automation_account 123__Automation3 {

Either a quoted string block label or an opening brace ("{") is expected here.

Error: Missing name for resource

on azurerm_automation_account.123__Automation4.tf line 2:
2: resource azurerm_automation_account 123__Automation4 {

All resource blocks must have 2 labels (type, name).

Error: Invalid block definition

on azurerm_automation_account.123__Automation4.tf line 2:
2: resource azurerm_automation_account 123__Automation4 {

Either a quoted string block label or an opening brace ("{") is expected here.

Error: Missing name for resource

on azurerm_automation_account.123__Automation5.tf line 2:
2: resource azurerm_automation_account 123__Automation5 {

All resource blocks must have 2 labels (type, name).

Error: Invalid block definition

on azurerm_automation_account.123__Automation5.tf line 2:
2: resource azurerm_automation_account 123__Automation5 {

Either a quoted string block label or an opening brace ("{") is expected here.

Error: Missing name for resource

on azurerm_automation_account.123__automation-NM.tf line 2:
2: resource azurerm_automation_account 123__automation-NM {

All resource blocks must have 2 labels (type, name).

Error: Invalid block definition

on azurerm_automation_account.123__automation-NM.tf line 2:
2: resource azurerm_automation_account 123__automation-NM {

Either a quoted string block label or an opening brace ("{") is expected here.

Error: Missing name for resource

on azurerm_automation_account.123__efewfefe.tf line 2:
2: resource azurerm_automation_account 123__efewfefe {

All resource blocks must have 2 labels (type, name).

Error: Invalid block definition

on azurerm_automation_account.123__efewfefe.tf line 2:
2: resource azurerm_automation_account 123__efewfefe {

Either a quoted string block label or an opening brace ("{") is expected here.

Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error: Missing name for resource
Error: Invalid block definition
Error with terraform init

@andyt530
Copy link
Owner

This seems to be down to your resource group name starting with a number
That resource group name is used as part of the terraform resource name eg "123__efewfefe"
And terraform doesn't seem to like the resource name beginning with a number

If I change it so it starts with a letter:
resource azurerm_automation_account r123__efewfefe {

It validates ok.

I'll have to check the terraform docs to see it this is a bug or expected behaviour for resource names.

@andyt530
Copy link
Owner

started posting fixes for this - I have to change every provider. But I started with the ones you are seeing errors on.

@andyt530
Copy link
Owner

should be in better shape for you now. Let me know how you get on

@samhodgkinson
Copy link
Author

This looks loads better, ran a fuller lookup. If I only have numbers, these resource groups still fail. These are testing resource groups, so I would not normally deploy them like this.

I am seeing issues with an interpolation expression

terraform init
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.

Error: Extra characters after interpolation expression

on azurerm_network_interface.rg_123__test01938.tf line 8, in resource "azurerm_network_interface" "rg_123__test01938":
8: network_security_group_id = "${azurerm_network_security_group.123__test01-nsg.id}"

Expected a closing brace to end the interpolation expression, but found extra
characters.

Error: Extra characters after interpolation expression

{
"name": "test01938",
"tags": {},
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Network/networkInterfaces/test01938",
"etag": "W/"8059d985-bf1b-44f8-a8bf-c6ee83bd23bc"",
"location": "ukwest",
"type": "Microsoft.Network/networkInterfaces",
"properties": {
"provisioningState": "Succeeded",
"dnsSettings": {
"dnsServers": [],
"appliedDnsServers": []
},
"networkSecurityGroup": {
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Network/networkSecurityGroups/test01-nsg"
},
"resourceGuid": "41e04110-bf30-4db9-8522-2210951ed9df",
"enableIPForwarding": false,
"ipConfigurations": [
{
"properties": {
"subnet": {
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Network/virtualNetworks/123-vnet/subnets/default"
},
"primary": true,
"privateIPAddressVersion": "IPv4",
"publicIPAddress": {
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Network/publicIPAddresses/test01-ip"
},
"privateIPAllocationMethod": "Dynamic",
"privateIPAddress": "10.0.0.4",
"provisioningState": "Succeeded"
},
"etag": "W/"8059d985-bf1b-44f8-a8bf-c6ee83bd23bc"",
"type": "Microsoft.Network/networkInterfaces/ipConfigurations",
"name": "ipconfig1",
"id": "/subscriptions/9acaa416-e542-46e1-855d-e207e2582998/resourceGroups/123/providers/Microsoft.Network/networkInterfaces/test01938/ipConfigurations/ipconfig1"
}
],
"enableAcceleratedNetworking": false
}
}

File generated by py-az2tf see: https://github.com/andyt530/py-az2tf

resource azurerm_network_interface rg_123__test01938 {
name = "test01938"
location = "ukwest"
resource_group_name = "123"
enable_ip_forwarding = false
enable_accelerated_networking = false
network_security_group_id = "${azurerm_network_security_group.123__test01-nsg.id}"
ip_configuration {
name = "ipconfig1"
subnet_id = "${azurerm_subnet.123__default.id}"
private_ip_address_allocation = "Dynamic"
public_ip_address_id = "${azurerm_public_ip.123__test01-ip.id}"
primary = true
}
tags = {
}
}

@andyt530
Copy link
Owner

working on fixes for that .....

@andyt530
Copy link
Owner

posted up some fixes - please give it another go - will test more thoroughly later.

@samhodgkinson
Copy link
Author

Thanks, tested and just the expected warnings for NSG and route association. I will test this across some other subscriptions and let you know If I find anything else.

@samhodgkinson
Copy link
Author

Tested this on 6 other subs no other issues found

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants