Skip to content

Commit 4aec595

Browse files
authored
Merge pull request #44463 from tabito-hara/f-aws_cloudfront_distribution-add_custom_origin_config_ip_address_type
[Enhancement] aws_cloudfront_distribution: Add `ip_address_type` argument to `origin.custom_origin_config` block
2 parents 3a0ea61 + 44a3f72 commit 4aec595

File tree

4 files changed

+139
-1
lines changed

4 files changed

+139
-1
lines changed

.changelog/44463.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_cloudfront_distribution: Add `ip_address_type` argument to `origin.custom_origin_config` block
3+
```

internal/service/cloudfront/distribution.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,11 @@ func resourceDistribution() *schema.Resource {
628628
Type: schema.TypeInt,
629629
Required: true,
630630
},
631+
names.AttrIPAddressType: {
632+
Type: schema.TypeString,
633+
Optional: true,
634+
ValidateDiagFunc: enum.Validate[awstypes.IpAddressType](),
635+
},
631636
"origin_keepalive_timeout": {
632637
Type: schema.TypeInt,
633638
Optional: true,
@@ -2446,6 +2451,10 @@ func expandCustomOriginConfig(tfMap map[string]any) *awstypes.CustomOriginConfig
24462451
OriginSslProtocols: expandCustomOriginConfigSSL(tfMap["origin_ssl_protocols"].(*schema.Set).List()),
24472452
}
24482453

2454+
if v, ok := tfMap[names.AttrIPAddressType]; ok && v.(string) != "" {
2455+
apiObject.IpAddressType = awstypes.IpAddressType(v.(string))
2456+
}
2457+
24492458
return apiObject
24502459
}
24512460

@@ -2463,6 +2472,10 @@ func flattenCustomOriginConfig(apiObject *awstypes.CustomOriginConfig) map[strin
24632472
"origin_ssl_protocols": flattenCustomOriginConfigSSL(apiObject.OriginSslProtocols),
24642473
}
24652474

2475+
if apiObject.IpAddressType != "" {
2476+
tfMap[names.AttrIPAddressType] = apiObject.IpAddressType
2477+
}
2478+
24662479
return tfMap
24672480
}
24682481

internal/service/cloudfront/distribution_test.go

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func TestAccCloudFrontDistribution_customOrigin(t *testing.T) {
180180

181181
var distribution awstypes.Distribution
182182
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
183+
resourceName := "aws_cloudfront_distribution.custom_distribution"
183184

184185
resource.ParallelTest(t, resource.TestCase{
185186
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.CloudFrontEndpointID) },
@@ -190,7 +191,48 @@ func TestAccCloudFrontDistribution_customOrigin(t *testing.T) {
190191
{
191192
Config: testAccDistributionConfig_custom(rName),
192193
Check: resource.ComposeTestCheckFunc(
193-
testAccCheckDistributionExists(ctx, "aws_cloudfront_distribution.custom_distribution", &distribution),
194+
testAccCheckDistributionExists(ctx, resourceName, &distribution),
195+
resource.TestCheckResourceAttr(resourceName, "origin.#", "1"),
196+
resource.TestCheckResourceAttr(resourceName, "origin.0.custom_origin_config.#", "1"),
197+
resource.TestCheckResourceAttr(resourceName, "origin.0.custom_origin_config.0.ip_address_type", ""),
198+
),
199+
},
200+
{
201+
ResourceName: "aws_cloudfront_distribution.custom_distribution",
202+
ImportState: true,
203+
ImportStateVerify: true,
204+
ImportStateVerifyIgnore: []string{
205+
"retain_on_delete",
206+
"wait_for_deployment",
207+
},
208+
},
209+
},
210+
})
211+
}
212+
213+
func TestAccCloudFrontDistribution_customOriginIPAddressType(t *testing.T) {
214+
ctx := acctest.Context(t)
215+
if testing.Short() {
216+
t.Skip("skipping long-running test in short mode")
217+
}
218+
219+
var distribution awstypes.Distribution
220+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
221+
resourceName := "aws_cloudfront_distribution.custom_distribution"
222+
223+
resource.ParallelTest(t, resource.TestCase{
224+
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.CloudFrontEndpointID) },
225+
ErrorCheck: acctest.ErrorCheck(t, names.CloudFrontServiceID),
226+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
227+
CheckDestroy: testAccCheckDistributionDestroy(ctx),
228+
Steps: []resource.TestStep{
229+
{
230+
Config: testAccDistributionConfig_customIPAddressType(rName, string(awstypes.IpAddressTypeIpv6)),
231+
Check: resource.ComposeTestCheckFunc(
232+
testAccCheckDistributionExists(ctx, resourceName, &distribution),
233+
resource.TestCheckResourceAttr(resourceName, "origin.#", "1"),
234+
resource.TestCheckResourceAttr(resourceName, "origin.0.custom_origin_config.#", "1"),
235+
resource.TestCheckResourceAttr(resourceName, "origin.0.custom_origin_config.0.ip_address_type", string(awstypes.IpAddressTypeIpv6)),
194236
),
195237
},
196238
{
@@ -202,6 +244,15 @@ func TestAccCloudFrontDistribution_customOrigin(t *testing.T) {
202244
"wait_for_deployment",
203245
},
204246
},
247+
{
248+
Config: testAccDistributionConfig_customIPAddressType(rName, string(awstypes.IpAddressTypeDualStack)),
249+
Check: resource.ComposeTestCheckFunc(
250+
testAccCheckDistributionExists(ctx, resourceName, &distribution),
251+
resource.TestCheckResourceAttr(resourceName, "origin.#", "1"),
252+
resource.TestCheckResourceAttr(resourceName, "origin.0.custom_origin_config.#", "1"),
253+
resource.TestCheckResourceAttr(resourceName, "origin.0.custom_origin_config.0.ip_address_type", string(awstypes.IpAddressTypeDualStack)),
254+
),
255+
},
205256
},
206257
})
207258
}
@@ -2050,6 +2101,76 @@ resource "aws_cloudfront_distribution" "custom_distribution" {
20502101
`, testAccDistributionRetainConfig()))
20512102
}
20522103

