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

ae network datasource #118

Merged
merged 2 commits into from
Apr 17, 2023
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
39 changes: 39 additions & 0 deletions docs/data-sources/network.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "glesys_network Data Source - terraform-provider-glesys"
subcategory: ""
description: |-
Get information about a Network associated with your GleSYS Project.
---

# glesys_network (Data Source)

Get information about a Network associated with your GleSYS Project.

## Example Usage

```terraform
# glesys_dnsdomain datasource
data "glesys_network" "examplenet" {
name = "vl12345"
}

output "network_dc" {
value = data.glesys_network.examplenet.datacenter
}
```

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

### Required

- `id` (String) network ID.

### Read-Only

- `datacenter` (String) network datacenter.
- `description` (String) network description.
- `public` (String) network public, yes/no.


59 changes: 59 additions & 0 deletions glesys/datasource_glesys_network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package glesys

import (
"context"

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

func dataSourceGlesysNetwork() *schema.Resource {
return &schema.Resource{
Description: "Get information about a Network associated with your GleSYS Project.",

ReadContext: dataSourceGlesysNetworkRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
Description: "network ID.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "network description.",
},
"datacenter": {
Type: schema.TypeString,
Computed: true,
Description: "network datacenter.",
},
"public": {
Type: schema.TypeString,
Computed: true,
Description: "network public, yes/no.",
},
},
}
}

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

var network *glesys.Network
if networkid, ok := d.GetOk("id"); ok {
net, err := client.Networks.Details(ctx, networkid.(string))
if err != nil {
return diag.Errorf("Error retrieving network: %s", err)
}
network = net
}

d.SetId(network.ID)
d.Set("description", network.Description)
d.Set("datacenter", network.DataCenter)
d.Set("public", network.Public)

return nil
}
1 change: 1 addition & 0 deletions glesys/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func Provider() *schema.Provider {

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

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