Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add provider flag to tolerate partial success #181

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

var defaultRetryOnStatusCodes = []int{429, 503}
var toleratePartialSuccess = false

// Provider for VMWare NSX-T. Returns terraform.ResourceProvider
func Provider() terraform.ResourceProvider {
Expand Down Expand Up @@ -85,6 +86,12 @@ func Provider() terraform.ResourceProvider {
},
// There is no support for default values/func for list, so it will be handled later
},
"tolerate_partial_success": {
Type: schema.TypeBool,
Optional: true,
Description: "Treat partial success status as success",
DefaultFunc: schema.EnvDefaultFunc("NSXT_TOLERATE_PARTIAL_SUCCESS", false),
},
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -189,6 +196,9 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
password := d.Get("password").(string)
remoteAuth := d.Get("remote_auth").(bool)

// Global variable used in resources with realization checks
toleratePartialSuccess = d.Get("tolerate_partial_success").(bool)

if needCreds {
if username == "" {
return nil, fmt.Errorf("username must be provided")
Expand Down
11 changes: 9 additions & 2 deletions nsxt/resource_nsxt_logical_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,16 @@ func resourceNsxtLogicalSwitchCreate(d *schema.ResourceData, m interface{}) erro

func resourceNsxtLogicalSwitchVerifyRealization(d *schema.ResourceData, nsxClient *api.APIClient, logicalSwitch *manager.LogicalSwitch) error {
// verifying switch realization on hypervisor
pendingStates := []string{"in_progress", "pending"}
targetStates := []string{"success"}
if toleratePartialSuccess {
targetStates = append(targetStates, "partial_success")
} else {
pendingStates = append(pendingStates, "partial_success")
}
stateConf := &resource.StateChangeConf{
Pending: []string{"in_progress", "pending", "partial_success"},
Target: []string{"success"},
Pending: pendingStates,
Target: targetStates,
Refresh: func() (interface{}, string, error) {
state, resp, err := nsxClient.LogicalSwitchingApi.GetLogicalSwitchState(nsxClient.Context, logicalSwitch.Id)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ The following arguments are used to configure the VMware NSX-T Provider:
authorization. This is required for users based on vIDM authentication.
The default for this flag is false. Can also be specified with the
`NSXT_REMOTE_AUTH` environment variable.
* `tolerate_partial_success` - (Optional) Setting this flag to true would treat
partially succesful realization as valid state and not fail apply.

## NSX Logical Networking

Expand Down