Skip to content

Commit

Permalink
convert terraform resources to use sdk manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kklimonda-cl committed Sep 3, 2024
1 parent 2928bad commit 16d11ac
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 965 deletions.
9 changes: 9 additions & 0 deletions assets/pango/errors/panos.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ func (e Panos) ObjectNotFound() bool {
return e.Code == 7
}

func IsObjectNotFound(e error) bool {
e2, ok := e.(Panos)
if ok && e2.ObjectNotFound() {
return true
}

return false
}

// ObjectNotFound returns an object not found error.
func ObjectNotFound() Panos {
return Panos{
Expand Down
13 changes: 0 additions & 13 deletions assets/terraform/internal/provider/errors.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
package provider

import (
"github.com/PaloAltoNetworks/pango/errors"
)

var InspectionModeError = "Resources are unavailable when the provider is in inspection mode. Resources are only available in API mode."

func IsObjectNotFound(e error) bool {
e2, ok := e.(errors.Panos)
if ok && e2.ObjectNotFound() {
return true
}

return false
}
17 changes: 13 additions & 4 deletions pkg/translate/terraform_provider/device_group_parent_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const deviceGroupParentImports = `
import (
"encoding/xml"
"github.com/PaloAltoNetworks/pango/xmlapi"
sdkerrors "github.com/PaloAltoNetworks/pango/errors"
"github.com/PaloAltoNetworks/pango/util"
"github.com/PaloAltoNetworks/pango/xmlapi"
)
`

Expand Down Expand Up @@ -106,7 +107,11 @@ if resp.Diagnostics.HasError() {
name := state.DeviceGroup.ValueString()
hierarchy, err := getParents(ctx, o.client, name)
if err != nil {
resp.Diagnostics.AddError("Failed to query for the device group parent", err.Error())
if sdkerrors.IsObjectNotFound(err) {
resp.State.RemoveResource(ctx)
} else {
resp.Diagnostics.AddError("Failed to query for the device group parent", err.Error())
}
return
}
Expand All @@ -130,13 +135,17 @@ if resp.Diagnostics.HasError() {
name := state.DeviceGroup.ValueString()
hierarchy, err := getParents(ctx, o.client, name)
if err != nil {
resp.Diagnostics.AddError("Failed to query for the device group parent", err.Error())
if sdkerrors.IsObjectNotFound(err) {
resp.State.RemoveResource(ctx)
} else {
resp.Diagnostics.AddError("Failed to query for the device group parent", err.Error())
}
return
}
parent, ok := hierarchy[name]
if !ok {
resp.Diagnostics.AddError("Failed to query for the device group parent", fmt.Sprintf("Device Group '%s' doesn't exist", name))
resp.State.RemoveResource(ctx)
return
}
state.Parent = types.StringValue(parent)
Expand Down
Loading

0 comments on commit 16d11ac

Please sign in to comment.