-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lambda wait issue and add more integration tests (#15)
* Add missing waits after changing Lambda state * Add integration test for lambda module * Add integration test for lambda_alias module
- Loading branch information
Showing
11 changed files
with
244 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cloud/aws | ||
gather_facts/no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function_name: "{{ resource_prefix }}-event" | ||
function_arn: "arn:aws:lambda:{{ aws_region }}:{{ aws_account_id }}:function:{{ function_name }}:test" | ||
iam_role_name: "{{ ('' if resource_prefix.startswith('ansible-test-') else 'ansible-test-') + resource_prefix }}" | ||
iam_role_arn: "arn:aws:iam::{{ aws_account_id }}:role/{{ iam_role_name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- block: | ||
- import_tasks: setup.yml | ||
- import_tasks: tests.yml | ||
module_defaults: | ||
group/mattclay.aws.common: | ||
access_key: "{{ aws_access_key }}" | ||
secret_key: "{{ aws_secret_key }}" | ||
aws_region: "{{ aws_region }}" | ||
security_token: "{{ security_token }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
- name: Create a role | ||
community.aws.iam_role: | ||
name: "{{ iam_role_name }}" | ||
assume_role_policy_document: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Action: sts:AssumeRole | ||
Effect: Allow | ||
Principal: | ||
Service: lambda.amazonaws.com | ||
managed_policies: | ||
- arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole | ||
|
||
- name: Wait for role to be usable | ||
pause: | ||
seconds: 10 | ||
|
||
- name: Gather account facts | ||
aws_account_facts: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
- name: Create a Lambda function (check) | ||
lambda: | ||
name: "{{ function_name }}" | ||
code: "# no actual code" | ||
runtime: python3.8 | ||
timeout: 60 | ||
handler: lambda_function.lambda_handler | ||
memory_size: 128 | ||
role: "{{ iam_role_arn }}" | ||
publish: yes | ||
qualifier: "test" | ||
check_mode: yes | ||
register: create_check | ||
|
||
- name: Create a Lambda function (changed) | ||
lambda: | ||
name: "{{ function_name }}" | ||
code: "# no actual code" | ||
runtime: python3.8 | ||
timeout: 60 | ||
handler: lambda_function.lambda_handler | ||
memory_size: 128 | ||
role: "{{ iam_role_arn }}" | ||
publish: yes | ||
qualifier: "test" | ||
register: create_changed | ||
|
||
- name: Create a Lambda function (unchanged) | ||
lambda: | ||
name: "{{ function_name }}" | ||
code: "# no actual code" | ||
runtime: python3.8 | ||
timeout: 60 | ||
handler: lambda_function.lambda_handler | ||
memory_size: 128 | ||
role: "{{ iam_role_arn }}" | ||
publish: no # publishing would force an update and thus report changed | ||
qualifier: "test" | ||
register: create_unchanged | ||
|
||
- name: Update a Lambda function (check) | ||
lambda: | ||
name: "{{ function_name }}" | ||
code: "# updated code" | ||
runtime: python3.8 | ||
timeout: 60 | ||
handler: lambda_function.lambda_handler | ||
memory_size: 128 | ||
role: "{{ iam_role_arn }}" | ||
publish: yes | ||
qualifier: "test" | ||
check_mode: yes | ||
register: update_check | ||
|
||
- name: Update a Lambda function (changed) | ||
lambda: | ||
name: "{{ function_name }}" | ||
code: "# updated code" | ||
runtime: python3.8 | ||
timeout: 60 | ||
handler: lambda_function.lambda_handler | ||
memory_size: 128 | ||
role: "{{ iam_role_arn }}" | ||
publish: yes | ||
qualifier: "test" | ||
register: update_changed | ||
|
||
- name: Update a Lambda function (unchanged) | ||
lambda: | ||
name: "{{ function_name }}" | ||
code: "# updated code" | ||
runtime: python3.8 | ||
timeout: 60 | ||
handler: lambda_function.lambda_handler | ||
memory_size: 128 | ||
role: "{{ iam_role_arn }}" | ||
publish: no # publishing would force an update and thus report changed | ||
qualifier: "test" | ||
register: update_unchanged | ||
|
||
- name: Check results | ||
assert: | ||
that: | ||
- create_check is changed | ||
- create_changed is changed | ||
- create_unchanged is not changed | ||
- update_check is changed | ||
- update_changed is changed | ||
- update_unchanged is not changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cloud/aws | ||
gather_facts/no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function_name: "{{ resource_prefix }}-event" | ||
function_arn: "arn:aws:lambda:{{ aws_region }}:{{ aws_account_id }}:function:{{ function_name }}:test" | ||
iam_role_name: "{{ ('' if resource_prefix.startswith('ansible-test-') else 'ansible-test-') + resource_prefix }}" | ||
iam_role_arn: "arn:aws:iam::{{ aws_account_id }}:role/{{ iam_role_name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- block: | ||
- import_tasks: setup.yml | ||
- import_tasks: tests.yml | ||
module_defaults: | ||
group/mattclay.aws.common: | ||
access_key: "{{ aws_access_key }}" | ||
secret_key: "{{ aws_secret_key }}" | ||
aws_region: "{{ aws_region }}" | ||
security_token: "{{ security_token }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
- name: Create a role | ||
community.aws.iam_role: | ||
name: "{{ iam_role_name }}" | ||
assume_role_policy_document: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Action: sts:AssumeRole | ||
Effect: Allow | ||
Principal: | ||
Service: lambda.amazonaws.com | ||
managed_policies: | ||
- arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole | ||
|
||
- name: Wait for role to be usable | ||
pause: | ||
seconds: 10 | ||
|
||
- name: Gather account facts | ||
aws_account_facts: | ||
|
||
- name: Create a Lambda function | ||
lambda: | ||
name: "{{ function_name }}" | ||
code: "# no actual code" | ||
runtime: python3.8 | ||
timeout: 60 | ||
handler: lambda_function.lambda_handler | ||
memory_size: 128 | ||
role: "{{ iam_role_arn }}" | ||
publish: yes | ||
qualifier: "test" | ||
register: lambda_function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
- name: Create the Lambda function alias (check) | ||
lambda_alias: | ||
name: "test" | ||
description: "test alias" | ||
function_name: "{{ lambda_function.meta.function_name }}" | ||
version: "{{ lambda_function.meta.version }}" | ||
check_mode: yes | ||
register: create_check | ||
|
||
- name: Create the Lambda function alias (changed) | ||
lambda_alias: | ||
name: "test" | ||
description: "test alias" | ||
function_name: "{{ lambda_function.meta.function_name }}" | ||
version: "{{ lambda_function.meta.version }}" | ||
register: create_changed | ||
|
||
- name: Create the Lambda function alias (unchanged) | ||
lambda_alias: | ||
name: "test" | ||
description: "test alias" | ||
function_name: "{{ lambda_function.meta.function_name }}" | ||
version: "{{ lambda_function.meta.version }}" | ||
register: create_unchanged | ||
|
||
- name: Update the Lambda function alias (check) | ||
lambda_alias: | ||
name: "test" | ||
description: "updated alias" | ||
function_name: "{{ lambda_function.meta.function_name }}" | ||
version: "{{ lambda_function.meta.version }}" | ||
check_mode: yes | ||
register: update_check | ||
|
||
- name: Update the Lambda function alias (changed) | ||
lambda_alias: | ||
name: "test" | ||
description: "updated alias" | ||
function_name: "{{ lambda_function.meta.function_name }}" | ||
version: "{{ lambda_function.meta.version }}" | ||
register: update_changed | ||
|
||
- name: Update the Lambda function alias (unchanged) | ||
lambda_alias: | ||
name: "test" | ||
description: "updated alias" | ||
function_name: "{{ lambda_function.meta.function_name }}" | ||
version: "{{ lambda_function.meta.version }}" | ||
register: update_unchanged | ||
|
||
- name: Check results | ||
assert: | ||
that: | ||
- create_check is changed | ||
- create_changed is changed | ||
- create_unchanged is not changed | ||
- update_check is changed | ||
- update_changed is changed | ||
- update_unchanged is not changed |