diff --git a/go.mod b/go.mod index 152c7d7c..96b46244 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/HewlettPackard/hpegl-vmaas-terraform-resources go 1.17 require ( - github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.4 + github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.5 github.com/golang/mock v1.6.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-docs v0.9.0 diff --git a/go.sum b/go.sum index 20bd90f6..bfb2f1f6 100644 --- a/go.sum +++ b/go.sum @@ -71,18 +71,8 @@ github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.1 h1:OG6FsXwEn3Vt9QeJ0T73jzhF+7iXCucDp1jJjOt+kZI= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.1/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.2-0.20230206060111-b9ce4e0ba12b h1:XioqpC43aRWkNuzkF9oZ/S+/Ok3C0hUdM4/BGSyUzRU= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.2-0.20230206060111-b9ce4e0ba12b/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3-0.20230607070149-edbaab2cecc5 h1:sVx0x6IJ20fV4s6+kQK58Ur7rW8tpVNkS021qxgknBU= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3-0.20230607070149-edbaab2cecc5/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3-0.20230608151449-1fae7d0f2b31 h1:kRhW5VrM18kmdWKgbq0GGkdSqE/QxLmDYWHUW5OL7tA= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3-0.20230608151449-1fae7d0f2b31/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3 h1:UFovE1vu0cj6paebMNZCDZ4v7F654E7OmSOezO7nAog= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.3/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.4 h1:nhUgqXKnnBbl/MJNQjHSfyH+Rc4O0quI+TRDYlAnadw= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.4/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0= +github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.5 h1:LUSZRMK0Bphp9CoIqrVY9NJHgoZxyB2ZRZouqi7zQ1U= +github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.5/go.mod h1:gPk3WuH1P3kF3ROxyHERgKMMFHR+W0Fsspg5vsA0+O0= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= diff --git a/golangci-lint-config.yaml b/golangci-lint-config.yaml index c9aceb6b..eab7d0c1 100644 --- a/golangci-lint-config.yaml +++ b/golangci-lint-config.yaml @@ -1,4 +1,4 @@ -#(C) Copyright 2021 Hewlett Packard Enterprise Development LP +#(C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP run: deadline: 240s @@ -12,6 +12,8 @@ linters-settings: threshold: 110 lll: line-length: 128 + gofumpt: + module-path: "github.com/HewlettPackard/hpegl-vmaas-terraform-resources" goimports: local-prefixes: "github.com" godox: diff --git a/internal/cmp/resource_network.go b/internal/cmp/resource_network.go index c1c541d5..3447b436 100644 --- a/internal/cmp/resource_network.go +++ b/internal/cmp/resource_network.go @@ -5,6 +5,8 @@ package cmp import ( "context" "fmt" + "strings" + "time" "github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/client" "github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/models" @@ -105,6 +107,55 @@ func (r *resNetwork) Create(ctx context.Context, d *utils.Data, meta interface{} if err != nil { return err } + // Refresh NSX integration + serverRefreshResp, err := r.rClient.RefreshNetworkServices(ctx, createReq.NetworkServer.ID, nil) + if !serverRefreshResp.Success { + return fmt.Errorf("failed refresh NSX integration post NSX object creation") + } + if err != nil { + return err + } + errCount := 0 + cRetry := utils.CustomRetry{ + Timeout: time.Minute * 10, + RetryDelay: time.Second * 10, + InitialDelay: time.Second * 10, + Cond: func(response interface{}, err error) (bool, error) { + if err != nil { + errCount++ + // return false as condition if same error returns 3 times. + if errCount == 3 { + return false, err + } + + return false, nil + } + + networkResponse, ok := response.(models.GetSpecificNetworkBody) + if !ok { + errCount++ + if errCount == 3 { + return false, fmt.Errorf("%s", "error while getting Network") + } + + return false, nil + } + errCount = 0 + + if strings.Contains(networkResponse.Network.ExternalID, utils.PortGroupPrefix) { + return true, nil + } + + return false, nil + }, + } + + _, err = cRetry.Retry(ctx, meta, func(ctx context.Context) (interface{}, error) { + return r.nClient.GetSpecificNetwork(ctx, createResp.Network.ID) + }) + if err != nil { + return err + } return tftags.Set(d, createResp.Network) } @@ -140,9 +191,21 @@ func (r *resNetwork) Update(ctx context.Context, d *utils.Data, meta interface{} func (r *resNetwork) Delete(ctx context.Context, d *utils.Data, meta interface{}) error { setMeta(meta, r.rClient.Client) networkID := d.GetID() - resp, err := r.nClient.DeleteNetwork(ctx, networkID) - if !resp.Success { - return fmt.Errorf("got success as false on delete network, error: %w", err) + // wait until deleted + retry := &utils.CustomRetry{ + InitialDelay: time.Second * 10, + RetryDelay: time.Second * 10, + Timeout: time.Minute * 10, + } + resp, err := retry.Retry(ctx, meta, func(ctx context.Context) (interface{}, error) { + return r.nClient.DeleteNetwork(ctx, networkID) + }) + response := resp.(models.SuccessOrErrorMessage) + if !response.Success { + return fmt.Errorf("failed to delete the network due to following error: %s", response.Msg) + } + if err != nil { + return err } return err diff --git a/internal/utils/constants.go b/internal/utils/constants.go index 41a40fc5..b33dd2a8 100644 --- a/internal/utils/constants.go +++ b/internal/utils/constants.go @@ -27,11 +27,12 @@ const ( defaultTimeout = time.Hour * 24 noRetryCount = -1 // power constants - PowerOn = "poweron" - PowerOff = "poweroff" - Restart = "restart" - Suspend = "suspend" - Deleting = "deleting" - Deleted = "deleted" - Failed = "failed" + PowerOn = "poweron" + PowerOff = "poweroff" + Restart = "restart" + Suspend = "suspend" + Deleting = "deleting" + Deleted = "deleted" + Failed = "failed" + PortGroupPrefix = "dvportgroup-" )