Skip to content

Commit 5bd0dac

Browse files
authored
Merge pull request #43146 from hashicorp/td-replace-PlanOnly-test-steps
Technical debt: Replace `PlanOnly` acceptance tests (services `a` - `e`)
2 parents da19676 + 7be8867 commit 5bd0dac

File tree

61 files changed

+1417
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1417
-370
lines changed

internal/sdkv2/schema.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,33 @@ func ComputedOnlyFromResourceSchema(rs map[string]*schema.Schema) map[string]*sc
6868
return cs
6969
}
7070

71+
// IAMPolicyDocumentSchemaRequired returns the standard schema for an optional IAM policy JSON document.
72+
var IAMPolicyDocumentSchemaOptional = sync.OnceValue(jsonDocumentSchemaOptionalFunc(SuppressEquivalentIAMPolicyDocuments))
73+
7174
// IAMPolicyDocumentSchemaOptionalComputed returns the standard schema for an optional, computed IAM policy JSON document.
7275
var IAMPolicyDocumentSchemaOptionalComputed = sync.OnceValue(jsonDocumentSchemaOptionalComputedFunc(SuppressEquivalentIAMPolicyDocuments))
7376

74-
// JSONDocumentSchemaRequired returns the standard schema for an optional, force-new JSON document.
77+
// IAMPolicyDocumentSchemaRequired returns the standard schema for a required IAM policy JSON document.
78+
var IAMPolicyDocumentSchemaRequired = sync.OnceValue(jsonDocumentSchemaRequiredFunc(SuppressEquivalentIAMPolicyDocuments))
79+
80+
// JSONDocumentSchemaOptionalForceNew returns the standard schema for an optional, force-new JSON document.
7581
var JSONDocumentSchemaOptionalForceNew = sync.OnceValue(jsonDocumentSchemaOptionalForceNewFunc(SuppressEquivalentJSONDocuments))
7682

7783
// JSONDocumentSchemaRequired returns the standard schema for a required JSON document.
7884
var JSONDocumentSchemaRequired = sync.OnceValue(jsonDocumentSchemaRequiredFunc(SuppressEquivalentJSONDocuments))
7985

80-
// IAMPolicyDocumentSchemaRequired returns the standard schema for a required IAM policy JSON document.
81-
var IAMPolicyDocumentSchemaRequired = sync.OnceValue(jsonDocumentSchemaRequiredFunc(SuppressEquivalentIAMPolicyDocuments))
86+
func jsonDocumentSchemaOptionalFunc(diffSuppressFunc schema.SchemaDiffSuppressFunc) func() *schema.Schema {
87+
return func() *schema.Schema {
88+
return &schema.Schema{
89+
Type: schema.TypeString,
90+
Optional: true,
91+
ValidateFunc: validation.StringIsJSON,
92+
DiffSuppressFunc: diffSuppressFunc,
93+
DiffSuppressOnRefresh: true,
94+
StateFunc: NormalizeJsonStringSchemaStateFunc,
95+
}
96+
}
97+
}
8298