2104+
func testAccDistributionConfig_customIPAddressType(rName, ipAddressType string) string {
2105+
return acctest.ConfigCompose(
2106+
logBucket(rName),
2107+
fmt.Sprintf(`
2108+
resource "aws_cloudfront_distribution" "custom_distribution" {
2109+
depends_on = [aws_s3_bucket_acl.s3_bucket_logs_acl]
2110+
2111+
origin {
2112+
domain_name = "www.example.com"
2113+
origin_id = "myCustomOrigin"
2114+
2115+
custom_origin_config {
2116+
http_port = 80
2117+
https_port = 443
2118+
origin_protocol_policy = "http-only"
2119+
origin_ssl_protocols = ["SSLv3", "TLSv1"]
2120+
origin_read_timeout = 30
2121+
origin_keepalive_timeout = 5
2122+
ip_address_type = %[2]q
2123+
}
2124+
}
2125+
2126+
enabled = true
2127+
comment = "Some comment"
2128+
default_root_object = "index.html"
2129+
2130+
logging_config {
2131+
include_cookies = false
2132+
bucket = aws_s3_bucket.s3_bucket_logs.bucket_regional_domain_name
2133+
prefix = "myprefix"
2134+
}
2135+
2136+
default_cache_behavior {
2137+
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
2138+
cached_methods = ["GET", "HEAD"]
2139+
target_origin_id = "myCustomOrigin"
2140+
smooth_streaming = false
2141+
2142+
forwarded_values {
2143+
query_string = false
2144+
2145+
cookies {
2146+
forward = "all"
2147+
}
2148+
}
2149+
2150+
viewer_protocol_policy = "allow-all"
2151+
min_ttl = 0
2152+
default_ttl = 3600
2153+
max_ttl = 86400
2154+
}
2155+
2156+
price_class = "PriceClass_200"
2157+
2158+
restrictions {
2159+
geo_restriction {
2160+
restriction_type = "whitelist"
2161+
locations = ["US", "CA", "GB", "DE"]
2162+
}
2163+
}
2164+
2165+
viewer_certificate {
2166+
cloudfront_default_certificate = true
2167+
}
2168+
2169+
%[1]s
2170+
}
2171+
`, testAccDistributionRetainConfig(), ipAddressType))
2172+
}
2173+
20532174
func testAccDistributionConfig_originRequestPolicyDefault(rName string) string {
20542175
return acctest.ConfigCompose(
20552176
logBucket(rName),

website/docs/r/cloudfront_distribution.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ argument should not be specified.
549549

550550
* `http_port` (Required) - HTTP port the custom origin listens on.
551551
* `https_port` (Required) - HTTPS port the custom origin listens on.
552+
* `ip_address_type` (Optional) - IP protocol CloudFront uses when connecting to your origin. Valid values: `ipv4`, `ipv6`, `dualstack`.
552553
* `origin_protocol_policy` (Required) - Origin protocol policy to apply to your origin. One of `http-only`, `https-only`, or `match-viewer`.
553554
* `origin_ssl_protocols` (Required) - List of SSL/TLS protocols that CloudFront can use when connecting to your origin over HTTPS. Valid values: `SSLv3`, `TLSv1`, `TLSv1.1`, `TLSv1.2`. For more information, see [Minimum Origin SSL Protocol](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesOriginSSLProtocols) in the Amazon CloudFront Developer Guide.
554555
* `origin_keepalive_timeout` - (Optional) The Custom KeepAlive timeout, in seconds. By default, AWS enforces an upper limit of `60`. But you can request an [increase](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#request-custom-request-timeout). Defaults to `5`.

0 commit comments

Comments
 (0)