Skip to content

Commit

Permalink
resource/aws_cloudfront_distribution: Import into ordered_cache_behav…
Browse files Browse the repository at this point in the history
…ior instead of deprecated cache_behavior

Previously:

--- FAIL: TestAccAWSCloudFrontDistribution_orderedCacheBehavior (739.56s)
	testing.go:527: Step 1 error: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.

		(map[string]string) (len=59) {
		 (string) (len=16) "cache_behavior.#": (string) (len=1) "2",
...
		 (string) (len=48) "cache_behavior.1203603591.viewer_protocol_policy": (string) (len=9) "allow-all"
		}

		(map[string]string) (len=59) {
		 (string) (len=24) "ordered_cache_behavior.#": (string) (len=1) "2",
...
		 (string) (len=47) "ordered_cache_behavior.1.viewer_protocol_policy": (string) (len=9) "allow-all"
		}

Now:

--- PASS: TestAccAWSCloudFrontDistribution_orderedCacheBehavior (820.16s)
  • Loading branch information
bflad committed Aug 17, 2018
1 parent 5ee91f7 commit 4e56e0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aws/cloudfront_distribution_configuration_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ func flattenDistributionConfig(d *schema.ResourceData, distributionConfig *cloud
}
}
if distributionConfig.CacheBehaviors != nil {
if _, ok := d.GetOk("ordered_cache_behavior"); ok {
err = d.Set("ordered_cache_behavior", flattenCacheBehaviors(distributionConfig.CacheBehaviors))
} else {
if _, ok := d.GetOk("cache_behavior"); ok {
err = d.Set("cache_behavior", flattenCacheBehaviorsDeprecated(distributionConfig.CacheBehaviors))
} else {
err = d.Set("ordered_cache_behavior", flattenCacheBehaviors(distributionConfig.CacheBehaviors))
}

if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions aws/resource_aws_cloudfront_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ func TestAccAWSCloudFrontDistribution_orderedCacheBehavior(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "ordered_cache_behavior.1.path_pattern", "images2/*.jpg"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down

0 comments on commit 4e56e0c

Please sign in to comment.