Skip to content

Commit

Permalink
Add "description" to "cloudconnexa_network" resource (#11)
Browse files Browse the repository at this point in the history
* fixed network data source not mapping connectors

* [draft, client must be updated] fixed connector description not mapping in resources

* fixed connector list mappers

* Added description to cloudconnexa_connector

* Added description to cloudconnexa_connector

* Added description to cloudconnexa_connector

* Update documentation

* Revert "Update documentation"

This reverts commit e798a39.

---------

Co-authored-by: michaelfmnk <[email protected]>
  • Loading branch information
sahaqaa and michaelfmnk authored Jul 3, 2024
1 parent c80bc60 commit 369e52a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
19 changes: 18 additions & 1 deletion cloudconnexa/data_source_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,24 @@ func dataSourceHostRead(ctx context.Context, d *schema.ResourceData, m interface
d.Set("name", host.Name)
d.Set("internet_access", host.InternetAccess)
d.Set("system_subnets", host.SystemSubnets)
d.Set("connectors", getConnectorsSlice(&host.Connectors))
d.Set("connectors", getConnectorsSliceByConnectors(&host.Connectors))
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}

func getConnectorsSliceByConnectors(connectors *[]cloudconnexa.Connector) []interface{} {
conns := make([]interface{}, len(*connectors))
for i, c := range *connectors {
connector := make(map[string]interface{})
connector["id"] = c.Id
connector["name"] = c.Name
connector["network_item_id"] = c.NetworkItemId
connector["network_item_type"] = c.NetworkItemType
connector["vpn_region_id"] = c.VpnRegionId
connector["ip_v4_address"] = c.IPv4Address
connector["ip_v6_address"] = c.IPv6Address
connector["description"] = c.Description
conns[i] = connector
}
return conns
}
10 changes: 8 additions & 2 deletions cloudconnexa/data_source_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func dataSourceNetwork() *schema.Resource {
Computed: true,
Description: "The connector name.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The default connection description.",
},
"network_item_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -134,7 +139,7 @@ func dataSourceNetworkRead(ctx context.Context, d *schema.ResourceData, m interf
d.Set("internet_access", network.InternetAccess)
d.Set("system_subnets", network.SystemSubnets)
d.Set("routes", getRoutesSlice(&network.Routes))
//d.Set("connectors", getConnectorsSlice(&network.Connectors))
d.Set("connectors", getConnectorsSliceByNetworkConnectors(&network.Connectors))
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}
Expand All @@ -151,7 +156,7 @@ func getRoutesSlice(networkRoutes *[]cloudconnexa.Route) []interface{} {
return routes
}

func getConnectorsSlice(connectors *[]cloudconnexa.Connector) []interface{} {
func getConnectorsSliceByNetworkConnectors(connectors *[]cloudconnexa.NetworkConnector) []interface{} {
conns := make([]interface{}, len(*connectors))
for i, c := range *connectors {
connector := make(map[string]interface{})
Expand All @@ -162,6 +167,7 @@ func getConnectorsSlice(connectors *[]cloudconnexa.Connector) []interface{} {
connector["vpn_region_id"] = c.VpnRegionId
connector["ip_v4_address"] = c.IPv4Address
connector["ip_v6_address"] = c.IPv6Address
connector["description"] = c.Description
conns[i] = connector
}
return conns
Expand Down
11 changes: 11 additions & 0 deletions cloudconnexa/resource_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func resourceConnector() *schema.Resource {
ForceNew: true,
Description: "The connector display name.",
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "Managed by Terraform",
ValidateFunc: validation.StringLenBetween(1, 120),
Description: "The display description for this resource. Defaults to `Managed by Terraform`.",
},
"vpn_region_id": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -71,11 +79,13 @@ func resourceConnectorCreate(ctx context.Context, d *schema.ResourceData, m inte
networkItemId := d.Get("network_item_id").(string)
networkItemType := d.Get("network_item_type").(string)
vpnRegionId := d.Get("vpn_region_id").(string)
description := d.Get("description").(string)
connector := cloudconnexa.Connector{
Name: name,
NetworkItemId: networkItemId,
NetworkItemType: networkItemType,
VpnRegionId: vpnRegionId,
Description: description,
}
conn, err := c.Connectors.Create(connector, networkItemId)
if err != nil {
Expand Down Expand Up @@ -141,6 +151,7 @@ func getConnectorSlice(connectors []cloudconnexa.Connector, networkItemId string
connector["id"] = c.Id
connector["name"] = c.Name
connector["network_item_id"] = c.NetworkItemId
connector["description"] = c.Description
connector["network_item_type"] = c.NetworkItemType
connector["vpn_region_id"] = c.VpnRegionId
connector["ip_v4_address"] = c.IPv4Address
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.3
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.4
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.3 h1:aJ6yGyiw5nFXkQ6HE5dnJCQ0ag9cdLf9ARB2OjSHeDY=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.3/go.mod h1:udq5IDkgXvMO6mQUEFsLHzEyGGAduhO0jJvlb9f4JkE=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.4 h1:0Z8eTHPDYUFH3kCA1DTemiUnlPK9FhEuJhZB3bG1usE=
github.com/openvpn/cloudconnexa-go-client/v2 v2.0.4/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 369e52a

Please sign in to comment.