ansible/test/integration/targets/aws_api_gateway/tasks/main.yml
Stefan Horning 652346ad5d
Allow passing through of (almost) all params available … (#58118)
* Allow passing through of (almost) all params available on boto methods in aws_api_gateway

* Linting and docs fixes

* Refactored method signature of create_deployment() to use keyword args instead of named args

* Updated version_added flags to 2.10

* Cleanup and improve aws_api__gateway integration test play. Also included new params into test.

* Fixed RETURN docs and some ttests

* Completed RETURN docs and made integration tests match

* Fixed variable names in test and YAML syntax in docs

* Comment out critical sections of integration test

* Fixed update test after figuring out what the error message means. Also updated error message to be more descriptive.

* Fixed test assertion

* Update docs and make tests reflect that endpoint type wont be changed on updates

* Syntax fix

* Add changelog fragment

* Improve aws_api_gateway docs, fix typos.

* Quote doc lines with colon
2020-02-27 10:44:20 -07:00

207 lines
6.7 KiB
YAML

- block:
# ====================== testing failure cases: ==================================
- name: test with no parameters
aws_api_gateway:
register: result
ignore_errors: true
- name: assert failure when called with no parameters
assert:
that:
- 'result.failed'
- 'result.msg.startswith("The aws_api_gateway module requires a region")'
- name: test with minimal parameters but no region
aws_api_gateway:
api_id: 'fake-api-doesnt-exist'
register: result
ignore_errors: true
- name: assert failure when called with with minimal parameters but no region
assert:
that:
- 'result.failed'
- 'result.msg.startswith("The aws_api_gateway module requires a region")'
- name: test for disallowing multiple swagger sources
aws_api_gateway:
api_id: 'fake-api-doesnt-exist'
region: '{{ec2_region}}'
swagger_file: foo.yml
swagger_text: "this is not really an API"
register: result
ignore_errors: true
- name: assert failure when called with with minimal parameters but no region
assert:
that:
- 'result.failed'
- 'result.msg.startswith("parameters are mutually exclusive")'
# ====================== regular testing: ===================================
- name: build API file
template:
src: minimal-swagger-api.yml.j2
dest: "{{output_dir}}/minimal-swagger-api.yml"
- name: deploy new API
aws_api_gateway:
api_file: "{{output_dir}}/minimal-swagger-api.yml"
stage: "minimal"
endpoint_type: 'REGIONAL'
state: present
region: '{{ec2_region}}'
aws_access_key: '{{ec2_access_key}}'
aws_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: create_result
- name: assert deploy new API worked
assert:
that:
- 'create_result.changed == True'
- 'create_result.failed == False'
- 'create_result.deploy_response.description == "Automatic deployment by Ansible."'
- 'create_result.configure_response.id == create_result.api_id'
- '"apigateway:CreateRestApi" in create_result.resource_actions'
- 'create_result.configure_response.endpoint_configuration.types.0 == "REGIONAL"'
- name: check if API endpoint works
uri: url="https://{{create_result.api_id}}.execute-api.{{ec2_region}}.amazonaws.com/minimal"
register: uri_result
- name: assert API works success
assert:
that:
- 'uri_result.status == 200'
- name: check if nonexistent endpoint causes error
uri: url="https://{{create_result.api_id}}.execute-api.{{ec2_region}}.amazonaws.com/nominal"
register: bad_uri_result
ignore_errors: true
- name: assert
assert:
that:
- bad_uri_result is failed
- name: Update API to test params effect
aws_api_gateway:
api_id: '{{create_result.api_id}}'
api_file: "{{output_dir}}/minimal-swagger-api.yml"
cache_enabled: true
cache_size: '1.6'
tracing_enabled: true
state: present
region: '{{ec2_region}}'
aws_access_key: '{{ec2_access_key}}'
aws_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: update_result
- name: assert update result
assert:
that:
- 'update_result.changed == True'
- 'update_result.failed == False'
- '"apigateway:PutRestApi" in update_result.resource_actions'
# ==== additional create/delete tests ====
- name: deploy first API
aws_api_gateway:
api_file: "{{output_dir}}/minimal-swagger-api.yml"
stage: "minimal"
cache_enabled: false
state: present
region: '{{ec2_region}}'
aws_access_key: '{{ec2_access_key}}'
aws_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: create_result_1
- name: deploy second API rapidly after first
aws_api_gateway:
api_file: "{{output_dir}}/minimal-swagger-api.yml"
stage: "minimal"
state: present
region: '{{ec2_region}}'
aws_access_key: '{{ec2_access_key}}'
aws_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: create_result_2
- name: assert both APIs deployed successfully
assert:
that:
- 'create_result_1.changed == True'
- 'create_result_2.changed == True'
- '"api_id" in create_result_1'
- '"api_id" in create_result_1'
- 'create_result_1.configure_response.endpoint_configuration.types.0 == "EDGE"'
- name: destroy first API
aws_api_gateway:
state: absent
api_id: '{{create_result_1.api_id}}'
region: '{{ec2_region}}'
aws_access_key: '{{ec2_access_key}}'
aws_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: destroy_result_1
- name: destroy second API rapidly after first
aws_api_gateway:
state: absent
api_id: '{{create_result_2.api_id}}'
region: '{{ec2_region}}'
aws_access_key: '{{ec2_access_key}}'
aws_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: destroy_result_2
- name: assert both APIs deployed successfully
assert:
that:
- 'destroy_result_1.changed == True'
- 'destroy_result_2.changed == True'
- '"apigateway:DeleteRestApi" in destroy_result_1.resource_actions'
- '"apigateway:DeleteRestApi" in destroy_result_2.resource_actions'
# ================= end testing ====================================
always:
- name: Ensure cleanup of API deploy
aws_api_gateway:
state: absent
api_id: '{{create_result.api_id}}'
ec2_region: '{{ec2_region}}'
aws_access_key: '{{ec2_access_key}}'
aws_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
ignore_errors: true
- name: Ensure cleanup of API deploy 1
aws_api_gateway:
state: absent
api_id: '{{create_result_1.api_id}}'
ec2_region: '{{ec2_region}}'
aws_access_key: '{{ec2_access_key}}'
aws_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
ignore_errors: true
- name: Ensure cleanup of API deploy 2
aws_api_gateway:
state: absent
api_id: '{{create_result_2.api_id}}'
ec2_region: '{{ec2_region}}'
aws_access_key: '{{ec2_access_key}}'
aws_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
ignore_errors: true