Skip to content

Commit

Permalink
r/aws_instance: Verify that 'public_dns' and 'public_ip' are only new…
Browse files Browse the repository at this point in the history
…ly Computed if there was a value.
  • Loading branch information
ewbankkit committed Dec 27, 2024
1 parent 8a35381 commit b888a5c
Showing 1 changed file with 68 additions and 6 deletions.
74 changes: 68 additions & 6 deletions internal/service/ec2/ec2_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2446,16 +2446,46 @@ func TestAccEC2Instance_changeInstanceTypeReplace(t *testing.T) {
Config: testAccInstanceConfig_typeReplace(rName, "m5.2xlarge"),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &before),
resource.TestCheckResourceAttr(resourceName, names.AttrInstanceType, "m5.2xlarge"),
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
},
PostApplyPreRefresh: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
PostApplyPostRefresh: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrInstanceType), knownvalue.StringExact("m5.2xlarge")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_dns"), knownvalue.StringExact("")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_ip"), knownvalue.StringExact("")),
},
},
{
Config: testAccInstanceConfig_typeReplace(rName, "m6g.2xlarge"),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &after),
testAccCheckInstanceRecreated(&before, &after),
resource.TestCheckResourceAttr(resourceName, names.AttrInstanceType, "m6g.2xlarge"),
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionDestroyBeforeCreate),
},
PostApplyPreRefresh: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
PostApplyPostRefresh: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrInstanceType), knownvalue.StringExact("m6g.2xlarge")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_dns"), knownvalue.StringExact("")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_ip"), knownvalue.StringExact("")),
},
},
},
})
Expand All @@ -2482,17 +2512,49 @@ func TestAccEC2Instance_changeInstanceTypeAndUserData(t *testing.T) {
Config: testAccInstanceConfig_typeAndUserData(rName, "t2.medium", "hello world"),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, names.AttrInstanceType, "t2.medium"),
resource.TestCheckResourceAttr(resourceName, "user_data", expectedUserData),
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
},
PostApplyPreRefresh: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
PostApplyPostRefresh: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrInstanceType), knownvalue.StringExact("t2.medium")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_dns"), knownvalue.StringExact("")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_ip"), knownvalue.StringExact("")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("user_data"), knownvalue.StringExact(expectedUserData)),
},
},
{
Config: testAccInstanceConfig_typeAndUserData(rName, "t2.large", "new world"),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, names.AttrInstanceType, "t2.large"),
resource.TestCheckResourceAttr(resourceName, "user_data", expectedUserDataUpdated),
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_dns"), knownvalue.StringExact("")),
plancheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_ip"), knownvalue.StringExact("")),
},
PostApplyPreRefresh: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
PostApplyPostRefresh: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
},
},
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrInstanceType), knownvalue.StringExact("t2.large")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_dns"), knownvalue.StringExact("")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("public_ip"), knownvalue.StringExact("")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("user_data"), knownvalue.StringExact(expectedUserDataUpdated)),
},
},
{
ResourceName: resourceName,
Expand Down

0 comments on commit b888a5c

Please sign in to comment.