mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-20 11:48:24 -06:00
* provider/triton: Move to joyent/triton-go This commit moves the Triton provider to the new joyent/triton-go library from gosdc. This has a number of advantages - not least that requests can be signed using an SSH agent without having to keep unencrypted key material in memory. Schema has been maintained for all resources, and several tests have been added and acceptance tests repaired - in some cases by fixing bugs in the underlying resources. After applying this patch, all acceptance tests pass: ``` go generate $(go list ./... | grep -v /terraform/vendor/) 2017/03/30 13:48:33 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/triton -v -timeout 120m === RUN TestProvider --- PASS: TestProvider (0.00s) === RUN TestProvider_impl --- PASS: TestProvider_impl (0.00s) === RUN TestAccTritonFabric_basic --- PASS: TestAccTritonFabric_basic (15.11s) === RUN TestAccTritonFirewallRule_basic --- PASS: TestAccTritonFirewallRule_basic (1.48s) === RUN TestAccTritonFirewallRule_update --- PASS: TestAccTritonFirewallRule_update (1.55s) === RUN TestAccTritonFirewallRule_enable --- PASS: TestAccTritonFirewallRule_enable (1.52s) === RUN TestAccTritonKey_basic --- PASS: TestAccTritonKey_basic (11.76s) === RUN TestAccTritonKey_noKeyName --- PASS: TestAccTritonKey_noKeyName (11.20s) === RUN TestAccTritonMachine_basic --- PASS: TestAccTritonMachine_basic (82.19s) === RUN TestAccTritonMachine_dns --- PASS: TestAccTritonMachine_dns (173.36s) === RUN TestAccTritonMachine_nic --- PASS: TestAccTritonMachine_nic (167.82s) === RUN TestAccTritonMachine_addNIC --- PASS: TestAccTritonMachine_addNIC (192.11s) === RUN TestAccTritonMachine_firewall --- PASS: TestAccTritonMachine_firewall (188.53s) === RUN TestAccTritonMachine_metadata --- PASS: TestAccTritonMachine_metadata (614.57s) === RUN TestAccTritonVLAN_basic --- PASS: TestAccTritonVLAN_basic (0.93s) === RUN TestAccTritonVLAN_update --- PASS: TestAccTritonVLAN_update (1.50s) PASS ok github.com/hashicorp/terraform/builtin/providers/triton 1463.621s ``` * provider/triton: Update docs for provider config * deps: Vendor github.com/joyent/triton-go/... * deps: Remove github.com/joyent/gosdc
179 lines
4.7 KiB
Go
179 lines
4.7 KiB
Go
package triton
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
"github.com/joyent/triton-go"
|
|
)
|
|
|
|
func resourceFabric() *schema.Resource {
|
|
return &schema.Resource{
|
|
Create: resourceFabricCreate,
|
|
Exists: resourceFabricExists,
|
|
Read: resourceFabricRead,
|
|
Delete: resourceFabricDelete,
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
"name": {
|
|
Description: "Network name",
|
|
Required: true,
|
|
ForceNew: true,
|
|
Type: schema.TypeString,
|
|
},
|
|
"public": {
|
|
Description: "Whether or not this is an RFC1918 network",
|
|
Computed: true,
|
|
Type: schema.TypeBool,
|
|
},
|
|
"fabric": {
|
|
Description: "Whether or not this network is on a fabric",
|
|
Computed: true,
|
|
Type: schema.TypeBool,
|
|
},
|
|
"description": {
|
|
Description: "Description of network",
|
|
Optional: true,
|
|
ForceNew: true,
|
|
Type: schema.TypeString,
|
|
},
|
|
"subnet": {
|
|
Description: "CIDR formatted string describing network address space",
|
|
Required: true,
|
|
ForceNew: true,
|
|
Type: schema.TypeString,
|
|
},
|
|
"provision_start_ip": {
|
|
Description: "First IP on the network that can be assigned",
|
|
Required: true,
|
|
ForceNew: true,
|
|
Type: schema.TypeString,
|
|
},
|
|
"provision_end_ip": {
|
|
Description: "Last assignable IP on the network",
|
|
Required: true,
|
|
ForceNew: true,
|
|
Type: schema.TypeString,
|
|
},
|
|
"gateway": {
|
|
Description: "Gateway IP",
|
|
Optional: true,
|
|
ForceNew: true,
|
|
Type: schema.TypeString,
|
|
},
|
|
"resolvers": {
|
|
Description: "List of IP addresses for DNS resolvers",
|
|
Optional: true,
|
|
Computed: true,
|
|
Type: schema.TypeList,
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
},
|
|
"routes": {
|
|
Description: "Map of CIDR block to Gateway IP address",
|
|
Computed: true,
|
|
Optional: true,
|
|
ForceNew: true,
|
|
Type: schema.TypeMap,
|
|
},
|
|
"internet_nat": {
|
|
Description: "Whether or not a NAT zone is provisioned at the Gateway IP address",
|
|
Computed: true,
|
|
Optional: true,
|
|
ForceNew: true,
|
|
Type: schema.TypeBool,
|
|
},
|
|
"vlan_id": {
|
|
Description: "VLAN on which the network exists",
|
|
Required: true,
|
|
ForceNew: true,
|
|
Type: schema.TypeInt,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func resourceFabricCreate(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*triton.Client)
|
|
|
|
var resolvers []string
|
|
for _, resolver := range d.Get("resolvers").([]interface{}) {
|
|
resolvers = append(resolvers, resolver.(string))
|
|
}
|
|
|
|
routes := map[string]string{}
|
|
for cidr, v := range d.Get("routes").(map[string]interface{}) {
|
|
ip, ok := v.(string)
|
|
if !ok {
|
|
return fmt.Errorf(`Cannot use "%v" as an IP address`, v)
|
|
}
|
|
routes[cidr] = ip
|
|
}
|
|
|
|
fabric, err := client.Fabrics().CreateFabricNetwork(&triton.CreateFabricNetworkInput{
|
|
FabricVLANID: d.Get("vlan_id").(int),
|
|
Name: d.Get("name").(string),
|
|
Description: d.Get("description").(string),
|
|
Subnet: d.Get("subnet").(string),
|
|
ProvisionStartIP: d.Get("provision_start_ip").(string),
|
|
ProvisionEndIP: d.Get("provision_end_ip").(string),
|
|
Gateway: d.Get("gateway").(string),
|
|
Resolvers: resolvers,
|
|
Routes: routes,
|
|
InternetNAT: d.Get("internet_nat").(bool),
|
|
},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
d.SetId(fabric.Id)
|
|
|
|
return resourceFabricRead(d, meta)
|
|
}
|
|
|
|
func resourceFabricExists(d *schema.ResourceData, meta interface{}) (bool, error) {
|
|
client := meta.(*triton.Client)
|
|
|
|
return resourceExists(client.Fabrics().GetFabricNetwork(&triton.GetFabricNetworkInput{
|
|
FabricVLANID: d.Get("vlan_id").(int),
|
|
NetworkID: d.Id(),
|
|
}))
|
|
}
|
|
|
|
func resourceFabricRead(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*triton.Client)
|
|
|
|
fabric, err := client.Fabrics().GetFabricNetwork(&triton.GetFabricNetworkInput{
|
|
FabricVLANID: d.Get("vlan_id").(int),
|
|
NetworkID: d.Id(),
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
d.SetId(fabric.Id)
|
|
d.Set("name", fabric.Name)
|
|
d.Set("public", fabric.Public)
|
|
d.Set("fabric", fabric.Fabric)
|
|
d.Set("description", fabric.Description)
|
|
d.Set("subnet", fabric.Subnet)
|
|
d.Set("provision_start_ip", fabric.ProvisioningStartIP)
|
|
d.Set("provision_end_ip", fabric.ProvisioningEndIP)
|
|
d.Set("gateway", fabric.Gateway)
|
|
d.Set("resolvers", fabric.Resolvers)
|
|
d.Set("routes", fabric.Routes)
|
|
d.Set("internet_nat", fabric.InternetNAT)
|
|
d.Set("vlan_id", d.Get("vlan_id").(int))
|
|
|
|
return nil
|
|
}
|
|
|
|
func resourceFabricDelete(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*triton.Client)
|
|
|
|
return client.Fabrics().DeleteFabricNetwork(&triton.DeleteFabricNetworkInput{
|
|
FabricVLANID: d.Get("vlan_id").(int),
|
|
NetworkID: d.Id(),
|
|
})
|
|
}
|