From 6dc9e98f8f169c8e59dd74f50ee6df810da7dea8 Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Fri, 18 Aug 2023 23:24:43 +0530 Subject: [PATCH 1/5] Upgrade metal device resource and data source to use timeouts --- equinix/resource_metal_device.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/equinix/resource_metal_device.go b/equinix/resource_metal_device.go index 1596ff188..e104334da 100644 --- a/equinix/resource_metal_device.go +++ b/equinix/resource_metal_device.go @@ -806,8 +806,8 @@ func doReinstall(ctx context.Context, client *packngo.Client, d *schema.Resource return friendlyError(err) } - updateTimeout := d.Timeout(schema.TimeoutUpdate) - 30*time.Second - time.Since(start) - if err := waitForActiveDevice(ctx, d, meta, updateTimeout); err != nil { + deleteTimeout := d.Timeout(schema.TimeoutUpdate) - 30*time.Second - time.Since(start) + if err := waitForActiveDevice(ctx, d, meta, deleteTimeout); err != nil { return err } } From 37fa0984c3a6bcca74c847b6016352f7cc3f3e6d Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Wed, 23 Aug 2023 19:31:32 +0530 Subject: [PATCH 2/5] Acceptance tests for metal device timeouts --- equinix/resource_network_bgp_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/equinix/resource_network_bgp_test.go b/equinix/resource_network_bgp_test.go index b4131f3c1..f40bafb6b 100644 --- a/equinix/resource_network_bgp_test.go +++ b/equinix/resource_network_bgp_test.go @@ -2,6 +2,7 @@ package equinix import ( "context" + "github.com/packethost/packngo" "testing" "time" @@ -100,6 +101,20 @@ func (r *mockedBGPUpdateRequest) Execute() error { return nil } +var _ packngo.BGPConfigService = &mockBgpConfigService{} + +type mockBgpConfigService struct { + GetFn func(projectID string, getOpt *packngo.GetOptions) (*packngo.BGPConfig, *packngo.Response, error) + CreateFn func(projectID string, request packngo.CreateBGPConfigRequest) (*packngo.Response, error) +} + +func (s *mockBgpConfigService) Get(projectID string, getOpt *packngo.GetOptions) (*packngo.BGPConfig, *packngo.Response, error) { + return s.GetFn(projectID, getOpt) +} +func (s *mockBgpConfigService) Create(projectID string, request packngo.CreateBGPConfigRequest) (*packngo.Response, error) { + return s.CreateFn(projectID, request) +} + func TestNetworkBGP_createUpdateRequest(t *testing.T) { // given req := &mockedBGPUpdateRequest{data: make(map[string]interface{})} From e5e0c96cbe7c000b301c64588768ca8aceb2d97d Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Thu, 24 Aug 2023 18:49:13 +0530 Subject: [PATCH 3/5] Timeouts tests to be unit test to be able to run without TF_ACC --- equinix/resource_network_bgp_test.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/equinix/resource_network_bgp_test.go b/equinix/resource_network_bgp_test.go index f40bafb6b..b4131f3c1 100644 --- a/equinix/resource_network_bgp_test.go +++ b/equinix/resource_network_bgp_test.go @@ -2,7 +2,6 @@ package equinix import ( "context" - "github.com/packethost/packngo" "testing" "time" @@ -101,20 +100,6 @@ func (r *mockedBGPUpdateRequest) Execute() error { return nil } -var _ packngo.BGPConfigService = &mockBgpConfigService{} - -type mockBgpConfigService struct { - GetFn func(projectID string, getOpt *packngo.GetOptions) (*packngo.BGPConfig, *packngo.Response, error) - CreateFn func(projectID string, request packngo.CreateBGPConfigRequest) (*packngo.Response, error) -} - -func (s *mockBgpConfigService) Get(projectID string, getOpt *packngo.GetOptions) (*packngo.BGPConfig, *packngo.Response, error) { - return s.GetFn(projectID, getOpt) -} -func (s *mockBgpConfigService) Create(projectID string, request packngo.CreateBGPConfigRequest) (*packngo.Response, error) { - return s.CreateFn(projectID, request) -} - func TestNetworkBGP_createUpdateRequest(t *testing.T) { // given req := &mockedBGPUpdateRequest{data: make(map[string]interface{})} From ab508e15fd28827f1bafd09764eb0a96ea78c959 Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Wed, 30 Aug 2023 19:11:38 +0530 Subject: [PATCH 4/5] Testing Update and create --- equinix/resource_metal_device.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/equinix/resource_metal_device.go b/equinix/resource_metal_device.go index e104334da..1596ff188 100644 --- a/equinix/resource_metal_device.go +++ b/equinix/resource_metal_device.go @@ -806,8 +806,8 @@ func doReinstall(ctx context.Context, client *packngo.Client, d *schema.Resource return friendlyError(err) } - deleteTimeout := d.Timeout(schema.TimeoutUpdate) - 30*time.Second - time.Since(start) - if err := waitForActiveDevice(ctx, d, meta, deleteTimeout); err != nil { + updateTimeout := d.Timeout(schema.TimeoutUpdate) - 30*time.Second - time.Since(start) + if err := waitForActiveDevice(ctx, d, meta, updateTimeout); err != nil { return err } } From b20559b0dbca6da824939f0446e0118ead46159d Mon Sep 17 00:00:00 2001 From: Ayush Rangwala Date: Tue, 19 Sep 2023 12:49:35 +0530 Subject: [PATCH 5/5] fix deprecated statecontext in importer --- cmd/migration-tool/transforms.go | 32 ++++++++++++------- equinix/resource_metal_connection_acc_test.go | 1 - equinix/resource_network_bgp.go | 2 +- equinix/resource_network_device.go | 2 +- equinix/resource_network_device_link.go | 2 +- equinix/resource_network_ssh_key.go | 2 +- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/cmd/migration-tool/transforms.go b/cmd/migration-tool/transforms.go index 849c92360..e3937e31f 100644 --- a/cmd/migration-tool/transforms.go +++ b/cmd/migration-tool/transforms.go @@ -8,39 +8,47 @@ import ( ) // matches block headers, ex: -// resource "metal_project" "fooproject" { -// data "packet_vlan" "foovlan" { +// +// resource "metal_project" "fooproject" { +// data "packet_vlan" "foovlan" { var matchBlockHeader = regexp.MustCompile(`(resource|data)(\s+")(metal|packet)(.*?)`) // matches resource interpolation strings (Terraform v0.11 and earlier), ex: -// device_id = "${metal_device.foodevice.id}" +// +// device_id = "${metal_device.foodevice.id}" var matchResourceInterpolation = regexp.MustCompile(`(.*?)(\${\s*)(metal|packet)(_.*?)`) // matches resource reference (Terraform v0.12+), ex: -// device_id = metal_device.foodevice.id +// +// device_id = metal_device.foodevice.id var matchResourceReference = regexp.MustCompile(`(.*?)(=\s*)(metal|packet)(_.*?)`) // matches resource reference in function, ex: -// cidr_notation = join("/", [cidrhost(metal_reserved_ip_block.fooblock.cidr_notation, 0), "32"]) +// +// cidr_notation = join("/", [cidrhost(metal_reserved_ip_block.fooblock.cidr_notation, 0), "32"]) var matchResourceFunction = regexp.MustCompile(`(.*?)(\(\s*)(metal|packet)(_.*?)`) // matches resource reference in conditional, ex: -// ip_address = "${var.network_type == "public" ? metal_device.foodevice.access_public_ipv4 : metal_device.foodevice.access_private_ipv4}" -// ip_address = var.network_type == "public" ? metal_device.foodevice.access_public_ipv4 : metal_device.foodevice.access_private_ipv4 +// +// ip_address = "${var.network_type == "public" ? metal_device.foodevice.access_public_ipv4 : metal_device.foodevice.access_private_ipv4}" +// ip_address = var.network_type == "public" ? metal_device.foodevice.access_public_ipv4 : metal_device.foodevice.access_private_ipv4 var matchResourceConditional = regexp.MustCompile(`(.*?[:|\?])(\s*)(metal|packet)(_.*?)`) // matches resource reference in for loop,ex: -// toset([for network in metal_device.foodevice.network : network.family]) +// +// toset([for network in metal_device.foodevice.network : network.family]) var matchResourceForLoop = regexp.MustCompile(`(.*?)(in\s*)(metal|packet)(_.*?)`) // matches resource in expression,ex: -// tolist([metal_device.foodevice[*].access_public_ipv4]) -// !metal_ip_attachment.fooattach.public -// totalSpeed = metal_connection.fooconnA.speed + metal_connection.fooconnB.speed +// +// tolist([metal_device.foodevice[*].access_public_ipv4]) +// !metal_ip_attachment.fooattach.public +// totalSpeed = metal_connection.fooconnA.speed + metal_connection.fooconnB.speed var matchResourceExpression = regexp.MustCompile(`(.*?[\+|-|\*|\/|>|<|&|\|\||%|!|\[]\s*)(metal|packet)(_.*?)`) // matches datasource references, ex: -// address_family = "${lookup(data.packet_device_bgp_neighbors.test.bgp_neighbors[0], "address_family")}" +// +// address_family = "${lookup(data.packet_device_bgp_neighbors.test.bgp_neighbors[0], "address_family")}" var matchDatasourceReference = regexp.MustCompile(`(.*?data)(\.)(metal|packet)(_.*?)`) // replace specific string patterns in template files diff --git a/equinix/resource_metal_connection_acc_test.go b/equinix/resource_metal_connection_acc_test.go index af00b3be5..45cb754b4 100644 --- a/equinix/resource_metal_connection_acc_test.go +++ b/equinix/resource_metal_connection_acc_test.go @@ -113,7 +113,6 @@ func TestAccMetalConnection_shared_zside(t *testing.T) { }, }) - } func TestAccMetalConnection_shared(t *testing.T) { diff --git a/equinix/resource_network_bgp.go b/equinix/resource_network_bgp.go index cbd6fbae8..f8a068bdd 100644 --- a/equinix/resource_network_bgp.go +++ b/equinix/resource_network_bgp.go @@ -47,7 +47,7 @@ func resourceNetworkBGP() *schema.Resource { UpdateContext: resourceNetworkBGPUpdate, DeleteContext: resourceNetworkBGPDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: createNetworkBGPResourceSchema(), Timeouts: &schema.ResourceTimeout{ diff --git a/equinix/resource_network_device.go b/equinix/resource_network_device.go index bdefb4b56..cf9549fee 100644 --- a/equinix/resource_network_device.go +++ b/equinix/resource_network_device.go @@ -198,7 +198,7 @@ func resourceNetworkDevice() *schema.Resource { UpdateContext: resourceNetworkDeviceUpdate, DeleteContext: resourceNetworkDeviceDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: createNetworkDeviceSchema(), Timeouts: &schema.ResourceTimeout{ diff --git a/equinix/resource_network_device_link.go b/equinix/resource_network_device_link.go index ac77036c9..4b3097032 100644 --- a/equinix/resource_network_device_link.go +++ b/equinix/resource_network_device_link.go @@ -79,7 +79,7 @@ func resourceNetworkDeviceLink() *schema.Resource { UpdateContext: resourceNetworkDeviceLinkUpdate, DeleteContext: resourceNetworkDeviceLinkDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: createNetworkDeviceLinkResourceSchema(), Timeouts: &schema.ResourceTimeout{ diff --git a/equinix/resource_network_ssh_key.go b/equinix/resource_network_ssh_key.go index 788e0efe8..22d883070 100644 --- a/equinix/resource_network_ssh_key.go +++ b/equinix/resource_network_ssh_key.go @@ -33,7 +33,7 @@ func resourceNetworkSSHKey() *schema.Resource { ReadContext: resourceNetworkSSHKeyRead, DeleteContext: resourceNetworkSSHKeyDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: createNetworkSSHKeyResourceSchema(), Timeouts: &schema.ResourceTimeout{