8399
func jsonDocumentSchemaOptionalComputedFunc(diffSuppressFunc schema.SchemaDiffSuppressFunc) func() *schema.Schema {
84100
return func() *schema.Schema {

internal/service/apigateway/account_test.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import (
1313
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1414
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1515
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
16+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1617
"github.com/hashicorp/terraform-plugin-testing/statecheck"
1718
"github.com/hashicorp/terraform-plugin-testing/terraform"
1819
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1920
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
21+
tfknownvalue "github.com/hashicorp/terraform-provider-aws/internal/acctest/knownvalue"
2022
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2123
tfapigateway "github.com/hashicorp/terraform-provider-aws/internal/service/apigateway"
2224
"github.com/hashicorp/terraform-provider-aws/names"
@@ -39,8 +41,8 @@ func testAccAccount_basic(t *testing.T) {
3941
ConfigStateChecks: []statecheck.StateCheck{
4042
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("api_key_version"), knownvalue.NotNull()),
4143
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("cloudwatch_role_arn"), knownvalue.StringExact("")),
42-
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("features"), knownvalue.NotNull()),
43-
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), knownvalue.StringExact("api-gateway-account")),
44+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("features"), knownvalue.Null()),
45+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrID), tfknownvalue.AccountID()),
4446
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("throttle_settings"), knownvalue.ListExact([]knownvalue.Check{
4547
knownvalue.ObjectExact(map[string]knownvalue.Check{
4648
"burst_limit": knownvalue.Int32Exact(5000),
@@ -162,14 +164,29 @@ func testAccAccount_frameworkMigration_basic(t *testing.T) {
162164
},
163165
},
164166
Config: testAccAccountConfig_basic,
167+
ConfigPlanChecks: resource.ConfigPlanChecks{
168+
PreApply: []plancheck.PlanCheck{
169+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
170+
},
171+
},
165172
ConfigStateChecks: []statecheck.StateCheck{
166173
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("cloudwatch_role_arn"), knownvalue.StringExact("")),
167174
},
168175
},
169176
{
170177
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
171178
Config: testAccAccountConfig_basic,
172-
PlanOnly: true,
179+
ConfigPlanChecks: resource.ConfigPlanChecks{
180+
PreApply: []plancheck.PlanCheck{
181+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
182+
},
183+
PostApplyPostRefresh: []plancheck.PlanCheck{
184+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
185+
},
186+
},
187+
ConfigStateChecks: []statecheck.StateCheck{
188+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("cloudwatch_role_arn"), knownvalue.StringExact("")),
189+
},
173190
},
174191
},
175192
})
@@ -195,6 +212,11 @@ func testAccAccount_frameworkMigration_cloudwatchRoleARN(t *testing.T) {
195212
},
196213
},
197214
Config: testAccAccountConfig_role0(rName),
215+
ConfigPlanChecks: resource.ConfigPlanChecks{
216+
PreApply: []plancheck.PlanCheck{
217+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
218+
},
219+
},
198220
ConfigStateChecks: []statecheck.StateCheck{
199221
statecheck.CompareValuePairs(
200222
resourceName, tfjsonpath.New("cloudwatch_role_arn"),
@@ -206,7 +228,21 @@ func testAccAccount_frameworkMigration_cloudwatchRoleARN(t *testing.T) {
206228
{
207229
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
208230
Config: testAccAccountConfig_role0(rName),
209-
PlanOnly: true,
231+
ConfigPlanChecks: resource.ConfigPlanChecks{
232+
PreApply: []plancheck.PlanCheck{
233+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
234+
},
235+
PostApplyPostRefresh: []plancheck.PlanCheck{
236+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
237+
},
238+
},
239+
ConfigStateChecks: []statecheck.StateCheck{
240+
statecheck.CompareValuePairs(
241+
resourceName, tfjsonpath.New("cloudwatch_role_arn"),
242+
"aws_iam_role.test[0]", tfjsonpath.New(names.AttrARN),
243+
compare.ValuesSame(),
244+
),
245+
},
210246
},
211247
},
212248
})

