fixing gcp_resourcemanager_project delete

gcp_resourcemanager_project was not properly deleting projects.

fixing gcp_resourcemanager_project as well.

fixes #530.
This commit is contained in:
Yusuke Tsutsumi 2022-12-13 06:17:00 +00:00 committed by Yusuke Tsutsumi
commit d063d44b73
6 changed files with 64 additions and 30 deletions

View file

@ -203,6 +203,8 @@ id:
type: str
'''
ACTIVE = "ACTIVE"
################################################################################
# Imports
################################################################################
@ -250,7 +252,7 @@ def main():
update(module, self_link(module))
fetch = fetch_resource(module, self_link(module))
changed = True
else:
elif fetch.get("lifecycleState") == ACTIVE:
delete(module, self_link(module))
fetch = {}
changed = True
@ -375,7 +377,7 @@ def async_op_url(module, extra_data=None):
def wait_for_operation(module, response):
op_result = return_if_object(module, response)
if op_result is None:
if not op_result:
return {}
status = navigate_hash(op_result, ['done'])
wait_done = wait_for_completion(status, op_result, module)

View file

@ -77,6 +77,11 @@ options:
- This should not be set unless you know what you're doing.
- This only alters the User Agent string for any API requests.
type: str
page_size:
description:
- Indicates the number of projects that should be returned by the API
request
type: str
notes:
- for authentication, you can set service_account_file using the C(GCP_SERVICE_ACCOUNT_FILE)
env variable.
@ -96,6 +101,7 @@ EXAMPLES = '''
project: test_project
auth_kind: serviceaccount
service_account_file: "/tmp/auth.pem"
page_size: 100
'''
RETURN = '''
@ -175,7 +181,9 @@ import json
def main():
module = GcpModule(argument_spec=dict())
module = GcpModule(argument_spec=dict(
page_size=dict(type='int')
))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
@ -190,7 +198,10 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'resourcemanager')
return auth.list(link, return_if_object, array_name='projects')
params = {}
if "page_size" in module.params:
params["pageSize"] = module.params.get("page_size")
return auth.list(link, return_if_object, array_name='projects', params=params)
def return_if_object(module, response):