Skip to content
Open
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
112 changes: 112 additions & 0 deletions cloudstack/resource_cloudstack_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,26 @@
ForceNew: true,
},

"ip6cidr": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"gateway": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"ip6gateway": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"startip": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -99,6 +112,20 @@
ForceNew: true,
},

"startipv6": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"endipv6": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"network_domain": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -209,6 +236,31 @@
p.SetEndip(endip)
}

// IPv6 support
if ip6cidr, ok := d.GetOk("ip6cidr"); ok && ip6cidr.(string) != none {
m6, err := parseCIDRv6(d, no.Specifyipranges)
if err != nil {
return err
}

p.SetIp6cidr(ip6cidr)

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / build

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.12.* with Cloudstack 4.19.0.1

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.11.* with Cloudstack 4.19.0.1

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.12.* with Cloudstack 4.19.3.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.8.* with Cloudstack 4.19.1.3

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.9.* with Cloudstack 4.19.3.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.9.* with Cloudstack 4.19.0.1

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.11.* with Cloudstack 4.19.2.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.8.* with Cloudstack 4.19.0.1

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.8.* with Cloudstack 4.19.3.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.12.* with Cloudstack 4.19.2.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.12.* with Cloudstack 4.19.1.3

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.12.* with Cloudstack 4.20.1.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.11.* with Cloudstack 4.19.1.3

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.8.* with Cloudstack 4.19.2.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.9.* with Cloudstack 4.19.2.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.11.* with Cloudstack 4.19.3.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.9.* with Cloudstack 4.19.1.3

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.8.* with Cloudstack 4.20.1.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / OpenTofu 1.9.* with Cloudstack 4.20.1.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

Check failure on line 246 in cloudstack/resource_cloudstack_network.go

View workflow job for this annotation

GitHub Actions / Terraform 1.11.* with Cloudstack 4.20.1.0

cannot use ip6cidr (variable of type interface{}) as string value in argument to p.SetIp6cidr: need type assertion

// Only set the start IPv6 if we have one
if startipv6, ok := m6["startipv6"]; ok {
p.SetStartipv6(startipv6)
}

// Only set the ipv6 gateway if we have one
if ip6gateway, ok := m6["ip6gateway"]; ok {
p.SetIp6gateway(ip6gateway)
}

// Only set the end IPv6 if we have one
if endipv6, ok := m6["endipv6"]; ok {
p.SetEndipv6(endipv6)
}
}

// Set the network domain if we have one
if networkDomain, ok := d.GetOk("network_domain"); ok {
p.SetNetworkdomain(networkDomain.(string))
Expand Down Expand Up @@ -306,6 +358,16 @@
d.Set("network_domain", n.Networkdomain)
d.Set("vpc_id", n.Vpcid)

if n.Ip6cidr == "" {
n.Ip6cidr = none
}
d.Set("ip6cidr", n.Ip6cidr)

if n.Ip6gateway == "" {
n.Ip6gateway = none
}
d.Set("ip6gateway", n.Ip6gateway)

if n.Aclid == "" {
n.Aclid = none
}
Expand Down Expand Up @@ -471,3 +533,53 @@

return m, nil
}

func parseCIDRv6(d *schema.ResourceData, specifyiprange bool) (map[string]string, error) {
m := make(map[string]string, 4)

cidr := d.Get("ip6cidr").(string)
_, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
return nil, fmt.Errorf("Unable to parse cidr %s: %s", cidr, err)
}

if gateway, ok := d.GetOk("ip6gateway"); ok {
m["ip6gateway"] = gateway.(string)
} else {
m["ip6gateway"] = ipnet.IP.String()
}

if startip, ok := d.GetOk("startip"); ok {
m["startip"] = startip.(string)
} else if specifyiprange {
ip16 := ipnet.IP.To16()
if ip16 == nil {
return nil, fmt.Errorf("cidr not valid for ipv6")
}

myip := make(net.IP, len(ip16))
copy(myip, ip16)
myip[len(ip16)-1] = 2
m["startip"] = myip.String()
}

if endip, ok := d.GetOk("endipv6"); ok {
m["endipv6"] = endip.(string)
} else if specifyiprange {
ip16 := ipnet.IP.To16()
if ip16 == nil {
return nil, fmt.Errorf("cidr not valid for ipv6")
}

last := make(net.IP, len(ip16))
copy(last, ip16)

for i := range ip16 {
// Perform bitwise OR with the inverse of the mask
last[i] |= ^ipnet.Mask[i]
}
m["endipv6"] = last.String()
}

return m, nil
}
12 changes: 12 additions & 0 deletions website/docs/r/network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ The following arguments are supported:
* `endip` - (Optional) End of the IP block that will be available on the
network. Defaults to the last available IP in the range.

* `ip6cidr` - (Optional) The IPv6 CIDR block for the network. Changing this
forces a new resource to be created.

* `ip6gateway` - (Optional) IPv6 Gateway that will be provided to the instances
in this network. Defaults to the first usable IP in the range.

* `startipv6` - (Optional) Start of the IPv6 block that will be available on the
network. Defaults to the second available IP in the range.

* `endipv6` - (Optional) End of the IPv6 block that will be available on the
network. Defaults to the last available IP in the range.

* `network_domain` - (Optional) DNS domain for the network.

* `network_offering` - (Required) The name or ID of the network offering to use
Expand Down
Loading