Bug fixes for GCP modules (as of 2019-01-09T15:35:45-08:00) (#50786)

This commit is contained in:
Alex Stephen 2019-01-16 09:58:57 -08:00 committed by ansibot
parent a7e81ba500
commit 5137bd5958
18 changed files with 142 additions and 119 deletions

View file

@ -67,7 +67,7 @@ items:
description: description:
- A reference to a Topic resource. - A reference to a Topic resource.
returned: success returned: success
type: dict type: str
pushConfig: pushConfig:
description: description:
- If push delivery is used with this subscription, this field is used to configure - If push delivery is used with this subscription, this field is used to configure

View file

@ -65,10 +65,9 @@ options:
description: description:
- The instance to create the database on. - The instance to create the database on.
- 'This field represents a link to a Instance resource in GCP. It can be specified - 'This field represents a link to a Instance resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_spanner_instance in two ways. First, you can place in the name of the resource here as a string
task and then set this instance field to "{{ name-of-resource }}" Alternatively, Alternatively, you can add `register: name-of-resource` to a gcp_spanner_instance
you can set this instance to a dictionary with the name key where the value task and then set this instance field to "{{ name-of-resource }}"'
is the name of your Instance'
required: true required: true
extends_documentation_fragment: gcp extends_documentation_fragment: gcp
''' '''
@ -118,7 +117,7 @@ instance:
description: description:
- The instance to create the database on. - The instance to create the database on.
returned: success returned: success
type: dict type: str
''' '''
################################################################################ ################################################################################
@ -141,7 +140,7 @@ def main():
state=dict(default='present', choices=['present', 'absent'], type='str'), state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str'), name=dict(type='str'),
extra_statements=dict(type='list', elements='str'), extra_statements=dict(type='list', elements='str'),
instance=dict(required=True, type='dict') instance=dict(required=True)
) )
) )

View file

@ -45,10 +45,9 @@ options:
description: description:
- The instance to create the database on. - The instance to create the database on.
- 'This field represents a link to a Instance resource in GCP. It can be specified - 'This field represents a link to a Instance resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_spanner_instance in two ways. First, you can place in the name of the resource here as a string
task and then set this instance field to "{{ name-of-resource }}" Alternatively, Alternatively, you can add `register: name-of-resource` to a gcp_spanner_instance
you can set this instance to a dictionary with the name key where the value task and then set this instance field to "{{ name-of-resource }}"'
is the name of your Instance'
required: true required: true
extends_documentation_fragment: gcp extends_documentation_fragment: gcp
''' '''
@ -87,7 +86,7 @@ items:
description: description:
- The instance to create the database on. - The instance to create the database on.
returned: success returned: success
type: dict type: str
''' '''
################################################################################ ################################################################################
@ -104,7 +103,7 @@ import json
def main(): def main():
module = GcpModule( module = GcpModule(
argument_spec=dict( argument_spec=dict(
instance=dict(required=True, type='dict') instance=dict(required=True)
) )
) )

View file

@ -65,10 +65,9 @@ options:
description: description:
- The name of the Cloud SQL instance. This does not include the project ID. - The name of the Cloud SQL instance. This does not include the project ID.
- 'This field represents a link to a Instance resource in GCP. It can be specified - 'This field represents a link to a Instance resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_sql_instance in two ways. First, you can place in the name of the resource here as a string
task and then set this instance field to "{{ name-of-resource }}" Alternatively, Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance
you can set this instance to a dictionary with the name key where the value task and then set this instance field to "{{ name-of-resource }}"'
is the name of your Instance'
required: true required: true
extends_documentation_fragment: gcp extends_documentation_fragment: gcp
''' '''
@ -76,7 +75,7 @@ extends_documentation_fragment: gcp
EXAMPLES = ''' EXAMPLES = '''
- name: create a instance - name: create a instance
gcp_sql_instance: gcp_sql_instance:
name: "instance-database" name: "{{resource_name}}-3"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -122,7 +121,7 @@ instance:
description: description:
- The name of the Cloud SQL instance. This does not include the project ID. - The name of the Cloud SQL instance. This does not include the project ID.
returned: success returned: success
type: dict type: str
''' '''
################################################################################ ################################################################################
@ -147,7 +146,7 @@ def main():
charset=dict(type='str'), charset=dict(type='str'),
collation=dict(type='str'), collation=dict(type='str'),
name=dict(type='str'), name=dict(type='str'),
instance=dict(required=True, type='dict') instance=dict(required=True)
) )
) )

