generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,276 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
data "device42_ipam_subnet" "example" { | ||
subnet_id = "1321" | ||
} | ||
|
||
output "example" { | ||
value = data.device42_ipam_subnet.example | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
provider "scaffolding" { | ||
# example configuration here | ||
provider "device42" { | ||
host = "d42.example.com" | ||
username = "terraform" | ||
password = "superpassword" | ||
insecure = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
resource "device42_ipam_subnet" "parent" { | ||
name = "SUPERNET" | ||
tags = "TEST" | ||
mask_bits = "21" | ||
network = "10.25.0.0" | ||
} | ||
|
||
resource "device42_ipam_subnet" "example" { | ||
create_from_parent = true | ||
|
||
name = "TEST-SUBNET" | ||
tags = "TEST,FART" | ||
mask_bits = "29" | ||
parent_subnet_id = device42_ipam_subnet.parent.subnet_id | ||
} | ||
|
||
output "example" { | ||
value = device42_ipam_subnet.example | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
resource "device42_ipam_vlan" "example" { | ||
check_if_exists = true | ||
create_within_range = "1-106" | ||
|
||
name = "API-TEST23" | ||
tags = "TEST,TEST2,TEST3" | ||
number = "666" | ||
} | ||
|
||
output "debug" { | ||
value = device42_ipam_vlan.example | ||
} | ||
|
||
resource "device42_ipam_vlan" "example2" { | ||
create_within_range = "100-199" | ||
|
||
name = "API-TEST23" | ||
tags = "TEST,TEST2,TEST3" | ||
} | ||
|
||
output "debug2" { | ||
value = device42_ipam_vlan.example2 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
module github.com/hashicorp/terraform-provider-scaffolding | ||
module github.com/poroping/terraform-provider-device42 | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/hashicorp/terraform-plugin-docs v0.4.0 | ||
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0 | ||
github.com/poroping/libdevice42 v0.0.0-20210826204514-db5775bea26d | ||
github.com/thoas/go-funk v0.9.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/poroping/libdevice42/client" | ||
ipam "github.com/poroping/libdevice42/client/ip_a_m" | ||
"github.com/poroping/libdevice42/models" | ||
) | ||
|
||
func dataSourceIpamSubnet() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Read IPAM subnet.", | ||
|
||
ReadContext: dataSourceIpamSubnetRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"mask_bits": { | ||
Description: "Netmask bits.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"customer_id": { | ||
Description: "Customer ID.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Description: "Name.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"network": { | ||
Description: "Network address.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"parent_mask_bits": { | ||
Description: "Parent netmask bits.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"parent_subnet_id": { | ||
Description: "ID of the parent subnet.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"parent_vlan_id": { | ||
Description: "Parent vlan ID.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"parent_vlan_name": { | ||
Description: "Parent vlan name.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"parent_vlan_number": { | ||
Description: "Parent vlan number.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"subnet_id": { | ||
Description: "ID of the subnet.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"tags": { | ||
Description: "Tags.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceIpamSubnetRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
// use the meta value to retrieve your client from the provider configure method | ||
// client := meta.(*apiClient) | ||
client := meta.(*client.Device42) | ||
|
||
params := ipam.NewGetIPAMSubnetIDParams() | ||
|
||
id := d.Get("subnet_id").(string) | ||
|
||
if v, ok := d.GetOk("subnet_id"); ok { | ||
if s, ok := v.(string); ok { | ||
i, _ := strconv.Atoi(s) | ||
params.SubnetID = int64(i) | ||
} | ||
} | ||
|
||
resp, err := client.IPam.GetIPAMSubnetID(params) | ||
|
||
if err != nil { | ||
return diag.Errorf("error retrieving IPAM subnets. %s", err) | ||
} | ||
|
||
dataSetIpamSubnet(d, resp.Payload) | ||
|
||
d.SetId(id) | ||
|
||
return nil | ||
} | ||
|
||
func dataSetIpamSubnet(d *schema.ResourceData, resp *models.IPAMsubnets) { | ||
if v, ok := resp.CustomerID.(json.Number); ok { | ||
d.Set("customer_id", v.String()) | ||
} | ||
if v, ok := resp.MaskBits.(json.Number); ok { | ||
d.Set("mask_bits", v.String()) | ||
} | ||
if v, ok := resp.Name.(string); ok { | ||
d.Set("name", v) | ||
} | ||
if v, ok := resp.Network.(string); ok { | ||
d.Set("network", v) | ||
} | ||
if v, ok := resp.ParentVlanID.(json.Number); ok { | ||
d.Set("parent_vlan_id", v.String()) | ||
} | ||
if v, ok := resp.ParentVlanName.(string); ok { | ||
d.Set("parent_vlan_name", v) | ||
} | ||
if v, ok := resp.ParentVlanNumber.(json.Number); ok { | ||
d.Set("parent_vlan_number", v) | ||
} | ||
if v, ok := resp.SubnetID.(json.Number); ok { | ||
d.Set("subnet_id", v.String()) | ||
} | ||
if v := resp.Tags; v != nil { | ||
d.Set("tags", strings.Join(v, ",")) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.