internal/service/apigateway/base_path_mapping_test.go

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/aws/aws-sdk-go-v2/aws"
1212
"github.com/aws/aws-sdk-go-v2/service/apigateway"
1313
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
14+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1415
"github.com/hashicorp/terraform-plugin-testing/terraform"
1516
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
1617
"github.com/hashicorp/terraform-provider-aws/internal/conns"
@@ -207,11 +208,23 @@ func TestAccAPIGatewayBasePathMapping_updateIDFormat(t *testing.T) {
207208
Check: resource.ComposeTestCheckFunc(
208209
testAccCheckBasePathExists(ctx, resourceName, &conf),
209210
),
211+
ConfigPlanChecks: resource.ConfigPlanChecks{
212+
PreApply: []plancheck.PlanCheck{
213+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
214+
},
215+
},
210216
},
211217
{
212218
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
213219
Config: testAccBasePathMappingConfig_basic(name, key, certificate, acctest.ResourcePrefix),
214-
PlanOnly: true,
220+
ConfigPlanChecks: resource.ConfigPlanChecks{
221+
PreApply: []plancheck.PlanCheck{
222+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
223+
},
224+
PostApplyPostRefresh: []plancheck.PlanCheck{
225+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
226+
},
227+
},
215228
},
216229
},
217230
})
@@ -359,8 +372,18 @@ resource "aws_api_gateway_integration" "test" {
359372
360373
resource "aws_api_gateway_deployment" "test" {
361374
rest_api_id = aws_api_gateway_rest_api.test.id
362-
stage_name = "test"
363-
depends_on = [aws_api_gateway_integration.test]
375+
376+
depends_on = [aws_api_gateway_integration.test]
377+
}
378+
379+
resource "aws_api_gateway_stage" "test" {
380+
rest_api_id = aws_api_gateway_rest_api.test.id
381+
stage_name = "test"
382+
deployment_id = aws_api_gateway_deployment.test.id
383+
384+
lifecycle {
385+
ignore_changes = [variables, canary_settings]
386+
}
364387
}
365388
`, domainName, acctest.TLSPEMEscapeNewlines(certificate), acctest.TLSPEMEscapeNewlines(key))
366389
}
@@ -370,7 +393,7 @@ func testAccBasePathMappingConfig_basic(domainName, key, certificate, basePath s
370393
resource "aws_api_gateway_base_path_mapping" "test" {
371394
api_id = aws_api_gateway_rest_api.test.id
372395
base_path = %[1]q
373-
stage_name = aws_api_gateway_deployment.test.stage_name
396+
stage_name = aws_api_gateway_stage.test.stage_name
374397
domain_name = aws_api_gateway_domain_name.test.domain_name
375398
}
376399
`, basePath))
@@ -440,14 +463,24 @@ resource "aws_api_gateway_integration" "test" {
440463
441464
resource "aws_api_gateway_deployment" "test" {
442465
rest_api_id = aws_api_gateway_rest_api.test.id
443-
stage_name = "test"
444-
depends_on = [aws_api_gateway_integration.test]
466+
467+
depends_on = [aws_api_gateway_integration.test]
468+
}
469+
470+
resource "aws_api_gateway_stage" "test" {
471+
rest_api_id = aws_api_gateway_rest_api.test.id
472+
stage_name = "test"
473+
deployment_id = aws_api_gateway_deployment.test.id
474+
475+
lifecycle {
476+
ignore_changes = [variables, canary_settings]
477+
}
445478
}
446479
447480
resource "aws_api_gateway_base_path_mapping" "test" {
448481
api_id = aws_api_gateway_rest_api.test.id
449482
base_path = %[4]q
450-
stage_name = aws_api_gateway_deployment.test.stage_name
483+
stage_name = aws_api_gateway_stage.test.stage_name
451484
domain_name = aws_api_gateway_domain_name.test.domain_name
452485
domain_name_id = aws_api_gateway_domain_name.test.domain_name_id
453486
}
@@ -465,9 +498,7 @@ resource "aws_api_gateway_rest_api" "test2" {
465498
}
466499
}
467500
468-
469501
resource "aws_api_gateway_stage" "test2" {
470-
471502
depends_on = [
472503
aws_api_gateway_deployment.test
473504
]
@@ -497,11 +528,10 @@ resource "aws_api_gateway_integration" "test2" {
497528
type = "MOCK"
498529
}
499530
500-
501531
resource "aws_api_gateway_deployment" "test2" {
502532
rest_api_id = aws_api_gateway_rest_api.test2.id
503-
stage_name = "test"
504-
depends_on = [aws_api_gateway_integration.test2]
533+
534+
depends_on = [aws_api_gateway_integration.test2]
505535
}
506536
507537
resource "aws_api_gateway_base_path_mapping" "test" {

internal/service/apigateway/domain_name_test.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ import (
1616
"github.com/hashicorp/aws-sdk-go-base/v2/endpoints"
1717
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1818
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
20+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
21+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
1922
"github.com/hashicorp/terraform-plugin-testing/terraform"
23+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
2024
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
25+
tfstatecheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/statecheck"
2126
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2227
tfapigateway "github.com/hashicorp/terraform-provider-aws/internal/service/apigateway"
2328
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
@@ -473,13 +478,33 @@ func TestAccAPIGatewayDomainName_updateIDFormat(t *testing.T) {
473478
Config: testAccDomainNameConfig_regionalCertificateARN(rName, key, certificate),
474479
Check: resource.ComposeTestCheckFunc(
475480
testAccCheckDomainNameExists(ctx, resourceName, &domainName),
476-
resource.TestCheckNoResourceAttr(resourceName, "domain_name_id"),
477481
),
482+
ConfigPlanChecks: resource.ConfigPlanChecks{
483+
PreApply: []plancheck.PlanCheck{
484+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
485+
},
486+
},
487+
ConfigStateChecks: []statecheck.StateCheck{
488+
tfstatecheck.ExpectNoValue(resourceName, tfjsonpath.New("domain_name_id")),
489+
},
478490
},
479491
{
480492
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
481493
Config: testAccDomainNameConfig_regionalCertificateARN(rName, key, certificate),
482-
PlanOnly: true,
494+
Check: resource.ComposeTestCheckFunc(
495+
testAccCheckDomainNameExists(ctx, resourceName, &domainName),
496+
),
497+
ConfigPlanChecks: resource.ConfigPlanChecks{
498+
PreApply: []plancheck.PlanCheck{
499+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
500+
},
501+
PostApplyPostRefresh: []plancheck.PlanCheck{
502+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
503+
},
504+
},
505+
ConfigStateChecks: []statecheck.StateCheck{
506+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("domain_name_id"), knownvalue.NotNull()),
507+
},
483508
},
484509
},
485510
})