View file

@ -45,10 +45,9 @@ options:
description: description:
- The name of the Cloud SQL instance. This does not include the project ID. - The name of the Cloud SQL instance. This does not include the project ID.
- 'This field represents a link to a Instance resource in GCP. It can be specified - 'This field represents a link to a Instance resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_sql_instance in two ways. First, you can place in the name of the resource here as a string
task and then set this instance field to "{{ name-of-resource }}" Alternatively, Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance
you can set this instance to a dictionary with the name key where the value task and then set this instance field to "{{ name-of-resource }}"'
is the name of your Instance'
required: true required: true
extends_documentation_fragment: gcp extends_documentation_fragment: gcp
''' '''
@ -88,7 +87,7 @@ items:
description: description:
- The name of the Cloud SQL instance. This does not include the project ID. - The name of the Cloud SQL instance. This does not include the project ID.
returned: success returned: success
type: dict type: str
''' '''
################################################################################ ################################################################################
@ -105,7 +104,7 @@ import json
def main(): def main():
module = GcpModule( module = GcpModule(
argument_spec=dict( argument_spec=dict(
instance=dict(required=True, type='dict') instance=dict(required=True)
) )
) )

View file

@ -87,7 +87,7 @@ options:
description: description:
- The availability status of the failover replica. A false status indicates - The availability status of the failover replica. A false status indicates
that the failover replica is out of sync. The master can only failover to that the failover replica is out of sync. The master can only failover to
the falover replica when the status is true. the failover replica when the status is true.
required: false required: false
type: bool type: bool
name: name:
@ -163,8 +163,8 @@ options:
required: false required: false
client_key: client_key:
description: description:
- PEM representation of the slave's private key. The corresponsing public - PEM representation of the slave's private key. The corresponding public
key is encoded in the client's asf asd certificate. key is encoded in the client's certificate.
required: false required: false
connect_retry_interval: connect_retry_interval:
description: description:
@ -273,7 +273,7 @@ extends_documentation_fragment: gcp
EXAMPLES = ''' EXAMPLES = '''
- name: create a instance - name: create a instance
gcp_sql_instance: gcp_sql_instance:
name: "test_object" name: "{{resource_name}}-2"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -320,7 +320,7 @@ failoverReplica:
description: description:
- The availability status of the failover replica. A false status indicates - The availability status of the failover replica. A false status indicates
that the failover replica is out of sync. The master can only failover to that the failover replica is out of sync. The master can only failover to
the falover replica when the status is true. the failover replica when the status is true.
returned: success returned: success
type: bool type: bool
name: name:
@ -427,8 +427,8 @@ replicaConfiguration:
type: str type: str
clientKey: clientKey:
description: description:
- PEM representation of the slave's private key. The corresponsing public - PEM representation of the slave's private key. The corresponding public
key is encoded in the client's asf asd certificate. key is encoded in the client's certificate.
returned: success returned: success
type: str type: str
connectRetryInterval: connectRetryInterval:

View file

@ -90,7 +90,7 @@ items:
description: description:
- The availability status of the failover replica. A false status indicates - The availability status of the failover replica. A false status indicates
that the failover replica is out of sync. The master can only failover that the failover replica is out of sync. The master can only failover
to the falover replica when the status is true. to the failover replica when the status is true.
returned: success returned: success
type: bool type: bool
name: name:
@ -200,8 +200,8 @@ items:
type: str type: str
clientKey: clientKey:
description: description:
- PEM representation of the slave's private key. The corresponsing public - PEM representation of the slave's private key. The corresponding public
key is encoded in the client's asf asd certificate. key is encoded in the client's certificate.
returned: success returned: success
type: str type: str
connectRetryInterval: connectRetryInterval:

View file

