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

VLAN Support #201

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
44 changes: 44 additions & 0 deletions civo/network/resource_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@ func ResourceNetwork() *schema.Resource {
Computed: true,
Description: "If the network is default, this will be `true`",
},
// VLAN Network
"vlan_id": {
Type: schema.TypeInt,
Optional: true,
Description: "VLAN ID for the network",
},
"vlan_cidr_v4": {
Type: schema.TypeString,
Optional: true,
Description: "CIDR for VLAN IPv4",
},
"vlan_gateway_ip_v4": {
Type: schema.TypeString,
Optional: true,
Description: "Gateway IP for VLAN IPv4",
},
"vlan_hardware_addr": {
Type: schema.TypeString,
Optional: true,
Description: "Hardware address for VLAN",
},
"vlan_allocation_pool_v4_start": {
Type: schema.TypeString,
Optional: true,
Description: "Start of the IPv4 allocation pool for VLAN",
},
"vlan_allocation_pool_v4_end": {
Type: schema.TypeString,
Optional: true,
Description: "End of the IPv4 allocation pool for VLAN",
},
},
CreateContext: resourceNetworkCreate,
ReadContext: resourceNetworkRead,
Expand All @@ -75,12 +106,25 @@ func resourceNetworkCreate(ctx context.Context, d *schema.ResourceData, m interf
}

log.Printf("[INFO] creating the new network %s", d.Get("label").(string))
vlanConfig := civogo.VLANConnectConfig{
VlanID: d.Get("vlan_id").(int),
HardwareAddr: d.Get("vlan_hardware_addr").(string),
CIDRv4: d.Get("vlan_cidr_v4").(string),
GatewayIPv4: d.Get("vlan_gateway_ip_v4").(string),
AllocationPoolV4Start: d.Get("vlan_allocation_pool_v4_start").(string),
AllocationPoolV4End: d.Get("vlan_allocation_pool_v4_end").(string),
}

configs := civogo.NetworkConfig{
Label: d.Get("label").(string),
CIDRv4: d.Get("cidr_v4").(string),
Region: apiClient.Region,
NameserversV4: expandStringList(d.Get("nameservers_v4")),
}
// Only add VLAN configuration if VLAN ID is set
if vlanConfig.VlanID > 0 {
configs.VLanConfig = &vlanConfig
}
network, err := apiClient.CreateNetwork(configs)
if err != nil {
return diag.Errorf("[ERR] failed to create a new network: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/civo/terraform-provider-civo

require (
github.com/civo/civogo v0.3.65
github.com/civo/civogo v0.3.66
github.com/google/uuid v1.3.1
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/civo/civogo v0.3.58 h1:FikCbwAKB5ovD8+NmSi7rzYBSpC4nUpGVpCyngEkTo4=
github.com/civo/civogo v0.3.58/go.mod h1:54lv/FOf7gh6wE9ZwVdw4yBehk8V1CvU9aWa4v6dvW0=
github.com/civo/civogo v0.3.65 h1:FZpkaVoTxcc4lAgRbh5fo65EPDBu/0xmJsoql5xEBHk=
github.com/civo/civogo v0.3.65/go.mod h1:S/iYmGvQOraxdRtcXeq/2mVX01/ia2qfpQUp2SsTLKA=
github.com/civo/civogo v0.3.66 h1:yzTsaQApTeH5UsRTtL4umx5ERAtzCpd4HuS9qTyoZs0=
github.com/civo/civogo v0.3.66/go.mod h1:S/iYmGvQOraxdRtcXeq/2mVX01/ia2qfpQUp2SsTLKA=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
Expand Down
Loading