From 369e52af21fca5387e34dd53d2e90d8d72c02177 Mon Sep 17 00:00:00 2001 From: Oleksandr Lytvyn Date: Wed, 3 Jul 2024 16:01:34 +0300 Subject: [PATCH] Add "description" to "cloudconnexa_network" resource (#11) * 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 e798a397992fdad7230fb1b51c412e90d0215f62. --------- Co-authored-by: michaelfmnk --- cloudconnexa/data_source_host.go | 19 ++++++++++++++++++- cloudconnexa/data_source_network.go | 10 ++++++++-- cloudconnexa/resource_connector.go | 11 +++++++++++ go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/cloudconnexa/data_source_host.go b/cloudconnexa/data_source_host.go index ca29cf8..54d2d65 100644 --- a/cloudconnexa/data_source_host.go +++ b/cloudconnexa/data_source_host.go @@ -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 +} diff --git a/cloudconnexa/data_source_network.go b/cloudconnexa/data_source_network.go index 2d9c27f..1a68382 100644 --- a/cloudconnexa/data_source_network.go +++ b/cloudconnexa/data_source_network.go @@ -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, @@ -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 } @@ -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{}) @@ -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 diff --git a/cloudconnexa/resource_connector.go b/cloudconnexa/resource_connector.go index 300881e..c55925b 100644 --- a/cloudconnexa/resource_connector.go +++ b/cloudconnexa/resource_connector.go @@ -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, @@ -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 { @@ -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 diff --git a/go.mod b/go.mod index cf389a8..44cb4b0 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 678c9e0..0dba60f 100644 --- a/go.sum +++ b/go.sum @@ -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=