forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10,274 changed files
with
946,952 additions
and
946,952 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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,115 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package acctest | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
fwresource "github.com/hashicorp/terraform-plugin-framework/resource" | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
"github.com/hashicorp/terraform-provider-aws/errs/fwdiag" | ||
) | ||
|
||
// Terraform Plugin Framework variants of standard acceptance test helpers. | ||
|
||
// CheckFrameworkResourceDisappears destroys an existing resource out of band | ||
// | ||
// By default, this check will only copy root-level string arguments into the state | ||
// used to delete the remote resource. For resources requiring nested or non-string | ||
// arguments to be available for the delete operation, consider using | ||
// CheckFrameworkResourceDisappearsWithStateFunc with a custom state function | ||
// instead. | ||
func CheckFrameworkResourceDisappears( | ||
ctx context.Context, | ||
provo *schema.Provider, | ||
factory func(context.Context) (fwresource.ResourceWithConfigure, error), | ||
n string, | ||
) resource.TestCheckFunc { | ||
return deleteFrameworkResource(ctx, provo, factory, n, rootStringStateFunc()) | ||
} | ||
|
||
// CheckFrameworkResourceDisappearsWithStateFunc destroys an existing resource | ||
// out of band, constructing state from the provided state function | ||
func CheckFrameworkResourceDisappearsWithStateFunc( | ||
ctx context.Context, | ||
provo *schema.Provider, | ||
factory func(context.Context) (fwresource.ResourceWithConfigure, error), | ||
n string, | ||
stateFunc func(ctx context.Context, state *tfsdk.State, is *terraform.InstanceState) error, | ||
) resource.TestCheckFunc { | ||
return deleteFrameworkResource(ctx, provo, factory, n, stateFunc) | ||
} | ||
|
||
func deleteFrameworkResource( | ||
ctx context.Context, | ||
provo *schema.Provider, | ||
factory func(context.Context) (fwresource.ResourceWithConfigure, error), | ||
n string, | ||
stateFunc func(ctx context.Context, state *tfsdk.State, is *terraform.InstanceState) error, | ||
) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("resource not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("resource ID missing: %s", n) | ||
} | ||
|
||
resource, err := factory(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resource.Configure(ctx, fwresource.ConfigureRequest{ProviderData: provo.Meta()}, &fwresource.ConfigureResponse{}) | ||
|
||
schemaResp := fwresource.SchemaResponse{} | ||
resource.Schema(ctx, fwresource.SchemaRequest{}, &schemaResp) | ||
|
||
// Construct a simple Framework State that contains just top-level attributes. | ||
state := tfsdk.State{ | ||
Raw: tftypes.NewValue(schemaResp.Schema.Type().TerraformType(ctx), nil), | ||
Schema: schemaResp.Schema, | ||
} | ||
|
||
err = stateFunc(ctx, &state, rs.Primary) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
response := fwresource.DeleteResponse{} | ||
resource.Delete(ctx, fwresource.DeleteRequest{State: state}, &response) | ||
|
||
if response.Diagnostics.HasError() { | ||
return fwdiag.DiagnosticsError(response.Diagnostics) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// rootStringStateFunc copies root-level string arguments into `state` | ||
func rootStringStateFunc() func(ctx context.Context, state *tfsdk.State, is *terraform.InstanceState) error { | ||
return func(ctx context.Context, state *tfsdk.State, is *terraform.InstanceState) error { | ||
for name, v := range is.Attributes { | ||
if name == "%" || strings.Contains(name, ".") { | ||
continue | ||
} | ||
|
||
if err := fwdiag.DiagnosticsError(state.SetAttribute(ctx, path.Root(name), v)); err != nil { | ||
log.Printf("[WARN] %s(%s): %s", name, v, err) | ||
} | ||
} | ||
return nil | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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,195 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package acctest_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-aws/acctest" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
func TestIsIsolatedPartition(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
input string | ||
expected bool | ||
}{ | ||
{ | ||
input: names.StandardPartitionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.ChinaPartitionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.USGovCloudPartitionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.ISOPartitionID, | ||
expected: true, | ||
}, | ||
{ | ||
input: names.ISOBPartitionID, | ||
expected: true, | ||
}, | ||
{ | ||
input: names.ISOEPartitionID, | ||
expected: true, | ||
}, | ||
{ | ||
input: names.ISOFPartitionID, | ||
expected: true, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.input, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
if got, want := acctest.IsIsolatedPartition(testCase.input), testCase.expected; got != want { | ||
t.Errorf("got: %#v, expected: %#v", got, want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsIsolatedRegion(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
input string | ||
expected bool | ||
}{ | ||
{ | ||
input: names.USEast1RegionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.CNNorth1RegionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.USGovEast1RegionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.USISOEast1RegionID, | ||
expected: true, | ||
}, | ||
{ | ||
input: names.USISOBEast1RegionID, | ||
expected: true, | ||
}, | ||
{ | ||
input: names.EUISOEWest1RegionID, | ||
expected: true, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.input, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
if got, want := acctest.IsIsolatedRegion(testCase.input), testCase.expected; got != want { | ||
t.Errorf("got: %#v, expected: %#v", got, want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsStandardPartition(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
input string | ||
expected bool | ||
}{ | ||
{ | ||
input: names.StandardPartitionID, | ||
expected: true, | ||
}, | ||
{ | ||
input: names.ChinaPartitionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.USGovCloudPartitionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.ISOPartitionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.ISOBPartitionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.ISOEPartitionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.ISOFPartitionID, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.input, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
if got, want := acctest.IsStandardPartition(testCase.input), testCase.expected; got != want { | ||
t.Errorf("got: %#v, expected: %#v", got, want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsStandardRegion(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
input string | ||
expected bool | ||
}{ | ||
{ | ||
input: names.USEast1RegionID, | ||
expected: true, | ||
}, | ||
{ | ||
input: names.CNNorth1RegionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.USGovEast1RegionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.USISOEast1RegionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.USISOBEast1RegionID, | ||
expected: false, | ||
}, | ||
{ | ||
input: names.EUISOEWest1RegionID, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.input, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
if got, want := acctest.IsStandardRegion(testCase.input), testCase.expected; got != want { | ||
t.Errorf("got: %#v, expected: %#v", got, want) | ||
} | ||
}) | ||
} | ||
} |
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
File renamed without changes.
Oops, something went wrong.