canonical / terraform-provider-maas

Terraform MAAS provider
Mozilla Public License 2.0
64 stars 45 forks source link

Problem creating a simple machine #88

Closed cdino closed 1 year ago

cdino commented 1 year ago

I'm testing Terraform with MAAS and I'm facing an issue:

Here is my code provider.tf:

terraform {
  required_providers {
    maas = {
      source = "maas/maas"
    }
  }
}

provider "maas" {
  api_version = "2.0"
  api_key  = "<HIDDEN>"
  api_url = "http://maas:5240/MAAS"
}

main.tf:

resource "maas_machine" "maas-machine" {
  power_type = "manual"
  power_parameters = {

  }
  pxe_mac_address = "00:50:56:ac:3b:cb"
  hostname = "machine02-tds"
  pool = "nodes-tds"
  zone = "zone1"
  architecture = "amd64/generic"
  domain = "blabla.com"
}

resource "maas_network_interface_physical" "maas-machine_nic1" {
  machine = "machine02-tds"
  mac_address = "00:50:56:ac:3b:cb"
  #name = "ens192"
  #vlan = data.maas_vlan.current_vlan.id
  vlan = "5188"
}

resource "maas_network_interface_link" "maas-machine_nic1" {
  machine = "machine02-tds"
  network_interface = "00:50:56:ac:3b:cb"
  subnet = "15"
  mode = "STATIC"
  ip_address = "10.10.10.165"
  default_gateway = true
}

I'm getting these errors:

╷
│ Error: json: cannot unmarshal object into Go struct field Machine.raids of type string
│ 
│   with maas_network_interface_physical.maas-machine_nic1,
│   on main.tf line 24, in resource "maas_network_interface_physical" "maas-machine_nic1":
│   24: resource "maas_network_interface_physical" "maas-machine_nic1" {
│ 
╵
╷
│ Error: json: cannot unmarshal object into Go struct field Machine.raids of type string
│ 
│   with maas_network_interface_link.maas-machine_nic1,
│   on main.tf line 33, in resource "maas_network_interface_link" "maas-machine_nic1":
│   33: resource "maas_network_interface_link" "maas-machine_nic1" {
│ 
╵
2023-09-20T15:25:26.985+0200 [ERROR] vertex "maas_network_interface_physical.maas-machine_nic1" error: json: cannot unmarshal object into Go struct field Machine.raids of type string
2023-09-20T15:25:26.985+0200 [TRACE] vertex "maas_network_interface_physical.maas-machine_nic1": visit complete, with errors

Terraform version:

2023-09-20T15:51:42.014+0200 [DEBUG] using github.com/hashicorp/go-tfe v1.26.0
2023-09-20T15:51:42.014+0200 [DEBUG] using github.com/hashicorp/hcl/v2 v2.16.2
2023-09-20T15:51:42.014+0200 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.0
2023-09-20T15:51:42.014+0200 [DEBUG] using github.com/zclconf/go-cty v1.12.2
2023-09-20T15:51:42.014+0200 [INFO]  Go runtime version: go1.21.1
2023-09-20T15:51:42.014+0200 [INFO]  CLI args: []string{"terraform", "-version"}
2023-09-20T15:51:42.014+0200 [TRACE] Stdout is a terminal of width 230
2023-09-20T15:51:42.014+0200 [TRACE] Stderr is a terminal of width 230
2023-09-20T15:51:42.014+0200 [TRACE] Stdin is a terminal
2023-09-20T15:51:42.014+0200 [DEBUG] Attempting to open CLI config file: /Users/xxxx/.terraformrc
2023-09-20T15:51:42.014+0200 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2023-09-20T15:51:42.014+0200 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2023-09-20T15:51:42.014+0200 [DEBUG] ignoring non-existing provider search directory /Users/xxxx/.terraform.d/plugins
2023-09-20T15:51:42.014+0200 [DEBUG] ignoring non-existing provider search directory /Users/xxxx/Library/Application Support/io.terraform/plugins
2023-09-20T15:51:42.014+0200 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2023-09-20T15:51:42.015+0200 [INFO]  CLI command args: []string{"version", "-version"}
Terraform v1.5.7
on darwin_arm64
+ provider registry.terraform.io/maas/maas v1.2.0

and

MAAS: 3.3.4
skatsaounis commented 1 year ago

Hi @cdino. Thank you for opening this issue and raising awareness.

With this PR https://github.com/maas/terraform-provider-maas/pull/92, the new version of gomaasclient is used by the provider, which includes a fix on the parsing of field raids among others.

Could you please try the new version of the provider 1.3.0 and let me know if the problem persists?

cdino commented 1 year ago

Hi, thanks for the update! Seems that the parsing issue is gone.. but now i have a permission error:

╷
│ Error: ServerError: 401 Unauthorized (Forbidden)
│ 
│   with maas_network_interface_physical.machine1_nic1,
│   on main.tf line 36, in resource "maas_network_interface_physical" "machine1_nic1":
│   36: resource "maas_network_interface_physical" "machine1_nic1" {
│ 
╵

Here the code I'm using:

#
# Machine 1
#
resource "maas_machine" "machine1" {
  power_type = "ipmi"
  power_parameters = {
    power_address = "x.y.z.k"
    mac_address = "xx:xx:xx:xx:xx:xx"
    power_user = "admin"
    power_pass = "pass"
    privilege_level = "ADMIN"
  }
  pxe_mac_address = "xx:xx:xx:xx:xx:xx"
  hostname = "node018"
  domain = "domain.com"
  pool = "pool"
  zone = "zone1"
}

resource "maas_network_interface_physical" "machine1_nic1" {
  machine = maas_machine.machine1.id
  mac_address = "xx:xx:xx:xx:xx:xx"
  #name = "ens192"
  vlan = 5006 #MAAS ID workaround... data is not working
}

resource "maas_network_interface_link" "machine1_nic1" {
  machine = maas_machine.machine1.id
  network_interface = maas_network_interface_physical.machine1_nic1.id
  subnet = 4 #MAAS ID workaround... data is not working
  mode = "STATIC"
  ip_address = "x.y.z.k"
  default_gateway = true
}
skatsaounis commented 1 year ago

Hi @cdino. This new error appears to be a different one than the correct parsing. Could you please issue a new api_key and retry? If you are still receiving it, please open a new issue so we can investigate further.