-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resource/aws_cloudfront_distribution: Add wait_for_deployment argument
Reference: #8073 Since we are adding a virtual attribute with a `Default`, we must use include a schema state migration to prevent the `"" => "true"` difference on upgrade. Output from acceptance testing: ``` --- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyDomainName (1.25s) --- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyOriginID (1.30s) --- PASS: TestAccAWSCloudFrontDistribution_disappears (571.01s) --- PASS: TestAccAWSCloudFrontDistribution_noOptionalItemsConfig (1263.05s) --- PASS: TestAccAWSCloudFrontDistribution_noCustomErrorResponseConfig (1265.06s) --- PASS: TestAccAWSCloudFrontDistribution_HTTP11Config (1265.34s) --- PASS: TestAccAWSCloudFrontDistribution_customOrigin (1267.09s) --- PASS: TestAccAWSCloudFrontDistribution_OriginGroups (1267.68s) --- PASS: TestAccAWSCloudFrontDistribution_RetainOnDelete (1268.95s) --- PASS: TestAccAWSCloudFrontDistribution_orderedCacheBehavior (1271.12s) --- PASS: TestAccAWSCloudFrontDistribution_S3Origin (1271.30s) --- PASS: TestAccAWSCloudFrontDistribution_multiOrigin (1271.50s) --- PASS: TestAccAWSCloudFrontDistribution_IsIPV6EnabledConfig (1272.82s) --- PASS: TestAccAWSCloudFrontDistribution_ViewerCertificate_AcmCertificateArn (1275.16s) --- PASS: TestAccAWSCloudFrontDistribution_WaitForDeployment (1275.81s) --- PASS: TestAccAWSCloudFrontDistribution_ViewerCertificate_AcmCertificateArn_ConflictsWithCloudFrontDefaultCertificate (1372.94s) --- PASS: TestAccAWSCloudFrontDistribution_S3OriginWithTags (1782.07s) --- PASS: TestAccAWSCloudFrontDistribution_Enabled (1782.38s) ```
- Loading branch information
Showing
5 changed files
with
310 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func resourceAwsCloudFrontDistributionMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { | ||
switch v { | ||
case 0: | ||
log.Println("[INFO] Found CloudFront Distribution state v0; migrating to v1") | ||
return migrateCloudFrontDistributionStateV0toV1(is) | ||
default: | ||
return is, fmt.Errorf("Unexpected schema version: %d", v) | ||
} | ||
} | ||
|
||
func migrateCloudFrontDistributionStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) { | ||
if is.Empty() || is.Attributes == nil { | ||
log.Println("[DEBUG] Empty CloudFront Distribution state; nothing to migrate.") | ||
return is, nil | ||
} | ||
|
||
log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes) | ||
|
||
// Add wait_for_deployment virtual attribute with Default | ||
is.Attributes["wait_for_deployment"] = "true" | ||
|
||
log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes) | ||
|
||
return is, nil | ||
} |
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,52 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAwsCloudFrontDistributionMigrateState(t *testing.T) { | ||
cases := map[string]struct { | ||
StateVersion int | ||
Attributes map[string]string | ||
Expected map[string]string | ||
Meta interface{} | ||
}{ | ||
"v0_1": { | ||
StateVersion: 0, | ||
Attributes: map[string]string{ | ||
"wait_for_deployment": "", | ||
}, | ||
Expected: map[string]string{ | ||
"wait_for_deployment": "true", | ||
}, | ||
}, | ||
} | ||
|
||
for tn, tc := range cases { | ||
is := &terraform.InstanceState{ | ||
ID: "some_id", | ||
Attributes: tc.Attributes, | ||
} | ||
|
||
tfResource := resourceAwsCloudFrontDistribution() | ||
|
||
if tfResource.MigrateState == nil { | ||
t.Fatalf("bad: %s, err: missing MigrateState function in resource", tn) | ||
} | ||
|
||
is, err := tfResource.MigrateState(tc.StateVersion, is, tc.Meta) | ||
if err != nil { | ||
t.Fatalf("bad: %s, err: %#v", tn, err) | ||
} | ||
|
||
for k, v := range tc.Expected { | ||
if is.Attributes[k] != v { | ||
t.Fatalf( | ||
"bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", | ||
tn, k, v, k, is.Attributes[k], is.Attributes) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.