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

Fix nat READ for non-existant rule #166

Merged
merged 1 commit into from
May 15, 2019
Merged
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: 6 additions & 4 deletions nsxt/resource_nsxt_nat_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ func resourceNsxtNatRuleRead(d *schema.ResourceData, m interface{}) error {
}

natRule, resp, err := nsxClient.LogicalRoutingAndServicesApi.GetNatRule(nsxClient.Context, logicalRouterID, id)
if err != nil {
return fmt.Errorf("Error during NatRule read: %v", err)
}
if resp.StatusCode == http.StatusNotFound {
if resp != nil && (resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusNotFound) {
// Due to platform bug, 400 response is returned when NAT rule is not found
// In this case terraform should not error out
log.Printf("[DEBUG] NatRule %s not found", id)
d.SetId("")
return nil
}
if err != nil {
return fmt.Errorf("Error during NatRule read: %v", err)
}

d.Set("revision", natRule.Revision)
d.Set("description", natRule.Description)
Expand Down