| 1 |
--- |
| 2 |
- name: aws_glue_job 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 |
# AWS CLI is needed until there's a module to get info about Glue jobs |
| 13 |
- name: Install AWS CLI |
| 14 |
pip: |
| 15 |
name: awscli |
| 16 |
state: present |
| 17 |
|
| 18 |
- name: Create minimal Glue job role |
| 19 |
iam_role: |
| 20 |
name: "{{ glue_job_role_name }}" |
| 21 |
assume_role_policy_document: |
| 22 |
Version: "2008-10-17" |
| 23 |
Statement: |
| 24 |
- Action: "sts:AssumeRole" |
| 25 |
Effect: Allow |
| 26 |
Principal: |
| 27 |
Service: glue.amazonaws.com |
| 28 |
create_instance_profile: false |
| 29 |
managed_policies: |
| 30 |
- "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" |
| 31 |
|
| 32 |
- name: Create Glue job (check mode) |
| 33 |
glue_job: |
| 34 |
name: "{{ glue_job_name }}" |
| 35 |
command_python_version: 3 |
| 36 |
command_script_location: "{{ glue_job_command_script_location }}" |
| 37 |
default_arguments: |
| 38 |
"--TempDir": "{{ glue_job_temp_dir }}" |
| 39 |
description: "{{ glue_job_description }}" |
| 40 |
glue_version: "2.0" |
| 41 |
role: "{{ glue_job_role_name }}" |
| 42 |
tags: |
| 43 |
Environment: Test |
| 44 |
Product: Glue |
| 45 |
state: present |
| 46 |
check_mode: true |
| 47 |
register: glue_job_check |
| 48 |
|
| 49 |
- name: Verity that Glue job was not created in check mode |
| 50 |
assert: |
| 51 |
that: |
| 52 |
- glue_job_check.changed |
| 53 |
- glue_job_check.description is not defined |
| 54 |
|
| 55 |
- name: Create Glue job |
| 56 |
glue_job: |
| 57 |
name: "{{ glue_job_name }}" |
| 58 |
command_python_version: 3 |
| 59 |
command_script_location: "{{ glue_job_command_script_location }}" |
| 60 |
default_arguments: |
| 61 |
"--TempDir": "{{ glue_job_temp_dir }}" |
| 62 |
description: "{{ glue_job_description }}" |
| 63 |
glue_version: "2.0" |
| 64 |
role: "{{ glue_job_role_name }}" |
| 65 |
tags: |
| 66 |
Environment: Test |
| 67 |
Product: Glue |
| 68 |
state: present |
| 69 |
register: glue_job |
| 70 |
|
| 71 |
- name: Get info on Glue job |
| 72 |
command: "aws glue get-job --job-name {{ glue_job_name }}" |
| 73 |
environment: |
| 74 |
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" |
| 75 |
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" |
| 76 |
AWS_SESSION_TOKEN: "{{ security_token | default('') }}" |
| 77 |
AWS_DEFAULT_REGION: "{{ aws_region }}" |
| 78 |
register: job_info_query |
| 79 |
|
| 80 |
- name: Convert it to an object |
| 81 |
set_fact: |
| 82 |
job_info: "{{ job_info_query.stdout | from_json }}" |
| 83 |
|
| 84 |
- name: Verity that Glue job was created |
| 85 |
assert: |
| 86 |
that: |
| 87 |
- glue_job.changed |
| 88 |
- glue_job.command.python_version == job_info["Job"]["Command"]["PythonVersion"] |
| 89 |
- glue_job.command.script_location == job_info["Job"]["Command"]["ScriptLocation"] |
| 90 |
- glue_job.default_arguments == job_info["Job"]["DefaultArguments"] |
| 91 |
- glue_job.description == job_info["Job"]["Description"] |
| 92 |
- glue_job.glue_version == job_info["Job"]["GlueVersion"] |
| 93 |
- glue_job.role == job_info["Job"]["Role"] |
| 94 |
|
| 95 |
- name: Create Glue job (idempotent) (check mode) |
| 96 |
glue_job: |
| 97 |
name: "{{ glue_job_name }}" |
| 98 |
command_python_version: 3 |
| 99 |
command_script_location: "{{ glue_job_command_script_location }}" |
| 100 |
default_arguments: |
| 101 |
"--TempDir": "{{ glue_job_temp_dir }}" |
| 102 |
description: "{{ glue_job_description }}" |
| 103 |
glue_version: "2.0" |
| 104 |
role: "{{ glue_job_role_name }}" |
| 105 |
tags: |
| 106 |
Environment: Test |
| 107 |
Product: Glue |
| 108 |
state: present |
| 109 |
check_mode: true |
| 110 |
register: glue_job_idempotent_check |
| 111 |
|
| 112 |
- name: Get info on Glue job |
| 113 |
command: "aws glue get-job --job-name {{ glue_job_name }}" |
| 114 |
environment: |
| 115 |
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" |
| 116 |
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" |
| 117 |
AWS_SESSION_TOKEN: "{{ security_token | default('') }}" |
| 118 |
AWS_DEFAULT_REGION: "{{ aws_region }}" |
| 119 |
register: job_info_query_idempotent_check |
| 120 |
|
| 121 |
- name: Convert it to an object |
| 122 |
set_fact: |
| 123 |
job_info_idempotent_check: "{{ job_info_query_idempotent_check.stdout | from_json }}" |
| 124 |
|
| 125 |
- name: Verity that Glue job was not modified in check mode |
| 126 |
assert: |
| 127 |
that: |
| 128 |
- not glue_job_idempotent_check.changed |
| 129 |
- job_info["Job"]["Name"] == job_info_idempotent_check["Job"]["Name"] |
| 130 |
- job_info["Job"]["Command"]["PythonVersion"] == job_info_idempotent_check["Job"]["Command"]["PythonVersion"] |
| 131 |
- job_info["Job"]["Command"]["ScriptLocation"] == job_info_idempotent_check["Job"]["Command"]["ScriptLocation"] |
| 132 |
- job_info["Job"]["DefaultArguments"] == job_info_idempotent_check["Job"]["DefaultArguments"] |
| 133 |
- job_info["Job"]["Description"] == job_info_idempotent_check["Job"]["Description"] |
| 134 |
- job_info["Job"]["GlueVersion"] == job_info_idempotent_check["Job"]["GlueVersion"] |
| 135 |
- job_info["Job"]["Role"] == job_info_idempotent_check["Job"]["Role"] |
| 136 |
|
| 137 |
- name: Create Glue job (idempotent) |
| 138 |
glue_job: |
| 139 |
name: "{{ glue_job_name }}" |
| 140 |
command_python_version: 3 |
| 141 |
command_script_location: "{{ glue_job_command_script_location }}" |
| 142 |
default_arguments: |
| 143 |
"--TempDir": "{{ glue_job_temp_dir }}" |
| 144 |
description: "{{ glue_job_description }}" |
| 145 |
glue_version: "2.0" |
| 146 |
role: "{{ glue_job_role_name }}" |
| 147 |
tags: |
| 148 |
Environment: Test |
| 149 |
Product: Glue |
| 150 |
state: present |
| 151 |
register: glue_job_idempotent |
| 152 |
|
| 153 |
- name: Get info on Glue job |
| 154 |
command: "aws glue get-job --job-name {{ glue_job_name }}" |
| 155 |
environment: |
| 156 |
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" |
| 157 |
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" |
| 158 |
AWS_SESSION_TOKEN: "{{ security_token | default('') }}" |
| 159 |
AWS_DEFAULT_REGION: "{{ aws_region }}" |
| 160 |
register: job_info_query_idempotent |
| 161 |
|
| 162 |
- name: Convert it to an object |
| 163 |
set_fact: |
| 164 |
job_info_idempotent: "{{ job_info_query_idempotent.stdout | from_json }}" |
| 165 |
|
| 166 |
- name: Verity that Glue job was not modified |
| 167 |
assert: |
| 168 |
that: |
| 169 |
- not glue_job_idempotent.changed |
| 170 |
- job_info["Job"]["Name"] == job_info_idempotent["Job"]["Name"] |
| 171 |
- job_info["Job"]["Command"]["PythonVersion"] == job_info_idempotent["Job"]["Command"]["PythonVersion"] |
| 172 |
- job_info["Job"]["Command"]["ScriptLocation"] == job_info_idempotent["Job"]["Command"]["ScriptLocation"] |
| 173 |
- job_info["Job"]["DefaultArguments"] == job_info_idempotent["Job"]["DefaultArguments"] |
| 174 |
- job_info["Job"]["Description"] == job_info_idempotent["Job"]["Description"] |
| 175 |
- job_info["Job"]["GlueVersion"] == job_info_idempotent["Job"]["GlueVersion"] |
| 176 |
- job_info["Job"]["Role"] == job_info_idempotent["Job"]["Role"] |
| 177 |
|
| 178 |
- name: Update Glue job (check mode) |
| 179 |
glue_job: |
| 180 |
name: "{{ glue_job_name }}" |
| 181 |
command_python_version: 2 |
| 182 |
command_script_location: "{{ glue_job_command_script_location }}" |
| 183 |
default_arguments: |
| 184 |
"--TempDir": "{{ glue_job_temp_dir }}subfolder/" |
| 185 |
description: "{{ glue_job_description }}" |
| 186 |
glue_version: "0.9" |
| 187 |
role: "{{ glue_job_role_name }}" |
| 188 |
tags: |
| 189 |
Environment: Test |
| 190 |
state: present |
| 191 |
check_mode: true |
| 192 |
register: glue_job_update_check |
| 193 |
|
| 194 |
- name: Get info on Glue job |
| 195 |
command: "aws glue get-job --job-name {{ glue_job_name }}" |
| 196 |
environment: |
| 197 |
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" |
| 198 |
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" |
| 199 |
AWS_SESSION_TOKEN: "{{ security_token | default('') }}" |
| 200 |
AWS_DEFAULT_REGION: "{{ aws_region }}" |
| 201 |
register: job_info_query_update_check |
| 202 |
|
| 203 |
- name: Convert it to an object |
| 204 |
set_fact: |
| 205 |
job_info_update_check: "{{ job_info_query_update_check.stdout | from_json }}" |
| 206 |
|
| 207 |
- name: Verity that Glue job was not modified in check mode |
| 208 |
assert: |
| 209 |
that: |
| 210 |
- glue_job_update_check.changed |
| 211 |
- glue_job_update_check.command.python_version == job_info_update_check["Job"]["Command"]["PythonVersion"] |
| 212 |
- glue_job_update_check.command.script_location == job_info_update_check["Job"]["Command"]["ScriptLocation"] |
| 213 |
- glue_job_update_check.default_arguments == job_info_update_check["Job"]["DefaultArguments"] |
| 214 |
- glue_job_update_check.description == job_info_update_check["Job"]["Description"] |
| 215 |
- glue_job_update_check.glue_version == job_info_update_check["Job"]["GlueVersion"] |
| 216 |
- glue_job_update_check.role == job_info_update_check["Job"]["Role"] |
| 217 |
|
| 218 |
- name: Update Glue job |
| 219 |
glue_job: |
| 220 |
name: "{{ glue_job_name }}" |
| 221 |
command_python_version: 2 |
| 222 |
command_script_location: "{{ glue_job_command_script_location }}" |
| 223 |
default_arguments: |
| 224 |
"--TempDir": "{{ glue_job_temp_dir }}subfolder/" |
| 225 |
description: "{{ glue_job_description }}" |
| 226 |
glue_version: "0.9" |
| 227 |
role: "{{ glue_job_role_name }}" |
| 228 |
tags: |
| 229 |
Environment: Test |
| 230 |
state: present |
| 231 |
register: glue_job_update |
| 232 |
|
| 233 |
- name: Get info on Glue job |
| 234 |
command: "aws glue get-job --job-name {{ glue_job_name }}" |
| 235 |
environment: |
| 236 |
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" |
| 237 |
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" |
| 238 |
AWS_SESSION_TOKEN: "{{ security_token | default('') }}" |
| 239 |
AWS_DEFAULT_REGION: "{{ aws_region }}" |
| 240 |
register: job_info_query_update |
| 241 |
|
| 242 |
- name: Convert it to an object |
| 243 |
set_fact: |
| 244 |
job_info_update: "{{ job_info_query_update.stdout | from_json }}" |
| 245 |
|
| 246 |
- name: Verity that Glue job was modified |
| 247 |
assert: |
| 248 |
that: |
| 249 |
- glue_job_update.changed |
| 250 |
- glue_job_update.command.python_version == job_info_update["Job"]["Command"]["PythonVersion"] |
| 251 |
- glue_job_update.command.script_location == job_info_update["Job"]["Command"]["ScriptLocation"] |
| 252 |
- glue_job_update.default_arguments == job_info_update["Job"]["DefaultArguments"] |
| 253 |
- glue_job_update.description == job_info_update["Job"]["Description"] |
| 254 |
- glue_job_update.glue_version == job_info_update["Job"]["GlueVersion"] |
| 255 |
- glue_job_update.role == job_info_update["Job"]["Role"] |
| 256 |
|
| 257 |
- name: Delete Glue job (check mode) |
| 258 |
glue_job: |
| 259 |
name: "{{ glue_job_name }}" |
| 260 |
state: absent |
| 261 |
check_mode: true |
| 262 |
register: glue_job_delete_check |
| 263 |
|
| 264 |
- name: Get info on Glue job |
| 265 |
command: "aws glue get-job --job-name {{ glue_job_name }}" |
| 266 |
environment: |
| 267 |
AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" |
| 268 |
AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" |
| 269 |
AWS_SESSION_TOKEN: "{{ security_token | default('') }}" |
| 270 |
AWS_DEFAULT_REGION: "{{ aws_region }}" |
| 271 |
register: job_info_query_delete_check |
| 272 |
|
| 273 |
- name: Convert it to an object |
| 274 |
set_fact: |
| 275 |
job_info_delete_check: "{{ job_info_query_delete_check.stdout | from_json }}" |
| 276 |
|
| 277 |
- name: Verity that Glue job was not deleted in check mode |
| 278 |
assert: |
| 279 |
that: |
| 280 |
- glue_job_delete_check.changed |
| 281 |
- job_info["Job"]["Name"] == job_info_delete_check["Job"]["Name"] |
| 282 |
|
| 283 |
- name: Delete Glue job |
| 284 |
glue_job: |
| 285 |
name: "{{ glue_job_name }}" |
| 286 |
state: absent |
| 287 |
register: glue_job_delete |
| 288 |
|
| 289 |
- name: Verity that Glue job was deleted |
| 290 |
assert: |
| 291 |
that: |
| 292 |
- glue_job_delete.changed |
| 293 |
|
| 294 |
always: |
| 295 |
- name: Delete Glue job |
| 296 |
glue_job: |
| 297 |
name: "{{ glue_job_name }}" |
| 298 |
state: absent |
| 299 |
ignore_errors: true |
| 300 |
- name: Delete Glue job role |
| 301 |
iam_role: |
| 302 |
name: "{{ glue_job_role_name }}" |
| 303 |
state: absent |
| 304 |
ignore_errors: true |