| 1 |
--- |
| 2 |
- name: 'aws_codebuild integration tests' |
| 3 |
collections: |
| 4 |
- amazon.aws |
| 5 |
module_defaults: |
| 6 |
group/aws: |
| 7 |
access_key: '{{ aws_access_key }}' |
| 8 |
secret_key: '{{ aws_secret_key }}' |
| 9 |
session_token: '{{ security_token | default(omit) }}' |
| 10 |
region: '{{ aws_region }}' |
| 11 |
block: |
| 12 |
|
| 13 |
# ==================== preparaions ======================================== |
| 14 |
|
| 15 |
- name: create IAM role needed for CodePipeline test |
| 16 |
iam_role: |
| 17 |
name: "{{ codepipeline_service_role_name }}" |
| 18 |
description: Role with permissions for CodePipeline actions. |
| 19 |
assume_role_policy_document: "{{ lookup('file', 'codepipeline_iam_trust_policy.json') }}" |
| 20 |
state: present |
| 21 |
register: codepipeline_iam_role |
| 22 |
|
| 23 |
# ================== integration test ========================================== |
| 24 |
|
| 25 |
- name: create CodePipeline |
| 26 |
codepipeline: |
| 27 |
name: "{{ codepipeline_name }}" |
| 28 |
role_arn: "{{ codepipeline_iam_role.iam_role.arn }}" |
| 29 |
artifact_store: |
| 30 |
type: S3 |
| 31 |
location: foo |
| 32 |
stages: |
| 33 |
- name: step_1 |
| 34 |
actions: |
| 35 |
- name: action |
| 36 |
actionTypeId: |
| 37 |
category: Source |
| 38 |
owner: AWS |
| 39 |
provider: S3 |
| 40 |
version: '1' |
| 41 |
configuration: |
| 42 |
S3Bucket: foo |
| 43 |
S3ObjectKey: bar |
| 44 |
outputArtifacts: |
| 45 |
- { name: step_one_output } |
| 46 |
- name: step_2 |
| 47 |
actions: |
| 48 |
- name: action |
| 49 |
actionTypeId: |
| 50 |
category: Build |
| 51 |
owner: AWS |
| 52 |
provider: CodeBuild |
| 53 |
version: '1' |
| 54 |
inputArtifacts: |
| 55 |
- { name: step_one_output } |
| 56 |
outputArtifacts: |
| 57 |
- { name: step_two_output } |
| 58 |
configuration: |
| 59 |
ProjectName: foo |
| 60 |
state: present |
| 61 |
register: output |
| 62 |
retries: 10 |
| 63 |
delay: 5 |
| 64 |
until: output is success |
| 65 |
|
| 66 |
- assert: |
| 67 |
that: |
| 68 |
- output.changed == True |
| 69 |
- output.pipeline.name == codepipeline_name |
| 70 |
- output.pipeline.stages|length > 1 |
| 71 |
|
| 72 |
- name: idempotence check rerunning same CodePipeline task |
| 73 |
codepipeline: |
| 74 |
name: "{{ codepipeline_name }}" |
| 75 |
role_arn: "{{ codepipeline_iam_role.iam_role.arn }}" |
| 76 |
artifact_store: |
| 77 |
type: S3 |
| 78 |
location: foo |
| 79 |
stages: |
| 80 |
- name: step_1 |
| 81 |
actions: |
| 82 |
- name: action |
| 83 |
actionTypeId: |
| 84 |
category: Source |
| 85 |
owner: AWS |
| 86 |
provider: S3 |
| 87 |
version: '1' |
| 88 |
configuration: |
| 89 |
S3Bucket: foo |
| 90 |
S3ObjectKey: bar |
| 91 |
outputArtifacts: |
| 92 |
- { name: step_one_output } |
| 93 |
- name: step_2 |
| 94 |
actions: |
| 95 |
- name: action |
| 96 |
actionTypeId: |
| 97 |
category: Build |
| 98 |
owner: AWS |
| 99 |
provider: CodeBuild |
| 100 |
version: '1' |
| 101 |
inputArtifacts: |
| 102 |
- { name: step_one_output } |
| 103 |
outputArtifacts: |
| 104 |
- { name: step_two_output } |
| 105 |
configuration: |
| 106 |
ProjectName: foo |
| 107 |
state: present |
| 108 |
register: rerun_test_output |
| 109 |
|
| 110 |
- assert: |
| 111 |
that: |
| 112 |
- rerun_test_output.changed == False |
| 113 |
- rerun_test_output.pipeline == output.pipeline |
| 114 |
|
| 115 |
- name: Test deletion of CodePipeline |
| 116 |
codepipeline: |
| 117 |
name: "{{ codepipeline_name }}" |
| 118 |
role_arn: '' |
| 119 |
artifact_store: {} |
| 120 |
stages: [] |
| 121 |
state: absent |
| 122 |
register: absent_test_output |
| 123 |
|
| 124 |
- assert: |
| 125 |
that: |
| 126 |
- absent_test_output.changed == True |
| 127 |
- absent_test_output.pipeline is undefined |
| 128 |
|
| 129 |
# ==================== cleanup ======================= |
| 130 |
|
| 131 |
always: |
| 132 |
|
| 133 |
- name: Cleanup - delete test CodePipeline |
| 134 |
codepipeline: |
| 135 |
name: "{{ codepipeline_name }}" |
| 136 |
role_arn: '' |
| 137 |
artifact_store: {} |
| 138 |
stages: [] |
| 139 |
state: absent |
| 140 |
ignore_errors: true |
| 141 |
|
| 142 |
- name: Cleanup - delete IAM role needed for CodePipeline test |
| 143 |
iam_role: |
| 144 |
name: "{{ codepipeline_name }}" |
| 145 |
state: absent |
| 146 |
ignore_errors: true |