From aa31e7177456e68c212cae8c00cc526c8171edbd Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 4 Jul 2024 12:21:56 +0200 Subject: [PATCH 01/13] update connector implemented --- cloudconnexa/resource_connector.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cloudconnexa/resource_connector.go b/cloudconnexa/resource_connector.go index 300881e..0c5c062 100644 --- a/cloudconnexa/resource_connector.go +++ b/cloudconnexa/resource_connector.go @@ -16,6 +16,7 @@ func resourceConnector() *schema.Resource { CreateContext: resourceConnectorCreate, ReadContext: resourceConnectorRead, DeleteContext: resourceConnectorDelete, + UpdateContext: resourceConnectorUpdate, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -64,6 +65,23 @@ func resourceConnector() *schema.Resource { } } +func resourceConnectorUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*cloudconnexa.Client) + var diags diag.Diagnostics + connector := cloudconnexa.Connector{ + Id: d.Id(), + Name: d.Get("name").(string), + NetworkItemId: d.Get("network_item_id").(string), + NetworkItemType: d.Get("network_item_type").(string), + VpnRegionId: d.Get("vpn_region_id").(string), + } + _, err := c.Connectors.Update(connector) + if err != nil { + return append(diags, diag.FromErr(err)...) + } + return diags +} + func resourceConnectorCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*cloudconnexa.Client) var diags diag.Diagnostics From af0a398b0ce8ca7996af080afa3f25d0f6b02b8b Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Fri, 5 Jul 2024 13:36:01 +0200 Subject: [PATCH 02/13] fixed updated fields list in resource connector --- cloudconnexa/resource_connector.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cloudconnexa/resource_connector.go b/cloudconnexa/resource_connector.go index 0c5c062..3940920 100644 --- a/cloudconnexa/resource_connector.go +++ b/cloudconnexa/resource_connector.go @@ -69,11 +69,10 @@ func resourceConnectorUpdate(ctx context.Context, d *schema.ResourceData, m inte c := m.(*cloudconnexa.Client) var diags diag.Diagnostics connector := cloudconnexa.Connector{ - Id: d.Id(), - Name: d.Get("name").(string), - NetworkItemId: d.Get("network_item_id").(string), - NetworkItemType: d.Get("network_item_type").(string), - VpnRegionId: d.Get("vpn_region_id").(string), + Id: d.Id(), + Name: d.Get("name").(string), + Description: d.Get("description").(string), + VpnRegionId: d.Get("vpn_region_id").(string), } _, err := c.Connectors.Update(connector) if err != nil { From f1f15a67e7d62d2321a89b09cf2d21c7eed2ab9c Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Thu, 4 Jul 2024 12:21:56 +0200 Subject: [PATCH 03/13] update connector implemented --- cloudconnexa/resource_connector.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cloudconnexa/resource_connector.go b/cloudconnexa/resource_connector.go index c55925b..08c7b21 100644 --- a/cloudconnexa/resource_connector.go +++ b/cloudconnexa/resource_connector.go @@ -16,6 +16,7 @@ func resourceConnector() *schema.Resource { CreateContext: resourceConnectorCreate, ReadContext: resourceConnectorRead, DeleteContext: resourceConnectorDelete, + UpdateContext: resourceConnectorUpdate, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -72,6 +73,23 @@ func resourceConnector() *schema.Resource { } } +func resourceConnectorUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*cloudconnexa.Client) + var diags diag.Diagnostics + connector := cloudconnexa.Connector{ + Id: d.Id(), + Name: d.Get("name").(string), + NetworkItemId: d.Get("network_item_id").(string), + NetworkItemType: d.Get("network_item_type").(string), + VpnRegionId: d.Get("vpn_region_id").(string), + } + _, err := c.Connectors.Update(connector) + if err != nil { + return append(diags, diag.FromErr(err)...) + } + return diags +} + func resourceConnectorCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*cloudconnexa.Client) var diags diag.Diagnostics From 44b1ab444cf4416723e060795e447e66ccab1f40 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Fri, 5 Jul 2024 13:36:01 +0200 Subject: [PATCH 04/13] fixed updated fields list in resource connector --- cloudconnexa/resource_connector.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cloudconnexa/resource_connector.go b/cloudconnexa/resource_connector.go index 08c7b21..51ea3bf 100644 --- a/cloudconnexa/resource_connector.go +++ b/cloudconnexa/resource_connector.go @@ -77,11 +77,10 @@ func resourceConnectorUpdate(ctx context.Context, d *schema.ResourceData, m inte c := m.(*cloudconnexa.Client) var diags diag.Diagnostics connector := cloudconnexa.Connector{ - Id: d.Id(), - Name: d.Get("name").(string), - NetworkItemId: d.Get("network_item_id").(string), - NetworkItemType: d.Get("network_item_type").(string), - VpnRegionId: d.Get("vpn_region_id").(string), + Id: d.Id(), + Name: d.Get("name").(string), + Description: d.Get("description").(string), + VpnRegionId: d.Get("vpn_region_id").(string), } _, err := c.Connectors.Update(connector) if err != nil { From da8eb636f18bf5b467729511550780012bcbf2ce Mon Sep 17 00:00:00 2001 From: "oleksandr.lytvyn" Date: Mon, 8 Jul 2024 17:31:49 +0300 Subject: [PATCH 05/13] init --- Makefile | 2 +- cloudconnexa/resource_connector.go | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 937057a..771a1d0 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ NAMESPACE=openvpn NAME=cloudconnexa VERSION=0.0.12 BINARY=terraform-provider-${NAME} -OS_ARCH=darwin_arm64 +OS_ARCH ?= $(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) default: install diff --git a/cloudconnexa/resource_connector.go b/cloudconnexa/resource_connector.go index 51ea3bf..2d8e79f 100644 --- a/cloudconnexa/resource_connector.go +++ b/cloudconnexa/resource_connector.go @@ -24,21 +24,18 @@ func resourceConnector() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - 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`.", + Description: "The description for the UI. Defaults to `Managed by Terraform`.", }, "vpn_region_id": { Type: schema.TypeString, Required: true, - ForceNew: true, Description: "The id of the region where the connector will be deployed.", }, "network_item_type": { From 8c1b7a8ef591927ccbfd8a65fbf6670c25304767 Mon Sep 17 00:00:00 2001 From: Olexandr Lytvyn Date: Fri, 5 Jul 2024 15:37:51 +0300 Subject: [PATCH 06/13] Add small changes to allow provider to be initialized --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 771a1d0..937057a 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ NAMESPACE=openvpn NAME=cloudconnexa VERSION=0.0.12 BINARY=terraform-provider-${NAME} -OS_ARCH ?= $(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) +OS_ARCH=darwin_arm64 default: install From 212e8a5b5887e8fc50cb48c1d6a5ddeb82901961 Mon Sep 17 00:00:00 2001 From: Olexandr Lytvyn Date: Fri, 5 Jul 2024 15:53:48 +0300 Subject: [PATCH 07/13] Add description field to resourceConnectorCreate function --- cloudconnexa/resource_connector.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cloudconnexa/resource_connector.go b/cloudconnexa/resource_connector.go index 2d8e79f..e3613bb 100644 --- a/cloudconnexa/resource_connector.go +++ b/cloudconnexa/resource_connector.go @@ -90,6 +90,7 @@ func resourceConnectorCreate(ctx context.Context, d *schema.ResourceData, m inte c := m.(*cloudconnexa.Client) var diags diag.Diagnostics name := d.Get("name").(string) + description := d.Get("description").(string) networkItemId := d.Get("network_item_id").(string) networkItemType := d.Get("network_item_type").(string) vpnRegionId := d.Get("vpn_region_id").(string) From 9bb8ec94dfd5c880b47282f9571576d3e6bc1fd3 Mon Sep 17 00:00:00 2001 From: "oleksandr.lytvyn" Date: Mon, 8 Jul 2024 17:48:06 +0300 Subject: [PATCH 08/13] Remove duplicate description field --- cloudconnexa/resource_connector.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cloudconnexa/resource_connector.go b/cloudconnexa/resource_connector.go index e3613bb..ef78191 100644 --- a/cloudconnexa/resource_connector.go +++ b/cloudconnexa/resource_connector.go @@ -94,7 +94,6 @@ 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, From 45a9dbeba340143b709b061714c2708cd62970fc Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Fri, 26 Jul 2024 13:13:47 +0200 Subject: [PATCH 09/13] update network uses new update connector client method --- cloudconnexa/resource_network.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cloudconnexa/resource_network.go b/cloudconnexa/resource_network.go index f69d0e7..6168ef2 100644 --- a/cloudconnexa/resource_network.go +++ b/cloudconnexa/resource_network.go @@ -294,21 +294,15 @@ func resourceNetworkUpdate(ctx context.Context, d *schema.ResourceData, m interf newMap := newSlice[0].(map[string]interface{}) if oldMap["name"].(string) != newMap["name"].(string) || oldMap["vpn_region_id"].(string) != newMap["vpn_region_id"].(string) { newConnector := cloudconnexa.Connector{ + Id: d.Id(), Name: newMap["name"].(string), VpnRegionId: newMap["vpn_region_id"].(string), NetworkItemType: "NETWORK", } - _, err := c.Connectors.Create(newConnector, d.Id()) + _, err := c.Connectors.Update(newConnector) if err != nil { return append(diags, diag.FromErr(err)...) } - if len(oldMap["id"].(string)) > 0 { - // This can sometimes happen when importing the resource - err = c.Connectors.Delete(oldMap["id"].(string), d.Id(), oldMap["network_item_type"].(string)) - if err != nil { - return append(diags, diag.FromErr(err)...) - } - } } } } From 9518bf12cdb9470ccf97597b646f031e744d6903 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Fri, 26 Jul 2024 13:17:14 +0200 Subject: [PATCH 10/13] updated client lib --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3b33588..fd32a41 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.8 + github.com/openvpn/cloudconnexa-go-client/v2 v2.0.9 github.com/stretchr/testify v1.9.0 ) diff --git a/go.sum b/go.sum index 546fc20..8294df8 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.8 h1:67NXu2WqNnE05fhrq1HXbQKFMidhnd7ts6SFeuZSkLo= -github.com/openvpn/cloudconnexa-go-client/v2 v2.0.8/go.mod h1:udq5IDkgXvMO6mQUEFsLHzEyGGAduhO0jJvlb9f4JkE= +github.com/openvpn/cloudconnexa-go-client/v2 v2.0.9 h1:1clb6wRbCjJXUM41Jrbe8/0LBYGNMnCA77QIGAAiUpQ= +github.com/openvpn/cloudconnexa-go-client/v2 v2.0.9/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= From 2f667d52ebe5b2bedc626f914c37e13c371310f3 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Fri, 26 Jul 2024 14:06:38 +0200 Subject: [PATCH 11/13] fixed resourceNetworkUpdate --- cloudconnexa/resource_network.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cloudconnexa/resource_network.go b/cloudconnexa/resource_network.go index 6168ef2..c6af144 100644 --- a/cloudconnexa/resource_network.go +++ b/cloudconnexa/resource_network.go @@ -283,6 +283,7 @@ func resourceNetworkUpdate(ctx context.Context, d *schema.ResourceData, m interf newConnector := cloudconnexa.Connector{ Name: newSlice[0].(map[string]interface{})["name"].(string), VpnRegionId: newSlice[0].(map[string]interface{})["vpn_region_id"].(string), + Description: newSlice[0].(map[string]interface{})["description"].(string), NetworkItemType: "NETWORK", } _, err := c.Connectors.Create(newConnector, d.Id()) @@ -292,7 +293,10 @@ func resourceNetworkUpdate(ctx context.Context, d *schema.ResourceData, m interf } else { oldMap := oldSlice[0].(map[string]interface{}) newMap := newSlice[0].(map[string]interface{}) - if oldMap["name"].(string) != newMap["name"].(string) || oldMap["vpn_region_id"].(string) != newMap["vpn_region_id"].(string) { + if oldMap["name"].(string) != newMap["name"].(string) || + oldMap["description"].(string) != newMap["description"].(string) || + oldMap["vpn_region_id"].(string) != newMap["vpn_region_id"].(string) { + newConnector := cloudconnexa.Connector{ Id: d.Id(), Name: newMap["name"].(string), From bb78146294bad28291fc80d0c1353201ade3c3c4 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Fri, 26 Jul 2024 14:09:56 +0200 Subject: [PATCH 12/13] fixed resourceNetworkUpdate --- cloudconnexa/resource_network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudconnexa/resource_network.go b/cloudconnexa/resource_network.go index c6af144..1dc6019 100644 --- a/cloudconnexa/resource_network.go +++ b/cloudconnexa/resource_network.go @@ -298,7 +298,7 @@ func resourceNetworkUpdate(ctx context.Context, d *schema.ResourceData, m interf oldMap["vpn_region_id"].(string) != newMap["vpn_region_id"].(string) { newConnector := cloudconnexa.Connector{ - Id: d.Id(), + Id: oldMap["id"].(string), Name: newMap["name"].(string), VpnRegionId: newMap["vpn_region_id"].(string), NetworkItemType: "NETWORK", From 62e25d8f7dc2db795027a7837251a0bbb2287f9f Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Fri, 26 Jul 2024 14:12:06 +0200 Subject: [PATCH 13/13] fixed resourceNetworkUpdate --- cloudconnexa/resource_network.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cloudconnexa/resource_network.go b/cloudconnexa/resource_network.go index 1dc6019..bfd3b02 100644 --- a/cloudconnexa/resource_network.go +++ b/cloudconnexa/resource_network.go @@ -301,6 +301,7 @@ func resourceNetworkUpdate(ctx context.Context, d *schema.ResourceData, m interf Id: oldMap["id"].(string), Name: newMap["name"].(string), VpnRegionId: newMap["vpn_region_id"].(string), + Description: newMap["description"].(string), NetworkItemType: "NETWORK", } _, err := c.Connectors.Update(newConnector)