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

Allow to select all regions for a user group #44

Merged
merged 4 commits into from
Aug 22, 2024
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
8 changes: 7 additions & 1 deletion cloudconnexa/data_source_user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ func dataSourceUserGroup() *schema.Resource {
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The list of VPN region IDs this user group is associated with.",
Description: "The list of region IDs this user group is associated with.",
},
"all_regions_included": {
Type: schema.TypeBool,
Computed: true,
Description: "If true all regions will be available for this user group.",
},
"internet_access": {
Type: schema.TypeString,
Expand Down Expand Up @@ -72,6 +77,7 @@ func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m inte
d.SetId(userGroup.ID)
d.Set("name", userGroup.Name)
d.Set("vpn_region_ids", userGroup.VpnRegionIds)
d.Set("all_regions_included", userGroup.AllRegionsIncluded)
d.Set("internet_access", userGroup.InternetAccess)
d.Set("max_device", userGroup.MaxDevice)
d.Set("system_subnets", userGroup.SystemSubnets)
Expand Down
30 changes: 20 additions & 10 deletions cloudconnexa/resource_user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ func resourceUserGroup() *schema.Resource {
},
"vpn_region_ids": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
Description: "A list of VPN regions that are accessible to the user group.",
Optional: true,
Description: "A list of regions that are accessible to the user group.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"all_regions_included": {
Type: schema.TypeBool,
Optional: true,
ExactlyOneOf: []string{"vpn_region_ids", "all_regions_included"},
Description: "If true all regions will be available for this user group.",
},
},
}
}
Expand Down Expand Up @@ -106,14 +111,16 @@ func resourceDataToUserGroup(data *schema.ResourceData) *cloudconnexa.UserGroup
for _, r := range configVpnRegionIds {
vpnRegionIds = append(vpnRegionIds, r.(string))
}
allRegionsIncluded := data.Get("all_regions_included").(bool)

ug := &cloudconnexa.UserGroup{
Name: name,
ConnectAuth: connectAuth,
MaxDevice: maxDevice,
SystemSubnets: systemSubnets,
VpnRegionIds: vpnRegionIds,
InternetAccess: internetAccess,
Name: name,
ConnectAuth: connectAuth,
MaxDevice: maxDevice,
SystemSubnets: systemSubnets,
VpnRegionIds: vpnRegionIds,
InternetAccess: internetAccess,
AllRegionsIncluded: allRegionsIncluded,
}
return ug
}
Expand All @@ -124,8 +131,11 @@ func updateUserGroupData(data *schema.ResourceData, userGroup *cloudconnexa.User
_ = data.Set("max_device", userGroup.MaxDevice)
_ = data.Set("name", userGroup.Name)
_ = data.Set("system_subnets", userGroup.SystemSubnets)
_ = data.Set("vpn_region_ids", userGroup.VpnRegionIds)
_ = data.Set("internet_access", userGroup.InternetAccess)
if !userGroup.AllRegionsIncluded {
_ = data.Set("vpn_region_ids", userGroup.VpnRegionIds)
}
_ = data.Set("all_regions_included", userGroup.AllRegionsIncluded)
}

func resourceUserGroupDelete(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
Expand Down
3 changes: 2 additions & 1 deletion docs/data-sources/user_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ Use an `cloudconnexa_user_group` data source to read an CloudConnexa user group.
- `internet_access` (String) The type of internet access provided. Valid values are `BLOCKED`, `GLOBAL_INTERNET`, or `LOCAL`. Defaults to `LOCAL`.
- `max_device` (Number) The maximum number of devices per user.
- `system_subnets` (List of String) The IPV4 and IPV6 addresses of the subnets associated with this user group.
- `vpn_region_ids` (List of String) The list of VPN region IDs this user group is associated with.
- `vpn_region_ids` (List of String) The list of region IDs this user group is associated with.
- `all_regions_included` (Boolean) If true all regions will be available for this user group.
3 changes: 2 additions & 1 deletion docs/resources/user_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ Use `cloudconnexa_user_group` to create an CloudConnexa user group.
### Required

- `name` (String) The name of the user group.
- `vpn_region_ids` (List of String) A list of VPN regions that are accessible to the user group.

### Optional

- `connect_auth` (String)
- `internet_access` (String)
- `max_device` (Number) The maximum number of devices that can be connected to the user group.
- `system_subnets` (List of String) A list of subnets that are accessible to the user group.
- `vpn_region_ids` (List of String) A list of regions that are accessible to the user group.
- `all_regions_included` (Boolean) If true all regions will be available for this user group.

### Read-Only

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/gruntwork-io/terratest v0.47.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.13
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.15
github.com/stretchr/testify v1.9.0
)

Expand Down Expand Up @@ -89,7 +89,7 @@ require (
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/api v0.162.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.13 h1:Bm47oT/O+CwXdwUu84NZZXETZCo/9Th3Cx+EGUXvyPU=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.13/go.mod h1:udq5IDkgXvMO6mQUEFsLHzEyGGAduhO0jJvlb9f4JkE=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.15 h1:AcU6zhs8WvOPQ7s3kJ+6ikk6RsJzKhgjTrMFnkIezdo=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.15/go.mod h1:WJZU+oOwHUYoO7Q2tFnGavKGbhrAvo8OEgvvr9EEtCw=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -797,8 +797,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down
Loading