Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement data source glesys_networkadapter #201

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/data-sources/networkadapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "glesys_networkadapter Data Source - terraform-provider-glesys"
subcategory: ""
description: |-
Get information about a NetworkAdapter associated with ServerID.
---

# glesys_networkadapter (Data Source)

Get information about a NetworkAdapter associated with ServerID.

## Example Usage

```terraform
# glesys_networkadapter datasource
data "glesys_networkadapter" "nic1" {
id = "bfcb4eac-b831-4124-9e5a-629d6516d205"
}

output "nic_networkid" {
value = data.glesys_networkadapter.nic1.networkid
}
```

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

### Required

- `id` (String) networkadapter ID.

### Read-Only

- `adaptertype` (String) networkadapter adaptertype. (VMware)
- `bandwidth` (Number) networkadapter bandwidth.
- `name` (String) networkadapter name.
- `serverid` (String) networkadapter ServerID.
8 changes: 8 additions & 0 deletions examples/data-sources/glesys_networkadapter/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# glesys_networkadapter datasource
data "glesys_networkadapter" "nic1" {
id = "bfcb4eac-b831-4124-9e5a-629d6516d205"
}

output "nic_networkid" {
value = data.glesys_networkadapter.nic1.networkid
}
64 changes: 64 additions & 0 deletions glesys/datasource_glesys_networkadapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package glesys

import (
"context"

"github.com/glesys/glesys-go/v8"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceGlesysNetworkAdapter() *schema.Resource {
return &schema.Resource{
Description: "Get information about a NetworkAdapter associated with ServerID.",

ReadContext: dataSourceGlesysNetworkAdapterRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
Description: "networkadapter ID.",
},
"adaptertype": {
Type: schema.TypeString,
Computed: true,
Description: "networkadapter adaptertype. (VMware)",
},
"bandwidth": {
Type: schema.TypeInt,
Computed: true,
Description: "networkadapter bandwidth.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "networkadapter name.",
},
"serverid": {
Type: schema.TypeString,
Computed: true,
Description: "networkadapter ServerID.",
},
},
}
}

func dataSourceGlesysNetworkAdapterRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*glesys.Client)

var na *glesys.NetworkAdapter
if adapterID, ok := d.GetOk("id"); ok {
nic, err := client.NetworkAdapters.Details(ctx, adapterID.(string))
if err != nil {
return diag.Errorf("Error retrieving networkadapter: %s", err)
}
na = nic
}

d.SetId(na.ID)
d.Set("adaptertype", na.AdapterType)
d.Set("bandwidth", na.Bandwidth)
d.Set("name", na.Name)

return nil
}
5 changes: 3 additions & 2 deletions glesys/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ func Provider() *schema.Provider {
},

DataSourcesMap: map[string]*schema.Resource{
"glesys_dnsdomain": dataSourceGlesysDNSDomain(),
"glesys_network": dataSourceGlesysNetwork(),
"glesys_dnsdomain": dataSourceGlesysDNSDomain(),
"glesys_network": dataSourceGlesysNetwork(),
"glesys_networkadapter": dataSourceGlesysNetworkAdapter(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down