| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: Ansible Project |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
DOCUMENTATION = r""" |
| 8 |
--- |
| 9 |
module: ecs_ecr |
| 10 |
version_added: 1.0.0 |
| 11 |
short_description: Manage Elastic Container Registry repositories |
| 12 |
description: |
| 13 |
- Manage Elastic Container Registry repositories. |
| 14 |
options: |
| 15 |
name: |
| 16 |
description: |
| 17 |
- The name of the repository. |
| 18 |
required: true |
| 19 |
type: str |
| 20 |
registry_id: |
| 21 |
description: |
| 22 |
- AWS account id associated with the registry. |
| 23 |
- If not specified, the default registry is assumed. |
| 24 |
required: false |
| 25 |
type: str |
| 26 |
policy: |
| 27 |
description: |
| 28 |
- JSON or dict that represents the new policy. |
| 29 |
required: false |
| 30 |
type: json |
| 31 |
force_absent: |
| 32 |
description: |
| 33 |
- If I(force_absent=true), the repository will be removed, even if images are present. |
| 34 |
required: false |
| 35 |
default: false |
| 36 |
type: bool |
| 37 |
version_added: 4.1.0 |
| 38 |
force_set_policy: |
| 39 |
description: |
| 40 |
- If I(force_set_policy=false), it prevents setting a policy that would prevent you from |
| 41 |
setting another policy in the future. |
| 42 |
required: false |
| 43 |
default: false |
| 44 |
type: bool |
| 45 |
purge_policy: |
| 46 |
description: |
| 47 |
- If C(true), remove the policy from the repository. |
| 48 |
- Defaults to C(false). |
| 49 |
required: false |
| 50 |
type: bool |
| 51 |
image_tag_mutability: |
| 52 |
description: |
| 53 |
- Configure whether repository should be mutable (ie. an already existing tag can be overwritten) or not. |
| 54 |
required: false |
| 55 |
choices: [mutable, immutable] |
| 56 |
default: 'mutable' |
| 57 |
type: str |
| 58 |
lifecycle_policy: |
| 59 |
description: |
| 60 |
- JSON or dict that represents the new lifecycle policy. |
| 61 |
required: false |
| 62 |
type: json |
| 63 |
purge_lifecycle_policy: |
| 64 |
description: |
| 65 |
- if C(true), remove the lifecycle policy from the repository. |
| 66 |
- Defaults to C(false). |
| 67 |
required: false |
| 68 |
type: bool |
| 69 |
state: |
| 70 |
description: |
| 71 |
- Create or destroy the repository. |
| 72 |
required: false |
| 73 |
choices: [present, absent] |
| 74 |
default: 'present' |
| 75 |
type: str |
| 76 |
scan_on_push: |
| 77 |
description: |
| 78 |
- if C(true), images are scanned for known vulnerabilities after being pushed to the repository. |
| 79 |
required: false |
| 80 |
default: false |
| 81 |
type: bool |
| 82 |
version_added: 1.3.0 |
| 83 |
encryption_configuration: |
| 84 |
description: |
| 85 |
- The encryption configuration for the repository. |
| 86 |
required: false |
| 87 |
suboptions: |
| 88 |
encryption_type: |
| 89 |
description: |
| 90 |
- The encryption type to use. |
| 91 |
choices: [AES256, KMS] |
| 92 |
default: 'AES256' |
| 93 |
type: str |
| 94 |
kms_key: |
| 95 |
description: |
| 96 |
- If I(encryption_type=KMS), specify the KMS key to use for encryption. |
| 97 |
- The alias, key ID, or full ARN of the KMS key can be specified. |
| 98 |
type: str |
| 99 |
type: dict |
| 100 |
version_added: 5.2.0 |
| 101 |
author: |
| 102 |
- David M. Lee (@leedm777) |
| 103 |
extends_documentation_fragment: |
| 104 |
- amazon.aws.common.modules |
| 105 |
- amazon.aws.region.modules |
| 106 |
- amazon.aws.boto3 |
| 107 |
""" |
| 108 |
|
| 109 |
EXAMPLES = r""" |
| 110 |
# If the repository does not exist, it is created. If it does exist, would not |
| 111 |
# affect any policies already on it. |
| 112 |
- name: ecr-repo |
| 113 |
community.aws.ecs_ecr: |
| 114 |
name: super/cool |
| 115 |
|
| 116 |
- name: destroy-ecr-repo |
| 117 |
community.aws.ecs_ecr: |
| 118 |
name: old/busted |
| 119 |
state: absent |
| 120 |
|
| 121 |
- name: Cross account ecr-repo |
| 122 |
community.aws.ecs_ecr: |
| 123 |
registry_id: 123456789012 |
| 124 |
name: cross/account |
| 125 |
|
| 126 |
- name: set-policy as object |
| 127 |
community.aws.ecs_ecr: |
| 128 |
name: needs-policy-object |
| 129 |
policy: |
| 130 |
Version: '2008-10-17' |
| 131 |
Statement: |
| 132 |
- Sid: read-only |
| 133 |
Effect: Allow |
| 134 |
Principal: |
| 135 |
AWS: '{{ read_only_arn }}' |
| 136 |
Action: |
| 137 |
- ecr:GetDownloadUrlForLayer |
| 138 |
- ecr:BatchGetImage |
| 139 |
- ecr:BatchCheckLayerAvailability |
| 140 |
|
| 141 |
- name: set-policy as string |
| 142 |
community.aws.ecs_ecr: |
| 143 |
name: needs-policy-string |
| 144 |
policy: "{{ lookup('template', 'policy.json.j2') }}" |
| 145 |
|
| 146 |
- name: delete-policy |
| 147 |
community.aws.ecs_ecr: |
| 148 |
name: needs-no-policy |
| 149 |
purge_policy: true |
| 150 |
|
| 151 |
- name: create immutable ecr-repo |
| 152 |
community.aws.ecs_ecr: |
| 153 |
name: super/cool |
| 154 |
image_tag_mutability: immutable |
| 155 |
|
| 156 |
- name: set-lifecycle-policy |
| 157 |
community.aws.ecs_ecr: |
| 158 |
name: needs-lifecycle-policy |
| 159 |
scan_on_push: true |
| 160 |
lifecycle_policy: |
| 161 |
rules: |
| 162 |
- rulePriority: 1 |
| 163 |
description: new policy |
| 164 |
selection: |
| 165 |
tagStatus: untagged |
| 166 |
countType: sinceImagePushed |
| 167 |
countUnit: days |
| 168 |
countNumber: 365 |
| 169 |
action: |
| 170 |
type: expire |
| 171 |
|
| 172 |
- name: purge-lifecycle-policy |
| 173 |
community.aws.ecs_ecr: |
| 174 |
name: needs-no-lifecycle-policy |
| 175 |
purge_lifecycle_policy: true |
| 176 |
|
| 177 |
- name: set-encryption-configuration |
| 178 |
community.aws.ecs_ecr: |
| 179 |
name: uses-custom-kms-key |
| 180 |
encryption_configuration: |
| 181 |
encryption_type: KMS |
| 182 |
kms_key: custom-kms-key-alias |
| 183 |
""" |
| 184 |
|
| 185 |
RETURN = r""" |
| 186 |
state: |
| 187 |
type: str |
| 188 |
description: The asserted state of the repository (present, absent) |
| 189 |
returned: always |
| 190 |
created: |
| 191 |
type: bool |
| 192 |
description: If true, the repository was created |
| 193 |
returned: always |
| 194 |
name: |
| 195 |
type: str |
| 196 |
description: The name of the repository |
| 197 |
returned: I(state=absent) |
| 198 |
policy: |
| 199 |
type: dict |
| 200 |
description: The existing, created or updated repository policy. |
| 201 |
returned: I(state=present) |
| 202 |
version_added: 4.0.0 |
| 203 |
repository: |
| 204 |
type: dict |
| 205 |
description: The created or updated repository |
| 206 |
returned: I(state=present) |
| 207 |
sample: |
| 208 |
createdAt: '2017-01-17T08:41:32-06:00' |
| 209 |
registryId: '123456789012' |
| 210 |
repositoryArn: arn:aws:ecr:us-east-1:123456789012:repository/ecr-test-1484664090 |
| 211 |
repositoryName: ecr-test-1484664090 |
| 212 |
repositoryUri: 123456789012.dkr.ecr.us-east-1.amazonaws.com/ecr-test-1484664090 |
| 213 |
""" |
| 214 |
|
| 215 |
import json |
| 216 |
import traceback |
| 217 |
|
| 218 |
try: |
| 219 |
import botocore |
| 220 |
except ImportError: |
| 221 |
pass # Handled by AnsibleAWSModule |
| 222 |
|
| 223 |
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict |
| 224 |
|
| 225 |
from ansible_collections.amazon.aws.plugins.module_utils.botocore import boto_exception |
| 226 |
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code |
| 227 |
from ansible_collections.amazon.aws.plugins.module_utils.policy import compare_policies |
| 228 |
|
| 229 |
from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule |
| 230 |
|
| 231 |
|
| 232 |
def build_kwargs(registry_id): |
| 233 |
""" |
| 234 |
Builds a kwargs dict which may contain the optional registryId. |
| 235 |
|
| 236 |
:param registry_id: Optional string containing the registryId. |
| 237 |
:return: kwargs dict with registryId, if given |
| 238 |
""" |
| 239 |
if not registry_id: |
| 240 |
return dict() |
| 241 |
else: |
| 242 |
return dict(registryId=registry_id) |
| 243 |
|
| 244 |
|
| 245 |
class EcsEcr: |
| 246 |
def __init__(self, module): |
| 247 |
self.ecr = module.client("ecr") |
| 248 |
self.sts = module.client("sts") |
| 249 |
self.check_mode = module.check_mode |
| 250 |
self.changed = False |
| 251 |
self.skipped = False |
| 252 |
|
| 253 |
def get_repository(self, registry_id, name): |
| 254 |
try: |
| 255 |
res = self.ecr.describe_repositories(repositoryNames=[name], **build_kwargs(registry_id)) |
| 256 |
repos = res.get("repositories") |
| 257 |
return repos and repos[0] |
| 258 |
except is_boto3_error_code("RepositoryNotFoundException"): |
| 259 |
return None |
| 260 |
|
| 261 |
def get_repository_policy(self, registry_id, name): |
| 262 |
try: |
| 263 |
res = self.ecr.get_repository_policy(repositoryName=name, **build_kwargs(registry_id)) |
| 264 |
text = res.get("policyText") |
| 265 |
return text and json.loads(text) |
| 266 |
except is_boto3_error_code(["RepositoryNotFoundException", "RepositoryPolicyNotFoundException"]): |
| 267 |
return None |
| 268 |
|
| 269 |
def create_repository(self, registry_id, name, image_tag_mutability, encryption_configuration): |
| 270 |
if registry_id: |
| 271 |
default_registry_id = self.sts.get_caller_identity().get("Account") |
| 272 |
if registry_id != default_registry_id: |
| 273 |
raise Exception( |
| 274 |
f"Cannot create repository in registry {registry_id}. Would be created in {default_registry_id} instead." |
| 275 |
) |
| 276 |
|
| 277 |
if encryption_configuration is None: |
| 278 |
encryption_configuration = dict(encryptionType="AES256") |
| 279 |
|
| 280 |
if not self.check_mode: |
| 281 |
repo = self.ecr.create_repository( |
| 282 |
repositoryName=name, |
| 283 |
imageTagMutability=image_tag_mutability, |
| 284 |
encryptionConfiguration=encryption_configuration, |
| 285 |
).get("repository") |
| 286 |
self.changed = True |
| 287 |
return repo |
| 288 |
else: |
| 289 |
self.skipped = True |
| 290 |
return dict(repositoryName=name) |
| 291 |
|
| 292 |
def set_repository_policy(self, registry_id, name, policy_text, force): |
| 293 |
if not self.check_mode: |
| 294 |
policy = self.ecr.set_repository_policy( |
| 295 |
repositoryName=name, policyText=policy_text, force=force, **build_kwargs(registry_id) |
| 296 |
) |
| 297 |
self.changed = True |
| 298 |
return policy |
| 299 |
else: |
| 300 |
self.skipped = True |
| 301 |
if self.get_repository(registry_id, name) is None: |
| 302 |
printable = name |
| 303 |
if registry_id: |
| 304 |
printable = f"{registry_id}:{name}" |
| 305 |
raise Exception(f"could not find repository {printable}") |
| 306 |
return |
| 307 |
|
| 308 |
def delete_repository(self, registry_id, name, force): |
| 309 |
if not self.check_mode: |
| 310 |
repo = self.ecr.delete_repository(repositoryName=name, force=force, **build_kwargs(registry_id)) |
| 311 |
self.changed = True |
| 312 |
return repo |
| 313 |
else: |
| 314 |
repo = self.get_repository(registry_id, name) |
| 315 |
if repo: |
| 316 |
self.skipped = True |
| 317 |
return repo |
| 318 |
return None |
| 319 |
|
| 320 |
def delete_repository_policy(self, registry_id, name): |
| 321 |
if not self.check_mode: |
| 322 |
policy = self.ecr.delete_repository_policy(repositoryName=name, **build_kwargs(registry_id)) |
| 323 |
self.changed = True |
| 324 |
return policy |
| 325 |
else: |
| 326 |
policy = self.get_repository_policy(registry_id, name) |
| 327 |
if policy: |
| 328 |
self.skipped = True |
| 329 |
return policy |
| 330 |
return None |
| 331 |
|
| 332 |
def put_image_tag_mutability(self, registry_id, name, new_mutability_configuration): |
| 333 |
repo = self.get_repository(registry_id, name) |
| 334 |
current_mutability_configuration = repo.get("imageTagMutability") |
| 335 |
|
| 336 |
if current_mutability_configuration != new_mutability_configuration: |
| 337 |
if not self.check_mode: |
| 338 |
self.ecr.put_image_tag_mutability( |
| 339 |
repositoryName=name, imageTagMutability=new_mutability_configuration, **build_kwargs(registry_id) |
| 340 |
) |
| 341 |
else: |
| 342 |
self.skipped = True |
| 343 |
self.changed = True |
| 344 |
|
| 345 |
repo["imageTagMutability"] = new_mutability_configuration |
| 346 |
return repo |
| 347 |
|
| 348 |
def get_lifecycle_policy(self, registry_id, name): |
| 349 |
try: |
| 350 |
res = self.ecr.get_lifecycle_policy(repositoryName=name, **build_kwargs(registry_id)) |
| 351 |
text = res.get("lifecyclePolicyText") |
| 352 |
return text and json.loads(text) |
| 353 |
except is_boto3_error_code(["LifecyclePolicyNotFoundException", "RepositoryNotFoundException"]): |
| 354 |
return None |
| 355 |
|
| 356 |
def put_lifecycle_policy(self, registry_id, name, policy_text): |
| 357 |
if not self.check_mode: |
| 358 |
policy = self.ecr.put_lifecycle_policy( |
| 359 |
repositoryName=name, lifecyclePolicyText=policy_text, **build_kwargs(registry_id) |
| 360 |
) |
| 361 |
self.changed = True |
| 362 |
return policy |
| 363 |
else: |
| 364 |
self.skipped = True |
| 365 |
if self.get_repository(registry_id, name) is None: |
| 366 |
printable = name |
| 367 |
if registry_id: |
| 368 |
printable = f"{registry_id}:{name}" |
| 369 |
raise Exception(f"could not find repository {printable}") |
| 370 |
return |
| 371 |
|
| 372 |
def purge_lifecycle_policy(self, registry_id, name): |
| 373 |
if not self.check_mode: |
| 374 |
policy = self.ecr.delete_lifecycle_policy(repositoryName=name, **build_kwargs(registry_id)) |
| 375 |
self.changed = True |
| 376 |
return policy |
| 377 |
else: |
| 378 |
policy = self.get_lifecycle_policy(registry_id, name) |
| 379 |
if policy: |
| 380 |
self.skipped = True |
| 381 |
return policy |
| 382 |
return None |
| 383 |
|
| 384 |
def put_image_scanning_configuration(self, registry_id, name, scan_on_push): |
| 385 |
if not self.check_mode: |
| 386 |
if registry_id: |
| 387 |
scan = self.ecr.put_image_scanning_configuration( |
| 388 |
registryId=registry_id, repositoryName=name, imageScanningConfiguration={"scanOnPush": scan_on_push} |
| 389 |
) |
| 390 |
else: |
| 391 |
scan = self.ecr.put_image_scanning_configuration( |
| 392 |
repositoryName=name, imageScanningConfiguration={"scanOnPush": scan_on_push} |
| 393 |
) |
| 394 |
self.changed = True |
| 395 |
return scan |
| 396 |
else: |
| 397 |
self.skipped = True |
| 398 |
return None |
| 399 |
|
| 400 |
|
| 401 |
def sort_lists_of_strings(policy): |
| 402 |
for statement_index in range(0, len(policy.get("Statement", []))): |
| 403 |
for key in policy["Statement"][statement_index]: |
| 404 |
value = policy["Statement"][statement_index][key] |
| 405 |
if isinstance(value, list) and all(isinstance(item, str) for item in value): |
| 406 |
policy["Statement"][statement_index][key] = sorted(value) |
| 407 |
return policy |
| 408 |
|
| 409 |
|
| 410 |
def run(ecr, params): |
| 411 |
# type: (EcsEcr, dict, int) -> Tuple[bool, dict] |
| 412 |
result = {} |
| 413 |
try: |
| 414 |
name = params["name"] |
| 415 |
state = params["state"] |
| 416 |
policy_text = params["policy"] |
| 417 |
purge_policy = params["purge_policy"] |
| 418 |
force_absent = params["force_absent"] |
| 419 |
registry_id = params["registry_id"] |
| 420 |
force_set_policy = params["force_set_policy"] |
| 421 |
image_tag_mutability = params["image_tag_mutability"].upper() |
| 422 |
lifecycle_policy_text = params["lifecycle_policy"] |
| 423 |
purge_lifecycle_policy = params["purge_lifecycle_policy"] |
| 424 |
scan_on_push = params["scan_on_push"] |
| 425 |
encryption_configuration = snake_dict_to_camel_dict(params["encryption_configuration"]) |
| 426 |
|
| 427 |
# Parse policies, if they are given |
| 428 |
try: |
| 429 |
policy = policy_text and json.loads(policy_text) |
| 430 |
except ValueError: |
| 431 |
result["policy"] = policy_text |
| 432 |
result["msg"] = "Could not parse policy" |
| 433 |
return False, result |
| 434 |
|
| 435 |
try: |
| 436 |
lifecycle_policy = lifecycle_policy_text and json.loads(lifecycle_policy_text) |
| 437 |
except ValueError: |
| 438 |
result["lifecycle_policy"] = lifecycle_policy_text |
| 439 |
result["msg"] = "Could not parse lifecycle_policy" |
| 440 |
return False, result |
| 441 |
|
| 442 |
result["state"] = state |
| 443 |
result["created"] = False |
| 444 |
|
| 445 |
repo = ecr.get_repository(registry_id, name) |
| 446 |
|
| 447 |
if state == "present": |
| 448 |
result["created"] = False |
| 449 |
|
| 450 |
if not repo: |
| 451 |
repo = ecr.create_repository(registry_id, name, image_tag_mutability, encryption_configuration) |
| 452 |
result["changed"] = True |
| 453 |
result["created"] = True |
| 454 |
else: |
| 455 |
if encryption_configuration is not None: |
| 456 |
if repo.get("encryptionConfiguration") != encryption_configuration: |
| 457 |
result["msg"] = "Cannot modify repository encryption type" |
| 458 |
return False, result |
| 459 |
|
| 460 |
repo = ecr.put_image_tag_mutability(registry_id, name, image_tag_mutability) |
| 461 |
result["repository"] = repo |
| 462 |
|
| 463 |
if purge_lifecycle_policy: |
| 464 |
original_lifecycle_policy = ecr.get_lifecycle_policy(registry_id, name) |
| 465 |
|
| 466 |
result["lifecycle_policy"] = None |
| 467 |
|
| 468 |
if original_lifecycle_policy: |
| 469 |
ecr.purge_lifecycle_policy(registry_id, name) |
| 470 |
result["changed"] = True |
| 471 |
|
| 472 |
elif lifecycle_policy_text is not None: |
| 473 |
try: |
| 474 |
result["lifecycle_policy"] = lifecycle_policy |
| 475 |
original_lifecycle_policy = ecr.get_lifecycle_policy(registry_id, name) |
| 476 |
|
| 477 |
if compare_policies(original_lifecycle_policy, lifecycle_policy): |
| 478 |
ecr.put_lifecycle_policy(registry_id, name, lifecycle_policy_text) |
| 479 |
result["changed"] = True |
| 480 |
except Exception: |
| 481 |
# Some failure w/ the policy. It's helpful to know what the |
| 482 |
# policy is. |
| 483 |
result["lifecycle_policy"] = lifecycle_policy_text |
| 484 |
raise |
| 485 |
|
| 486 |
if purge_policy: |
| 487 |
original_policy = ecr.get_repository_policy(registry_id, name) |
| 488 |
|
| 489 |
result["policy"] = None |
| 490 |
|
| 491 |
if original_policy: |
| 492 |
ecr.delete_repository_policy(registry_id, name) |
| 493 |
result["changed"] = True |
| 494 |
|
| 495 |
elif policy_text is not None: |
| 496 |
try: |
| 497 |
# Sort any lists containing only string types |
| 498 |
policy = sort_lists_of_strings(policy) |
| 499 |
|
| 500 |
result["policy"] = policy |
| 501 |
|
| 502 |
original_policy = ecr.get_repository_policy(registry_id, name) |
| 503 |
if original_policy: |
| 504 |
original_policy = sort_lists_of_strings(original_policy) |
| 505 |
|
| 506 |
if compare_policies(original_policy, policy): |
| 507 |
ecr.set_repository_policy(registry_id, name, policy_text, force_set_policy) |
| 508 |
result["changed"] = True |
| 509 |
except Exception: |
| 510 |
# Some failure w/ the policy. It's helpful to know what the |
| 511 |
# policy is. |
| 512 |
result["policy"] = policy_text |
| 513 |
raise |
| 514 |
|
| 515 |
else: |
| 516 |
original_policy = ecr.get_repository_policy(registry_id, name) |
| 517 |
if original_policy: |
| 518 |
result["policy"] = original_policy |
| 519 |
|
| 520 |
original_scan_on_push = ecr.get_repository(registry_id, name) |
| 521 |
if original_scan_on_push is not None: |
| 522 |
if scan_on_push != original_scan_on_push["imageScanningConfiguration"]["scanOnPush"]: |
| 523 |
result["changed"] = True |
| 524 |
result["repository"]["imageScanningConfiguration"]["scanOnPush"] = scan_on_push |
| 525 |
ecr.put_image_scanning_configuration(registry_id, name, scan_on_push) |
| 526 |
|
| 527 |
elif state == "absent": |
| 528 |
result["name"] = name |
| 529 |
if repo: |
| 530 |
ecr.delete_repository(registry_id, name, force_absent) |
| 531 |
result["changed"] = True |
| 532 |
|
| 533 |
except Exception as err: |
| 534 |
msg = str(err) |
| 535 |
if isinstance(err, botocore.exceptions.ClientError): |
| 536 |
msg = boto_exception(err) |
| 537 |
result["msg"] = msg |
| 538 |
result["exception"] = traceback.format_exc() |
| 539 |
return False, result |
| 540 |
|
| 541 |
if ecr.skipped: |
| 542 |
result["skipped"] = True |
| 543 |
|
| 544 |
if ecr.changed: |
| 545 |
result["changed"] = True |
| 546 |
|
| 547 |
return True, result |
| 548 |
|
| 549 |
|
| 550 |
def main(): |
| 551 |
argument_spec = dict( |
| 552 |
name=dict(required=True), |
| 553 |
registry_id=dict(required=False), |
| 554 |
state=dict(required=False, choices=["present", "absent"], default="present"), |
| 555 |
force_absent=dict(required=False, type="bool", default=False), |
| 556 |
force_set_policy=dict(required=False, type="bool", default=False), |
| 557 |
policy=dict(required=False, type="json"), |
| 558 |
image_tag_mutability=dict(required=False, choices=["mutable", "immutable"], default="mutable"), |
| 559 |
purge_policy=dict(required=False, type="bool"), |
| 560 |
lifecycle_policy=dict(required=False, type="json"), |
| 561 |
purge_lifecycle_policy=dict(required=False, type="bool"), |
| 562 |
scan_on_push=(dict(required=False, type="bool", default=False)), |
| 563 |
encryption_configuration=dict( |
| 564 |
required=False, |
| 565 |
type="dict", |
| 566 |
options=dict( |
| 567 |
encryption_type=dict(required=False, type="str", default="AES256", choices=["AES256", "KMS"]), |
| 568 |
kms_key=dict(required=False, type="str", no_log=False), |
| 569 |
), |
| 570 |
required_if=[ |
| 571 |
["encryption_type", "KMS", ["kms_key"]], |
| 572 |
], |
| 573 |
), |
| 574 |
) |
| 575 |
mutually_exclusive = [ |
| 576 |
["policy", "purge_policy"], |
| 577 |
["lifecycle_policy", "purge_lifecycle_policy"], |
| 578 |
] |
| 579 |
|
| 580 |
module = AnsibleAWSModule( |
| 581 |
argument_spec=argument_spec, |
| 582 |
supports_check_mode=True, |
| 583 |
mutually_exclusive=mutually_exclusive, |
| 584 |
) |
| 585 |
|
| 586 |
ecr = EcsEcr(module) |
| 587 |
passed, result = run(ecr, module.params) |
| 588 |
|
| 589 |
if passed: |
| 590 |
module.exit_json(**result) |
| 591 |
else: |
| 592 |
module.fail_json(**result) |
| 593 |
|
| 594 |
|
| 595 |
if __name__ == "__main__": |
| 596 |
main() |