-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement crud for the generic access resource
- Loading branch information
Showing
10 changed files
with
765 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package provider | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
tfjson "github.com/hashicorp/terraform-json" | ||
"github.com/hashicorp/terraform-plugin-testing/plancheck" | ||
) | ||
|
||
var _ plancheck.PlanCheck = expectRecreatedResource{} | ||
|
||
type expectRecreatedResource struct { | ||
resourceName string | ||
} | ||
|
||
// CheckPlan implements the plan check logic. | ||
func (e expectRecreatedResource) CheckPlan(ctx context.Context, req plancheck.CheckPlanRequest, resp *plancheck.CheckPlanResponse) { | ||
var result []error | ||
|
||
for _, rc := range req.Plan.ResourceChanges { | ||
if rc.Address == e.resourceName { | ||
changes := rc.Change.Actions | ||
if len(changes) != 2 { | ||
result = append(result, fmt.Errorf("2 changes for resource %s (delete and create): %d found", rc.Address, len(changes))) | ||
continue | ||
} | ||
if changes[0] != tfjson.ActionDelete && changes[1] != tfjson.ActionCreate { | ||
result = append(result, fmt.Errorf("expected delete then create for resource %s, but found planned action(s): %v", rc.Address, rc.Change.Actions)) | ||
} | ||
} | ||
} | ||
|
||
resp.Error = errors.Join(result...) | ||
} | ||
|
||
// expectRecreatedResource returns a plan check that asserts is a delete and create change present. | ||
// All output and resource changes found will be aggregated and returned in a plan check error. | ||
func ExpectRecreatedResource(resourceName string) plancheck.PlanCheck { | ||
return expectRecreatedResource{ | ||
resourceName: resourceName, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.