Skip to content

Commit

Permalink
Fix lint and add missing bits
Browse files Browse the repository at this point in the history
  • Loading branch information
skatsaounis committed Nov 16, 2023
1 parent fcc0c85 commit 7943029
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 51 deletions.
32 changes: 32 additions & 0 deletions docs/data-sources/machine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "maas_machine Data Source - terraform-provider-maas"
subcategory: ""
description: |-
---

# maas_machine (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `hostname` (String) The machine hostname.

### Read-Only

- `architecture` (String) The architecture type of the machine.
- `domain` (String) The domain of the machine.
- `id` (String) The ID of this resource.
- `min_hwe_kernel` (String) The minimum kernel version allowed to run on this machine.
- `pool` (String) The resource pool of the machine.
- `power_parameters` (Map of String, Sensitive) Serialized JSON string containing the parameters specific to the `power_type`. See [Power types](https://maas.io/docs/api#power-types) section for a list of the available power parameters for each power type.
- `power_type` (String) The power management type (e.g. `ipmi`) of the machine.
- `pxe_mac_address` (String) The MAC address of the machine's PXE boot NIC.
- `zone` (String) The zone of the machine.
32 changes: 32 additions & 0 deletions docs/data-sources/network_interface_physical.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "maas_network_interface_physical Data Source - terraform-provider-maas"
subcategory: ""
description: |-
---

# maas_network_interface_physical (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `machine` (String) The identifier (system ID, hostname, or FQDN) of the machine with the physical network interface.
- `name` (String) The physical network interface name.

### Optional

- `tags` (Set of String) A set of tag names assigned to the physical network interface.

### Read-Only

- `id` (String) The ID of this resource.
- `mac_address` (String) The physical network interface MAC address.
- `mtu` (Number) The MTU of the physical network interface.
- `vlan` (String) VLAN the physical network interface is connected to.
86 changes: 51 additions & 35 deletions maas/data_source_maas_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure"
"github.com/maas/gomaasclient/client"
)

Expand All @@ -13,52 +14,58 @@ func dataSourceMaasMachine() *schema.Resource {
ReadContext: dataSourceMachineRead,

Schema: map[string]*schema.Schema{
"power_type": {
Type: schema.TypeString,
Computed: true,
},
"power_parameters": {
Type: schema.TypeMap,
Computed: true,
Sensitive: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
"architecture": {
Type: schema.TypeString,
Computed: true,
Description: "The architecture type of the machine.",
},
"pxe_mac_address": {
Type: schema.TypeString,
Computed: true,
"domain": {
Type: schema.TypeString,
Computed: true,
Description: "The domain of the machine.",
},
"architecture": {
Type: schema.TypeString,
Computed: true,
"hostname": {
Type: schema.TypeString,
Required: true,
Description: "The machine hostname.",
},
"min_hwe_kernel": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Description: "The minimum kernel version allowed to run on this machine.",
},
"hostname": {
Type: schema.TypeString,
Required: true,
"pool": {
Type: schema.TypeString,
Computed: true,
Description: "The resource pool of the machine.",
},
"domain": {
Type: schema.TypeString,
Computed: true,
"power_parameters": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "Serialized JSON string containing the parameters specific to the `power_type`. See [Power types](https://maas.io/docs/api#power-types) section for a list of the available power parameters for each power type.",
},
"zone": {
Type: schema.TypeString,
Computed: true,
"power_type": {
Type: schema.TypeString,
Computed: true,
Description: "The power management type (e.g. `ipmi`) of the machine.",
},
"pool": {
Type: schema.TypeString,
Computed: true,
"pxe_mac_address": {
Type: schema.TypeString,
Computed: true,
Description: "The MAC address of the machine's PXE boot NIC.",
},
"zone": {
Type: schema.TypeString,
Computed: true,
Description: "The zone of the machine.",
},
},
}
}

func dataSourceMachineRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*client.Client)
func dataSourceMachineRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*client.Client)
machine, err := getMachine(client, d.Get("hostname").(string))
if err != nil {
return diag.FromErr(err)
Expand All @@ -67,12 +74,21 @@ func dataSourceMachineRead(ctx context.Context, d *schema.ResourceData, m interf
if err != nil {
return diag.FromErr(err)
}
powerParamsJson, err := structure.FlattenJsonToString(powerParams)
if err != nil {
return diag.FromErr(err)
}
tfState := map[string]interface{}{
"id": machine.SystemID,
"architecture": machine.Architecture,
"min_hwe_kernel": machine.MinHWEKernel,
"hostname": machine.Hostname,
"domain": machine.Domain.Name,
"zone": machine.Zone.Name,
"pool": machine.Pool.Name,
"power_type": machine.PowerType,
"power_parameters": powerParams,
"power_parameters": powerParamsJson,
"pxe_mac_address": machine.BootInterface.MACAddress,
"architecture": machine.Architecture,
}
if err := setTerraformState(d, tfState); err != nil {
return diag.FromErr(err)
Expand Down
49 changes: 33 additions & 16 deletions maas/data_source_maas_network_interface_physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,57 @@ func dataSourceMaasNetworkInterfacePhysical() *schema.Resource {
ReadContext: dataSourceNetworkInterfacePhysicalRead,

Schema: map[string]*schema.Schema{
"machine": {
Type: schema.TypeString,
Required: true,
},
"mac_address": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Description: "The physical network interface MAC address.",
},
"vlan": {
Type: schema.TypeString,
Computed: true,
"machine": {
Type: schema.TypeString,
Required: true,
Description: "The identifier (system ID, hostname, or FQDN) of the machine with the physical network interface.",
},
"mtu": {
Type: schema.TypeInt,
Computed: true,
Description: "The MTU of the physical network interface.",
},
"name": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
Description: "The physical network interface name.",
},
"mtu": {
Type: schema.TypeInt,
"tags": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "A set of tag names assigned to the physical network interface.",
},
"vlan": {
Type: schema.TypeString,
Computed: true,
Description: "VLAN the physical network interface is connected to.",
},
},
}
}

func dataSourceNetworkInterfacePhysicalRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*client.Client)
func dataSourceNetworkInterfacePhysicalRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*client.Client)
n, err := getNetworkInterfacePhysical(client, d.Get("machine").(string), d.Get("name").(string))
if err != nil {
return diag.FromErr(err)
}
tfState := map[string]interface{}{
"id": fmt.Sprintf("%v", n.ID),
"machine": d.Get("machine").(string),
"mac_address": n.MACAddress,
"machine": d.Get("machine").(string),
"mtu": n.EffectiveMTU,
"name": n.Name,
"tags": n.Tags,
"vlan": fmt.Sprintf("%v", n.VLAN.ID),
}
if err := setTerraformState(d, tfState); err != nil {
Expand Down

0 comments on commit 7943029

Please sign in to comment.