Skip to content

Commit

Permalink
Fix cloudfront bug
Browse files Browse the repository at this point in the history
  • Loading branch information
marknet15 committed Jan 28, 2022
1 parent 5e5f754 commit 270ee25
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions plugins/modules/cloudfront_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,9 +1686,6 @@ def validate_origins(self, client, config, origins, default_origin_domain_name,
self.module.fail_json_aws(e, msg="Error validating distribution origins")

def validate_s3_origin_configuration(self, client, existing_config, origin):
if not origin['s3_origin_access_identity_enabled']:
return None

if origin.get('s3_origin_config', {}).get('origin_access_identity'):
return origin['s3_origin_config']['origin_access_identity']

Expand Down Expand Up @@ -1719,13 +1716,20 @@ def validate_origin(self, client, existing_config, origin, default_origin_path):
origin['custom_headers'] = ansible_list_to_cloudfront_list()
if self.__s3_bucket_domain_identifier in origin.get('domain_name').lower():
if origin.get("s3_origin_access_identity_enabled") is not None:
s3_origin_config = self.validate_s3_origin_configuration(client, existing_config, origin)
if origin['s3_origin_access_identity_enabled']:
s3_origin_config = self.validate_s3_origin_configuration(client, existing_config, origin)
else:
s3_origin_config = None

del(origin["s3_origin_access_identity_enabled"])

if s3_origin_config:
oai = s3_origin_config
else:
oai = ""

origin["s3_origin_config"] = dict(origin_access_identity=oai)
del(origin["s3_origin_access_identity_enabled"])

if 'custom_origin_config' in origin:
self.module.fail_json(msg="s3_origin_access_identity_enabled and custom_origin_config are mutually exclusive")
else:
Expand Down

0 comments on commit 270ee25

Please sign in to comment.