internal/service/apigateway/rest_api_test.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import (
1414
"github.com/aws/aws-sdk-go-v2/service/apigateway/types"
1515
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1616
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
17+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
18+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
19+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
1720
"github.com/hashicorp/terraform-plugin-testing/terraform"
21+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1822
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
1923
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2024
"github.com/hashicorp/terraform-provider-aws/internal/errs"
@@ -1362,6 +1366,7 @@ func TestAccAPIGatewayRestAPI_Policy_basic(t *testing.T) {
13621366

13631367
func TestAccAPIGatewayRestAPI_Policy_order(t *testing.T) {
13641368
ctx := acctest.Context(t)
1369+
var conf apigateway.GetRestApiOutput
13651370
resourceName := "aws_api_gateway_rest_api.test"
13661371
expectedPolicyText := `{"Statement":[{"Action":"execute-api:Invoke","Condition":{"IpAddress":{"aws:SourceIp":["123.123.123.123/32","122.122.122.122/32","169.254.169.253/32"]}},"Effect":"Allow","Principal":{"AWS":"*"},"Resource":"*"}],"Version":"2012-10-17"}`
13671372
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
@@ -1375,12 +1380,30 @@ func TestAccAPIGatewayRestAPI_Policy_order(t *testing.T) {
13751380
{
13761381
Config: testAccRestAPIConfig_policyOrder(rName),
13771382
Check: resource.ComposeAggregateTestCheckFunc(
1378-
resource.TestCheckResourceAttr(resourceName, names.AttrPolicy, expectedPolicyText),
1383+
testAccCheckRESTAPIExists(ctx, resourceName, &conf),
13791384
),
1385+
ConfigPlanChecks: resource.ConfigPlanChecks{
1386+
PreApply: []plancheck.PlanCheck{
1387+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
1388+
},
1389+
},
1390+
ConfigStateChecks: []statecheck.StateCheck{
1391+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrPolicy), knownvalue.StringExact(expectedPolicyText)),
1392+
},
13801393
},
13811394
{
1382-
Config: testAccRestAPIConfig_policyNewOrder(rName),
1383-
PlanOnly: true,
1395+
Config: testAccRestAPIConfig_policyNewOrder(rName),
1396+
Check: resource.ComposeAggregateTestCheckFunc(
1397+
testAccCheckRESTAPIExists(ctx, resourceName, &conf),
1398+
),
1399+
ConfigPlanChecks: resource.ConfigPlanChecks{
1400+
PreApply: []plancheck.PlanCheck{
1401+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
1402+
},
1403+
PostApplyPostRefresh: []plancheck.PlanCheck{
1404+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop),
1405+
},
1406+
},
13841407
},
13851408
},
13861409
})

0 commit comments

Comments
 (0)