Skip to content

Commit a2a53ee

Browse files
committed
Adds TestAccS3Object_Identity_ExistingResource_NoRefresh_WithChange and TestAccS3Object_Identity_ExistingResource_NoRefresh_NoChange
1 parent 302f4d8 commit a2a53ee

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

internal/service/s3/object_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"github.com/hashicorp/terraform-plugin-testing/terraform"
3131
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
3232
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
33+
tfknownvalue "github.com/hashicorp/terraform-provider-aws/internal/acctest/knownvalue"
34+
tfstatecheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/statecheck"
3335
"github.com/hashicorp/terraform-provider-aws/internal/conns"
3436
tfs3 "github.com/hashicorp/terraform-provider-aws/internal/service/s3"
3537
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
@@ -2119,6 +2121,119 @@ func TestAccS3Object_basicUpgrade(t *testing.T) {
21192121
})
21202122
}
21212123

2124+
func TestAccS3Object_Identity_ExistingResource_NoRefresh_WithChange(t *testing.T) {
2125+
ctx := acctest.Context(t)
2126+
var conf s3.GetObjectOutput
2127+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
2128+
resourceName := "aws_s3_object.object"
2129+
2130+
resource.ParallelTest(t, resource.TestCase{
2131+
PreCheck: func() { acctest.PreCheck(ctx, t) },
2132+
ErrorCheck: acctest.ErrorCheck(t, names.IAMServiceID),
2133+
CheckDestroy: testAccCheckObjectDestroy(ctx),
2134+
AdditionalCLIOptions: &resource.AdditionalCLIOptions{
2135+
Plan: resource.PlanOptions{
2136+
NoRefresh: true,
2137+
},
2138+
},
2139+
Steps: []resource.TestStep{
2140+
{
2141+
ExternalProviders: map[string]resource.ExternalProvider{
2142+
"aws": {
2143+
Source: "hashicorp/aws",
2144+
VersionConstraint: "6.0.0",
2145+
},
2146+
},
2147+
Config: testAccObjectConfig_content(rName, "initial"),
2148+
Check: resource.ComposeAggregateTestCheckFunc(
2149+
testAccCheckObjectExists(ctx, resourceName, &conf),
2150+
),
2151+
ConfigStateChecks: []statecheck.StateCheck{
2152+
tfstatecheck.ExpectNoIdentity(resourceName),
2153+
},
2154+
},
2155+
{
2156+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
2157+
Config: testAccObjectConfig_content(rName, "updated"),
2158+
Check: resource.ComposeAggregateTestCheckFunc(
2159+
testAccCheckObjectExists(ctx, resourceName, &conf),
2160+
),
2161+
ConfigPlanChecks: resource.ConfigPlanChecks{
2162+
PreApply: []plancheck.PlanCheck{
2163+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
2164+
},
2165+
PostApplyPostRefresh: []plancheck.PlanCheck{
2166+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
2167+
},
2168+
},
2169+
ConfigStateChecks: []statecheck.StateCheck{
2170+
statecheck.ExpectIdentity(resourceName, map[string]knownvalue.Check{
2171+
names.AttrAccountID: tfknownvalue.AccountID(),
2172+
names.AttrRegion: knownvalue.StringExact(acctest.Region()),
2173+
names.AttrBucket: knownvalue.NotNull(),
2174+
names.AttrKey: knownvalue.NotNull(),
2175+
}),
2176+
statecheck.ExpectIdentityValueMatchesState(resourceName, tfjsonpath.New(names.AttrBucket)),
2177+
statecheck.ExpectIdentityValueMatchesState(resourceName, tfjsonpath.New(names.AttrKey)),
2178+
},
2179+
},
2180+
},
2181+
})
2182+
}
2183+
2184+
func TestAccS3Object_Identity_ExistingResource_NoRefresh_NoChange(t *testing.T) {
2185+
ctx := acctest.Context(t)
2186+
var conf s3.GetObjectOutput
2187+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
2188+
resourceName := "aws_s3_object.object"
2189+
2190+
resource.ParallelTest(t, resource.TestCase{
2191+
PreCheck: func() { acctest.PreCheck(ctx, t) },
2192+
ErrorCheck: acctest.ErrorCheck(t, names.IAMServiceID),
2193+
CheckDestroy: testAccCheckObjectDestroy(ctx),
2194+
AdditionalCLIOptions: &resource.AdditionalCLIOptions{
2195+
Plan: resource.PlanOptions{
2196+
NoRefresh: true,
2197+
},
2198+
},
2199+
Steps: []resource.TestStep{
2200+
{
2201+
ExternalProviders: map[string]resource.ExternalProvider{
2202+
"aws": {
2203+
Source: "hashicorp/aws",
2204+
VersionConstraint: "6.0.0",
2205+
},
2206+
},
2207+
Config: testAccObjectConfig_basic(rName),
2208+
Check: resource.ComposeAggregateTestCheckFunc(
2209+
testAccCheckObjectExists(ctx, resourceName, &conf),
2210+
),
2211+
ConfigStateChecks: []statecheck.StateCheck{
2212+
tfstatecheck.ExpectNoIdentity(resourceName),
2213+
},
2214+
},
2215+
{
2216+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
2217+
Config: testAccObjectConfig_basic(rName),
2218+
Check: resource.ComposeAggregateTestCheckFunc(
2219+
testAccCheckObjectExists(ctx, resourceName, &conf),
2220+
),
2221+
ConfigPlanChecks: resource.ConfigPlanChecks{
2222+
PreApply: []plancheck.PlanCheck{
2223+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
2224+
},
2225+
PostApplyPostRefresh: []plancheck.PlanCheck{
2226+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
2227+
},
2228+
},
2229+
ConfigStateChecks: []statecheck.StateCheck{
2230+
tfstatecheck.ExpectNoIdentity(resourceName),
2231+
},
2232+
},
2233+
},
2234+
})
2235+
}
2236+
21222237
func testAccCheckObjectVersionIDDiffers(first, second *s3.GetObjectOutput) resource.TestCheckFunc {
21232238
return func(s *terraform.State) error {
21242239
if aws.ToString(first.VersionId) == aws.ToString(second.VersionId) {

0 commit comments

Comments
 (0)