@ -62,10 +62,9 @@ options:
description: description:
- The name of the Cloud SQL instance. This does not include the project ID. - The name of the Cloud SQL instance. This does not include the project ID.
- 'This field represents a link to a Instance resource in GCP. It can be specified - 'This field represents a link to a Instance resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_sql_instance in two ways. First, you can place in the name of the resource here as a string
task and then set this instance field to "{{ name-of-resource }}" Alternatively, Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance
you can set this instance to a dictionary with the name key where the value task and then set this instance field to "{{ name-of-resource }}"'
is the name of your Instance'
required: true required: true
password: password:
description: description:
@ -77,7 +76,7 @@ extends_documentation_fragment: gcp
EXAMPLES = ''' EXAMPLES = '''
- name: create a instance - name: create a instance
gcp_sql_instance: gcp_sql_instance:
name: "instance-user" name: "{{resource_name}}-1"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -120,7 +119,7 @@ instance:
description: description:
- The name of the Cloud SQL instance. This does not include the project ID. - The name of the Cloud SQL instance. This does not include the project ID.
returned: success returned: success
type: dict type: str
password: password:
description: description:
- The password for the user. - The password for the user.
@ -149,7 +148,7 @@ def main():
state=dict(default='present', choices=['present', 'absent'], type='str'), state=dict(default='present', choices=['present', 'absent'], type='str'),
host=dict(required=True, type='str'), host=dict(required=True, type='str'),
name=dict(required=True, type='str'), name=dict(required=True, type='str'),
instance=dict(required=True, type='dict'), instance=dict(required=True),
password=dict(type='str') password=dict(type='str')
) )
) )

View file

@ -45,10 +45,9 @@ options:
description: description:
- The name of the Cloud SQL instance. This does not include the project ID. - The name of the Cloud SQL instance. This does not include the project ID.
- 'This field represents a link to a Instance resource in GCP. It can be specified - 'This field represents a link to a Instance resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_sql_instance in two ways. First, you can place in the name of the resource here as a string
task and then set this instance field to "{{ name-of-resource }}" Alternatively, Alternatively, you can add `register: name-of-resource` to a gcp_sql_instance
you can set this instance to a dictionary with the name key where the value task and then set this instance field to "{{ name-of-resource }}"'
is the name of your Instance'
required: true required: true
extends_documentation_fragment: gcp extends_documentation_fragment: gcp
''' '''
@ -84,7 +83,7 @@ items:
description: description:
- The name of the Cloud SQL instance. This does not include the project ID. - The name of the Cloud SQL instance. This does not include the project ID.
returned: success returned: success
type: dict type: str
password: password:
description: description:
- The password for the user. - The password for the user.
@ -106,7 +105,7 @@ import json
def main(): def main():
module = GcpModule( module = GcpModule(
argument_spec=dict( argument_spec=dict(
instance=dict(required=True, type='dict') instance=dict(required=True)
) )
) )

View file

