| 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 |
# ==================== preparations ======================================== |
| 14 |
|
| 15 |
- name: create IAM role needed for CodeBuild |
| 16 |
iam_role: |
| 17 |
name: "{{ iam_role_name }}" |
| 18 |
description: Role with permissions for CodeBuild actions. |
| 19 |
assume_role_policy_document: "{{ lookup('file', 'codebuild_iam_trust_policy.json') }}" |
| 20 |
state: present |
| 21 |
register: codebuild_iam_role |
| 22 |
|
| 23 |
- name: Set variable with aws account id |
| 24 |
set_fact: |
| 25 |
aws_account_id: "{{ codebuild_iam_role.iam_role.arn.split(':')[4] }}" |
| 26 |
|
| 27 |
# ================== integration test ========================================== |
| 28 |
|
| 29 |
- name: create CodeBuild project |
| 30 |
codebuild_project: |
| 31 |
name: "{{ project_name }}" |
| 32 |
description: Build project for testing the Ansible aws_codebuild module |
| 33 |
service_role: "{{ codebuild_iam_role.iam_role.arn }}" |
| 34 |
timeout_in_minutes: 30 |
| 35 |
source: |
| 36 |
type: CODEPIPELINE |
| 37 |
buildspec: '' |
| 38 |
artifacts: |
| 39 |
namespace_type: NONE |
| 40 |
packaging: NONE |
| 41 |
type: CODEPIPELINE |
| 42 |
name: test |
| 43 |
environment: |
| 44 |
compute_type: BUILD_GENERAL1_SMALL |
| 45 |
privileged_mode: true |
| 46 |
image: 'aws/codebuild/docker:17.09.0' |
| 47 |
type: LINUX_CONTAINER |
| 48 |
environment_variables: |
| 49 |
- { name: 'FOO_ENV', value: 'other' } |
| 50 |
tags: |
| 51 |
purpose: 'ansible-test' |
| 52 |
state: present |
| 53 |
register: output |
| 54 |
retries: 10 |
| 55 |
delay: 5 |
| 56 |
until: output is success |
| 57 |
|
| 58 |
- assert: |
| 59 |
that: |
| 60 |
- "output.project.description == 'Build project for testing the Ansible aws_codebuild module'" |
| 61 |
- output.project.resource_tags.purpose == "ansible-test" |
| 62 |
|
| 63 |
- name: idempotence check rerunning same Codebuild task |
| 64 |
codebuild_project: |
| 65 |
name: "{{ project_name }}" |
| 66 |
description: Build project for testing the Ansible aws_codebuild module |
| 67 |
service_role: "{{ codebuild_iam_role.iam_role.arn }}" |
| 68 |
timeout_in_minutes: 30 |
| 69 |
source: |
| 70 |
type: CODEPIPELINE |
| 71 |
buildspec: '' |
| 72 |
artifacts: |
| 73 |
namespace_type: NONE |
| 74 |
packaging: NONE |
| 75 |
type: CODEPIPELINE |
| 76 |
name: test |
| 77 |
encryption_key: 'arn:aws:kms:{{ aws_region }}:{{ aws_account_id }}:alias/aws/s3' |
| 78 |
environment: |
| 79 |
compute_type: BUILD_GENERAL1_SMALL |
| 80 |
privileged_mode: true |
| 81 |
image: 'aws/codebuild/docker:17.09.0' |
| 82 |
type: LINUX_CONTAINER |
| 83 |
environment_variables: |
| 84 |
- { name: 'FOO_ENV', value: 'other' } |
| 85 |
tags: |
| 86 |
purpose: 'ansible-test' |
| 87 |
state: present |
| 88 |
register: rerun_test_output |
| 89 |
|
| 90 |
- assert: |
| 91 |
that: |
| 92 |
- "rerun_test_output.project.created == output.project.created" |
| 93 |
- rerun_test_output.project.resource_tags.purpose == "ansible-test" |
| 94 |
|
| 95 |
- include_tasks: 'tagging.yml' |
| 96 |
- include_tasks: 'description.yml' |
| 97 |
|
| 98 |
- name: delete CodeBuild project |
| 99 |
codebuild_project: |
| 100 |
name: "{{ output.project.name }}" |
| 101 |
source: |
| 102 |
type: CODEPIPELINE |
| 103 |
buildspec: '' |
| 104 |
artifacts: {} |
| 105 |
state: absent |
| 106 |
async: 300 |
| 107 |
|
| 108 |
# ============================== cleanup ====================================== |
| 109 |
|
| 110 |
always: |
| 111 |
|
| 112 |
- name: cleanup IAM role created for CodeBuild test |
| 113 |
iam_role: |
| 114 |
name: "{{ iam_role_name }}" |
| 115 |
state: absent |