Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudfront_distribution: Add support for cache_policy_id and origin_request_policy_id for behaviors #1589

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ac757ec
cloudfront_distribution: Added ability to use cache_policy_id and ori…
Zozman Nov 7, 2022
58c3628
cloudfront_distribution: Added ability to use cache_policy_id and ori…
Zozman Nov 7, 2022
d5101ee
cloudfront_distribution: Added ability to use cache_policy_id and ori…
Zozman Nov 7, 2022
700beb0
Improved formattiung for changelog fragment 1589
Zozman Nov 8, 2022
1bb3026
Fixed pep8 issues with PR 1589
Zozman Nov 8, 2022
47ddf17
Fixed pep8 issues with PR 1589
Zozman Nov 8, 2022
1282a26
Fixed issue on cloudfront_distribution test
Zozman Nov 8, 2022
2f5604b
Added links to the CloudFront documentation for cache_policy_id and o…
Zozman Nov 9, 2022
d7e0e89
Merge branch 'ansible-collections:main' into cloudfrontCachePolicy
Zozman Apr 10, 2023
ed1e8f8
Merge branch 'main' of github.com:Zozman/community.aws into cloudfron…
Zozman Dec 2, 2023
0b66152
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 2, 2023
ad25bf1
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 2, 2023
0eaee56
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 2, 2023
3a931ca
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 3, 2023
84f30d2
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 4, 2023
4bcf71a
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 4, 2023
45e6725
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 10, 2023
85cf81a
Merge branch 'ansible-collections:main' into cloudfrontCachePolicy
Zozman Dec 10, 2023
6b31b48
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 10, 2023
6b9dce0
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 11, 2023
8ae7721
Merge branch 'ansible-collections:main' into cloudfrontCachePolicy
Zozman Dec 11, 2023
7839ded
cloudfront_distribution: Add support for cache_policy_id and origin_r…
Zozman Dec 11, 2023
ea5bb9a
Merge branch 'ansible-collections:main' into cloudfrontCachePolicy
Zozman Dec 31, 2023
f04664e
Merge branch 'ansible-collections:main' into cloudfrontCachePolicy
Zozman Jan 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- cloudfront_distribution - added support for ``cache_policy_id`` and ``origin_request_policy_id`` for behaviors (https://github.com/ansible-collections/community.aws/pull/1589)
76 changes: 63 additions & 13 deletions plugins/modules/cloudfront_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,25 @@
description:
- The ID of the header policy that CloudFront adds to responses that it sends to viewers.
type: str
cache_policy_id:
version_added: 7.1.0
description:
- The ID of the cache policy for CloudFront to use for the default cache behavior.
- A behavior should use either a C(cache_policy_id) or a C(forwarded_values) option.
- For more information see the CloudFront documentation
at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html)
type: str
origin_request_policy_id:
version_added: 7.1.0
description:
- The ID of the origin request policy for CloudFront to use for the default cache behavior.
- For more information see the CloudFront documentation
at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-origin-requests.html)
type: str
forwarded_values:
description:
- A dict that specifies how CloudFront handles query strings and cookies.
- A behavior should use either a C(cache_policy_id) or a C(forwarded_values) option.
type: dict
suboptions:
query_string:
Expand Down Expand Up @@ -326,9 +342,25 @@
description:
- The ID of the header policy that CloudFront adds to responses that it sends to viewers.
type: str
cache_policy_id:
version_added: 7.1.0
description:
- The ID of the cache policy for CloudFront to use for the cache behavior.
- A behavior should use either a C(cache_policy_id) or a C(forwarded_values) option.
- For more information see the CloudFront documentation
at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html)
type: str
origin_request_policy_id:
version_added: 7.1.0
description:
- The ID of the origin request policy for CloudFront to use for the cache behavior.
- For more information see the CloudFront documentation
at U(https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-origin-requests.html)
type: str
forwarded_values:
description:
- A dict that specifies how CloudFront handles query strings and cookies.
- A behavior should use either a C(cache_policy_id) or a C(forwarded_values) option.
type: dict
suboptions:
query_string:
Expand Down Expand Up @@ -1914,7 +1946,10 @@ def validate_cache_behavior(self, config, cache_behavior, valid_origins, is_defa
cache_behavior = self.validate_cache_behavior_first_level_keys(
config, cache_behavior, valid_origins, is_default_cache
)
cache_behavior = self.validate_forwarded_values(config, cache_behavior.get("forwarded_values"), cache_behavior)
if cache_behavior.get("cache_policy_id") is None:
cache_behavior = self.validate_forwarded_values(
config, cache_behavior.get("forwarded_values"), cache_behavior
)
cache_behavior = self.validate_allowed_methods(config, cache_behavior.get("allowed_methods"), cache_behavior)
cache_behavior = self.validate_lambda_function_associations(
config, cache_behavior.get("lambda_function_associations"), cache_behavior
Expand All @@ -1926,19 +1961,34 @@ def validate_cache_behavior(self, config, cache_behavior, valid_origins, is_defa
return cache_behavior

def validate_cache_behavior_first_level_keys(self, config, cache_behavior, valid_origins, is_default_cache):
try:
cache_behavior = self.add_key_else_change_dict_key(
cache_behavior, "min_ttl", "min_t_t_l", config.get("min_t_t_l", self.__default_cache_behavior_min_ttl)
)
cache_behavior = self.add_key_else_change_dict_key(
cache_behavior, "max_ttl", "max_t_t_l", config.get("max_t_t_l", self.__default_cache_behavior_max_ttl)
)
cache_behavior = self.add_key_else_change_dict_key(
cache_behavior,
"default_ttl",
"default_t_t_l",
config.get("default_t_t_l", self.__default_cache_behavior_default_ttl),
if cache_behavior.get("cache_policy_id") is not None and cache_behavior.get("forwarded_values") is not None:
if is_default_cache:
cache_behavior_name = "Default cache behavior"
else:
cache_behavior_name = f"Cache behavior for path {cache_behavior['path_pattern']}"
self.module.fail_json(
msg=f"{cache_behavior_name} cannot have both a cache_policy_id and a forwarded_values option."
)
try:
if cache_behavior.get("cache_policy_id") is None:
cache_behavior = self.add_key_else_change_dict_key(
cache_behavior,
"min_ttl",
"min_t_t_l",
config.get("min_t_t_l", self.__default_cache_behavior_min_ttl),
)
cache_behavior = self.add_key_else_change_dict_key(
cache_behavior,
"max_ttl",
"max_t_t_l",
config.get("max_t_t_l", self.__default_cache_behavior_max_ttl),
)
cache_behavior = self.add_key_else_change_dict_key(
cache_behavior,
"default_ttl",
"default_t_t_l",
config.get("default_t_t_l", self.__default_cache_behavior_default_ttl),
)
cache_behavior = self.add_missing_key(
cache_behavior, "compress", config.get("compress", self.__default_cache_behavior_compress)
)
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/targets/cloudfront_distribution/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,22 @@
- result.origins['quantity'] > 0
- result.origins['items'] | selectattr('s3_origin_config', 'defined') | map(attribute='s3_origin_config') | selectattr('origin_access_identity', 'eq', origin_access_identity) | list | length == 1

- name: update distribution to use cache_policy_id and origin_request_policy_id
cloudfront_distribution:
distribution_id: "{{ distribution_id }}"
default_cache_behavior:
cache_policy_id: "658327ea-f89d-4fab-a63d-7e88639e58f6"
origin_request_policy_id: "88a5eaf4-2fd4-4709-b370-b4c650ea3fcf"
state: present
register: update_distribution_with_cache_policies

- name: ensure that the cache_policy_id and origin_request_policy_id was set
assert:
that:
- update_distribution_with_cache_policies.changed
- update_distribution_with_cache_policies.default_cache_behavior.cache_policy_id == '658327ea-f89d-4fab-a63d-7e88639e58f6'
- update_distribution_with_cache_policies.default_cache_behavior.origin_request_policy_id == '88a5eaf4-2fd4-4709-b370-b4c650ea3fcf'

always:
# TEARDOWN STARTS HERE
- name: delete the s3 bucket
Expand Down