@ -62,10 +62,9 @@ options:
description: description:
- The name of the bucket. - The name of the bucket.
- 'This field represents a link to a Bucket resource in GCP. It can be specified - 'This field represents a link to a Bucket resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_storage_bucket in two ways. First, you can place in the name of the resource here as a
task and then set this bucket field to "{{ name-of-resource }}" Alternatively, string Alternatively, you can add `register: name-of-resource` to a gcp_storage_bucket
you can set this bucket to a dictionary with the name key where the value task and then set this bucket field to "{{ name-of-resource }}"'
is the name of your Bucket'
required: true required: true
domain: domain:
description: description:
@ -154,10 +153,9 @@ options:
description: description:
- The name of the bucket. - The name of the bucket.
- 'This field represents a link to a Bucket resource in GCP. It can be specified - 'This field represents a link to a Bucket resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_storage_bucket in two ways. First, you can place in the name of the resource here as a
task and then set this bucket field to "{{ name-of-resource }}" Alternatively, string Alternatively, you can add `register: name-of-resource` to a gcp_storage_bucket
you can set this bucket to a dictionary with the name key where the value task and then set this bucket field to "{{ name-of-resource }}"'
is the name of your Bucket'
required: true required: true
domain: domain:
description: description:
@ -415,7 +413,7 @@ acl:
description: description:
- The name of the bucket. - The name of the bucket.
returned: success returned: success
type: dict type: str
domain: domain:
description: description:
- The domain associated with the entity. - The domain associated with the entity.
@ -509,7 +507,7 @@ defaultObjectAcl:
description: description:
- The name of the bucket. - The name of the bucket.
returned: success returned: success
type: dict type: str
domain: domain:
description: description:
- The domain associated with the entity. - The domain associated with the entity.
@ -793,7 +791,7 @@ def main():
argument_spec=dict( argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'), state=dict(default='present', choices=['present', 'absent'], type='str'),
acl=dict(type='list', elements='dict', options=dict( acl=dict(type='list', elements='dict', options=dict(
bucket=dict(required=True, type='dict'), bucket=dict(required=True),
domain=dict(type='str'), domain=dict(type='str'),
email=dict(type='str'), email=dict(type='str'),
entity=dict(required=True, type='str'), entity=dict(required=True, type='str'),
@ -812,7 +810,7 @@ def main():
response_header=dict(type='list', elements='str') response_header=dict(type='list', elements='str')
)), )),
default_object_acl=dict(type='list', elements='dict', options=dict( default_object_acl=dict(type='list', elements='dict', options=dict(
bucket=dict(required=True, type='dict'), bucket=dict(required=True),
domain=dict(type='str'), domain=dict(type='str'),
email=dict(type='str'), email=dict(type='str'),
entity=dict(required=True, type='str'), entity=dict(required=True, type='str'),

View file

@ -61,10 +61,9 @@ options:
description: description:
- The name of the bucket. - The name of the bucket.
- 'This field represents a link to a Bucket resource in GCP. It can be specified - 'This field represents a link to a Bucket resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_storage_bucket in two ways. First, you can place in the name of the resource here as a string
task and then set this bucket field to "{{ name-of-resource }}" Alternatively, Alternatively, you can add `register: name-of-resource` to a gcp_storage_bucket
you can set this bucket to a dictionary with the name key where the value is task and then set this bucket field to "{{ name-of-resource }}"'
the name of your Bucket'
required: true required: true
entity: entity:
description: description:
@ -110,7 +109,7 @@ extends_documentation_fragment: gcp
EXAMPLES = ''' EXAMPLES = '''
- name: create a bucket - name: create a bucket
gcp_storage_bucket: gcp_storage_bucket:
name: "bucket-bac" name: "{{ resource_name }}"
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
@ -133,7 +132,7 @@ bucket:
description: description:
- The name of the bucket. - The name of the bucket.
returned: success returned: success
type: dict type: str
domain: domain:
description: description:
- The domain associated with the entity. - The domain associated with the entity.
@ -205,7 +204,7 @@ def main():
module = GcpModule( module = GcpModule(
argument_spec=dict( argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'), state=dict(default='present', choices=['present', 'absent'], type='str'),
bucket=dict(required=True, type='dict'), bucket=dict(required=True),
entity=dict(required=True, type='str'), entity=dict(required=True, type='str'),
entity_id=dict(type='str'), entity_id=dict(type='str'),
project_team=dict(type='dict', options=dict( project_team=dict(type='dict', options=dict(

View file

@ -44,7 +44,7 @@
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results['items'] | length == 1 - "'test-topic1' in \"{{ results['items'] | map(attribute='name') | list }}\""
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: create a topic that already exists - name: create a topic that already exists
gcp_pubsub_topic: gcp_pubsub_topic:
@ -82,7 +82,7 @@
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results['items'] | length == 0 - "'test-topic1' not in \"{{ results['items'] | map(attribute='name') | list }}\""
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a topic that does not exist - name: delete a topic that does not exist
gcp_pubsub_topic: gcp_pubsub_topic:

View file

@ -49,13 +49,18 @@
that: that:
- result.changed == true - result.changed == true
- name: verify that database was created - name: verify that database was created
shell: | gcp_spanner_database_facts:
gcloud spanner databases describe --project="{{ gcp_project }}" --instance="{{ instance.name }}" "webstore" instance: "{{ instance }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/spanner.admin
register: results register: results
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 0 - "'webstore' in \"{{ results['items'] | map(attribute='name') | list }}\""
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: create a database that already exists - name: create a database that already exists
gcp_spanner_database: gcp_spanner_database:
@ -85,15 +90,18 @@
that: that:
- result.changed == true - result.changed == true
- name: verify that database was deleted - name: verify that database was deleted
shell: | gcp_spanner_database_facts:
gcloud spanner databases describe --project="{{ gcp_project }}" --instance="{{ instance.name }}" "webstore" instance: "{{ instance }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/spanner.admin
register: results register: results
failed_when: results.rc == 0
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 1 - "'webstore' not in \"{{ results['items'] | map(attribute='name') | list }}\""
- "\"Database not found: projects/{{ gcp_project }}/instances/instance-database/databases/webstore\" in results.stderr"
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a database that does not exist - name: delete a database that does not exist
gcp_spanner_database: gcp_spanner_database:
@ -110,6 +118,7 @@
- result.changed == false - result.changed == false
#--------------------------------------------------------- #---------------------------------------------------------
# Post-test teardown # Post-test teardown
# If errors happen, don't crash the playbook!
- name: delete a instance - name: delete a instance
gcp_spanner_instance: gcp_spanner_instance:
name: "instance-database" name: "instance-database"
@ -123,3 +132,4 @@
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
state: absent state: absent
register: instance register: instance
ignore_errors: true

View file

@ -44,13 +44,17 @@
that: that:
- result.changed == true - result.changed == true
- name: verify that instance was created - name: verify that instance was created
shell: | gcp_spanner_instance_facts:
gcloud spanner instances describe --project="{{ gcp_project }}" "{{ resource_name }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/spanner.admin
register: results register: results
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 0 - "\"{{resource_name}}\" in \"{{ results['items'] | map(attribute='name') | list }}\""
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: create a instance that already exists - name: create a instance that already exists
gcp_spanner_instance: gcp_spanner_instance:
@ -88,15 +92,17 @@
that: that:
- result.changed == true - result.changed == true
- name: verify that instance was deleted - name: verify that instance was deleted
shell: | gcp_spanner_instance_facts:
gcloud spanner instances describe --project="{{ gcp_project }}" "{{ resource_name }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/spanner.admin
register: results register: results
failed_when: results.rc == 0
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 1 - "\"{{resource_name}}\" not in \"{{ results['items'] | map(attribute='name') | list }}\""
- "\"Instance not found: projects/{{ gcp_project }}/instances/{{ resource_name }}\" in results.stderr"
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a instance that does not exist - name: delete a instance that does not exist
gcp_spanner_instance: gcp_spanner_instance:

View file

@ -15,7 +15,7 @@
# Pre-test setup # Pre-test setup
- name: create a instance - name: create a instance
gcp_sql_instance: gcp_sql_instance:
name: "instance-database" name: "{{resource_name}}-3"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -54,13 +54,18 @@
- result.changed == true - result.changed == true
- "result.kind == 'sql#database'" - "result.kind == 'sql#database'"
- name: verify that database was created - name: verify that database was created
shell: | gcp_sql_database_facts:
gcloud sql databases describe --instance='instance-database' --project="{{ gcp_project}}" "{{ resource_name }}" instance: "{{ instance }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/sqlservice.admin
register: results register: results
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 0 - "\"{{resource_name}}\" in \"{{ results['items'] | map(attribute='name') | list }}\""
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: create a database that already exists - name: create a database that already exists
gcp_sql_database: gcp_sql_database:
@ -94,15 +99,18 @@
- result.changed == true - result.changed == true
- result.has_key('kind') == False - result.has_key('kind') == False
- name: verify that database was deleted - name: verify that database was deleted
shell: | gcp_sql_database_facts:
gcloud sql databases describe --instance='instance-database' --project="{{ gcp_project}}" "{{ resource_name }}" instance: "{{ instance }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/sqlservice.admin
register: results register: results
failed_when: results.rc == 0
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 1 - "\"{{resource_name}}\" not in \"{{ results['items'] | map(attribute='name') | list }}\""
- "\"(gcloud.sql.databases.describe) HTTPError 404: Not Found\" in results.stderr"
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a database that does not exist - name: delete a database that does not exist
gcp_sql_database: gcp_sql_database:
@ -121,9 +129,10 @@
- result.has_key('kind') == False - result.has_key('kind') == False
#--------------------------------------------------------- #---------------------------------------------------------
# Post-test teardown # Post-test teardown
# If errors happen, don't crash the playbook!
- name: delete a instance - name: delete a instance
gcp_sql_instance: gcp_sql_instance:
name: "instance-database" name: "{{resource_name}}-3"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -136,3 +145,4 @@
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
state: absent state: absent
register: instance register: instance
ignore_errors: true

View file

@ -15,7 +15,7 @@
# Pre-test setup # Pre-test setup
- name: delete a instance - name: delete a instance
gcp_sql_instance: gcp_sql_instance:
name: "{{ resource_name }}" name: "{{resource_name}}-2"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -30,7 +30,7 @@
#---------------------------------------------------------- #----------------------------------------------------------
- name: create a instance - name: create a instance
gcp_sql_instance: gcp_sql_instance:
name: "{{ resource_name }}" name: "{{resource_name}}-2"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -49,17 +49,21 @@
- result.changed == true - result.changed == true
- "result.kind == 'sql#instance'" - "result.kind == 'sql#instance'"
- name: verify that instance was created - name: verify that instance was created
shell: | gcp_sql_instance_facts:
gcloud sql instances describe --project="{{ gcp_project}}" "{{ resource_name }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/sqlservice.admin
register: results register: results
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 0 - results['items'] | length >= 1
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: create a instance that already exists - name: create a instance that already exists
gcp_sql_instance: gcp_sql_instance:
name: "{{ resource_name }}" name: "{{resource_name}}-2"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -80,7 +84,7 @@
#---------------------------------------------------------- #----------------------------------------------------------
- name: delete a instance - name: delete a instance
gcp_sql_instance: gcp_sql_instance:
name: "{{ resource_name }}" name: "{{resource_name}}-2"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -99,19 +103,21 @@
- result.changed == true - result.changed == true
- result.has_key('kind') == False - result.has_key('kind') == False
- name: verify that instance was deleted - name: verify that instance was deleted
shell: | gcp_sql_instance_facts:
gcloud sql instances describe --project="{{ gcp_project}}" "{{ resource_name }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/sqlservice.admin
register: results register: results
failed_when: results.rc == 0
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results.rc == 1 - results['items'] | length == 0
- "\"Cloud SQL instance does not exist\" in results.stderr"
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a instance that does not exist - name: delete a instance that does not exist
gcp_sql_instance: gcp_sql_instance:
name: "{{ resource_name }}" name: "{{resource_name}}-2"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:

View file

@ -15,7 +15,7 @@
# Pre-test setup # Pre-test setup
- name: create a instance - name: create a instance
gcp_sql_instance: gcp_sql_instance:
name: "instance-user" name: "{{resource_name}}-1"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -57,8 +57,6 @@
- "result.kind == 'sql#user'" - "result.kind == 'sql#user'"
- name: verify that user was created - name: verify that user was created
gcp_sql_user_facts: gcp_sql_user_facts:
filters:
- name = test-user
instance: "{{ instance }}" instance: "{{ instance }}"
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
@ -69,7 +67,7 @@
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results['items'] | length == 1 - "'test-user' in \"{{ results['items'] | map(attribute='name') | list }}\""
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: create a user that already exists - name: create a user that already exists
gcp_sql_user: gcp_sql_user:
@ -106,8 +104,6 @@
- result.has_key('kind') == False - result.has_key('kind') == False
- name: verify that user was deleted - name: verify that user was deleted
gcp_sql_user_facts: gcp_sql_user_facts:
filters:
- name = test-user
instance: "{{ instance }}" instance: "{{ instance }}"
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
@ -118,7 +114,7 @@
- name: verify that command succeeded - name: verify that command succeeded
assert: assert:
that: that:
- results['items'] | length == 0 - "'test-user' not in \"{{ results['items'] | map(attribute='name') | list }}\""
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a user that does not exist - name: delete a user that does not exist
gcp_sql_user: gcp_sql_user:
@ -138,9 +134,10 @@
- result.has_key('kind') == False - result.has_key('kind') == False
#--------------------------------------------------------- #---------------------------------------------------------
# Post-test teardown # Post-test teardown
# If errors happen, don't crash the playbook!
- name: delete a instance - name: delete a instance
gcp_sql_instance: gcp_sql_instance:
name: "instance-user" name: "{{resource_name}}-1"
settings: settings:
ip_configuration: ip_configuration:
authorized_networks: authorized_networks:
@ -153,3 +150,4 @@
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
state: absent state: absent
register: instance register: instance
ignore_errors: true

View file

@ -15,7 +15,7 @@
# Pre-test setup # Pre-test setup
- name: create a bucket - name: create a bucket
gcp_storage_bucket: gcp_storage_bucket:
name: "bucket-bac" name: "{{ resource_name }}"
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
@ -96,11 +96,13 @@
- result.has_key('kind') == False - result.has_key('kind') == False
#--------------------------------------------------------- #---------------------------------------------------------
# Post-test teardown # Post-test teardown
# If errors happen, don't crash the playbook!
- name: delete a bucket - name: delete a bucket
gcp_storage_bucket: gcp_storage_bucket:
name: "bucket-bac" name: "{{ resource_name }}"
project: "{{ gcp_project }}" project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}" auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}" service_account_file: "{{ gcp_cred_file }}"
state: absent state: absent
register: bucket register: bucket
ignore_errors: true