Skip to content

Commit

Permalink
Merge branch 'main' into feature/datasources-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sahaqaa authored Jul 30, 2024
2 parents d2b212c + a07bffb commit 5bfa1c2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
17 changes: 17 additions & 0 deletions cloudconnexa/data_source_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ func dataSourceHost() *schema.Resource {
Required: true,
Description: "The name of the host.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the host.",
},
"domain": {
Type: schema.TypeString,
Computed: true,
Description: "The host domain.",
},
"internet_access": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -51,6 +61,11 @@ func dataSourceHost() *schema.Resource {
Computed: true,
Description: "The connector name.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The connector description.",
},
"network_item_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -92,6 +107,8 @@ func dataSourceHostRead(ctx context.Context, d *schema.ResourceData, m interface
}
d.SetId(host.Id)
d.Set("name", host.Name)
d.Set("description", host.Description)
d.Set("domain", host.Domain)
d.Set("internet_access", host.InternetAccess)
d.Set("system_subnets", host.SystemSubnets)
d.Set("connectors", getConnectorsSliceByConnectors(&host.Connectors))
Expand Down
23 changes: 22 additions & 1 deletion cloudconnexa/resource_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func resourceHost() *schema.Resource {
ValidateFunc: validation.StringLenBetween(1, 120),
Description: "The description for the UI. Defaults to `Managed by Terraform`.",
},
"domain": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 253),
Description: "The domain of the host.",
},
"internet_access": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -70,6 +76,13 @@ func resourceHost() *schema.Resource {
Required: true,
Description: "Name of the connector associated with this host.",
},
"description": {
Type: schema.TypeString,
Optional: true,
Default: "Managed by Terraform",
ValidateFunc: validation.StringLenBetween(1, 120),
Description: "The description for the UI. Defaults to `Managed by Terraform`.",
},
"vpn_region_id": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -114,11 +127,13 @@ func resourceHostCreate(ctx context.Context, d *schema.ResourceData, m interface
for _, c := range configConnectors.List() {
connectors = append(connectors, cloudconnexa.Connector{
Name: c.(map[string]interface{})["name"].(string),
Description: c.(map[string]interface{})["description"].(string),
VpnRegionId: c.(map[string]interface{})["vpn_region_id"].(string),
})
}
h := cloudconnexa.Host{
Name: d.Get("name").(string),
Domain: d.Get("domain").(string),
Description: d.Get("description").(string),
InternetAccess: d.Get("internet_access").(string),
Connectors: connectors,
Expand Down Expand Up @@ -153,6 +168,7 @@ func resourceHostRead(ctx context.Context, d *schema.ResourceData, m interface{}
}
d.Set("name", host.Name)
d.Set("description", host.Description)
d.Set("domain", host.Domain)
d.Set("internet_access", host.InternetAccess)
d.Set("system_subnets", host.SystemSubnets)

Expand All @@ -174,6 +190,7 @@ func resourceHostUpdate(ctx context.Context, d *schema.ResourceData, m interface
// This happens when importing the resource
newConnector := cloudconnexa.Connector{
Name: newSet.List()[0].(map[string]interface{})["name"].(string),
Description: newSet.List()[0].(map[string]interface{})["description"].(string),
VpnRegionId: newSet.List()[0].(map[string]interface{})["vpn_region_id"].(string),
NetworkItemType: "HOST",
}
Expand All @@ -194,6 +211,7 @@ func resourceHostUpdate(ctx context.Context, d *schema.ResourceData, m interface
if !oldSet.Contains(n) {
newConnector := cloudconnexa.Connector{
Name: n.(map[string]interface{})["name"].(string),
Description: n.(map[string]interface{})["description"].(string),
VpnRegionId: n.(map[string]interface{})["vpn_region_id"].(string),
NetworkItemType: "HOST",
}
Expand All @@ -205,14 +223,16 @@ func resourceHostUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
}
if d.HasChanges("name", "description", "internet_access") {
if d.HasChanges("name", "description", "domain", "internet_access") {
_, newName := d.GetChange("name")
_, newDescription := d.GetChange("description")
_, newDomain := d.GetChange("domain")
_, newAccess := d.GetChange("internet_access")
err := c.Hosts.Update(cloudconnexa.Host{
Id: d.Id(),
Name: newName.(string),
Description: newDescription.(string),
Domain: newDomain.(string),
InternetAccess: newAccess.(string),
})
if err != nil {
Expand Down Expand Up @@ -253,6 +273,7 @@ func getConnectorsListItem(c *cloudconnexa.Client, connector cloudconnexa.Connec
connectorsData := map[string]interface{}{
"id": connector.Id,
"name": connector.Name,
"description": connector.Description,
"vpn_region_id": connector.VpnRegionId,
"ip_v4_address": connector.IPv4Address,
"ip_v6_address": connector.IPv6Address,
Expand Down
2 changes: 1 addition & 1 deletion 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.46.1
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.10
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.11
github.com/stretchr/testify v1.9.0
)

Expand Down
4 changes: 2 additions & 2 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.10 h1:k5wx9syxxwNNKbfEQkVjb/4hjhBrhbgBDmeT72yNe3w=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.10/go.mod h1:udq5IDkgXvMO6mQUEFsLHzEyGGAduhO0jJvlb9f4JkE=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.11 h1:NZ5cdmKhhjIYRbmyHXvRsCUTOI4tOtPlBaXpO/PgSnI=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.11/go.mod h1:udq5IDkgXvMO6mQUEFsLHzEyGGAduhO0jJvlb9f4JkE=
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

0 comments on commit 5bfa1c2

Please sign in to comment.