diff --git a/docs/data-sources/machine.md b/docs/data-sources/machine.md new file mode 100644 index 00000000..a466696d --- /dev/null +++ b/docs/data-sources/machine.md @@ -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 + +### 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. diff --git a/docs/data-sources/network_interface_physical.md b/docs/data-sources/network_interface_physical.md new file mode 100644 index 00000000..748be302 --- /dev/null +++ b/docs/data-sources/network_interface_physical.md @@ -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 + +### 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. diff --git a/maas/data_source_maas_machine.go b/maas/data_source_maas_machine.go index 98c0c8c7..32f29a98 100644 --- a/maas/data_source_maas_machine.go +++ b/maas/data_source_maas_machine.go @@ -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" ) @@ -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) @@ -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) diff --git a/maas/data_source_maas_network_interface_physical.go b/maas/data_source_maas_network_interface_physical.go index 1613c721..27464378 100644 --- a/maas/data_source_maas_network_interface_physical.go +++ b/maas/data_source_maas_network_interface_physical.go @@ -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 {