From ef3607f1e7502badc95eb61e8c4f84878436f4ba Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 29 Apr 2019 12:50:30 -0700 Subject: [PATCH] Bug fixes for GCP modules (#55361) --- .../cloud/google/gcp_container_cluster_facts.py | 1 + .../modules/cloud/google/gcp_iam_service_account.py | 2 +- lib/ansible/modules/cloud/google/gcp_pubsub_topic.py | 3 ++- .../modules/cloud/google/gcp_sourcerepo_repository.py | 3 ++- .../targets/gcp_container_cluster/defaults/main.yml | 3 +-- .../targets/gcp_container_node_pool/defaults/main.yml | 3 +-- .../targets/gcp_dns_managed_zone/defaults/main.yml | 3 +-- .../gcp_dns_resource_record_set/defaults/main.yml | 3 +-- .../integration/targets/gcp_iam_role/defaults/main.yml | 3 +-- .../targets/gcp_iam_service_account/defaults/main.yml | 4 ++-- .../targets/gcp_iam_service_account/tasks/main.yml | 10 +++++----- .../targets/gcp_pubsub_subscription/defaults/main.yml | 3 +-- .../targets/gcp_pubsub_topic/defaults/main.yml | 3 +-- .../targets/gcp_redis_instance/defaults/main.yml | 3 +-- .../gcp_resourcemanager_project/defaults/main.yml | 3 +-- .../gcp_sourcerepo_repository/defaults/main.yml | 3 +-- 16 files changed, 23 insertions(+), 30 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gcp_container_cluster_facts.py b/lib/ansible/modules/cloud/google/gcp_container_cluster_facts.py index ea1f91bc675..a19f87428cc 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_cluster_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_container_cluster_facts.py @@ -58,6 +58,7 @@ EXAMPLES = ''' project: test_project auth_kind: serviceaccount service_account_file: "/tmp/auth.pem" + state: facts ''' RETURN = ''' diff --git a/lib/ansible/modules/cloud/google/gcp_iam_service_account.py b/lib/ansible/modules/cloud/google/gcp_iam_service_account.py index 041171994b8..47a0587f2f5 100644 --- a/lib/ansible/modules/cloud/google/gcp_iam_service_account.py +++ b/lib/ansible/modules/cloud/google/gcp_iam_service_account.py @@ -61,7 +61,7 @@ extends_documentation_fragment: gcp EXAMPLES = ''' - name: create a service account gcp_iam_service_account: - name: '"{{resource_name}}@{{gcp_project}}.google.com.iam.gserviceaccount.com"' + name: "{{ sa_name }}" display_name: My Ansible test key project: test_project auth_kind: serviceaccount diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_topic.py b/lib/ansible/modules/cloud/google/gcp_pubsub_topic.py index 5982ed0a79c..728fc60080f 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_topic.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_topic.py @@ -142,7 +142,8 @@ def create(module, link): def update(module, link): - module.fail_json(msg="Topic cannot be edited") + delete(module, self_link(module)) + create(module, self_link(module)) def delete(module, link): diff --git a/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository.py b/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository.py index d1e1a06be43..8bfa22e7065 100644 --- a/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository.py +++ b/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository.py @@ -142,7 +142,8 @@ def create(module, link): def update(module, link): - module.fail_json(msg="Repository cannot be edited") + delete(module, self_link(module)) + create(module, collection(module)) def delete(module, link): diff --git a/test/integration/targets/gcp_container_cluster/defaults/main.yml b/test/integration/targets/gcp_container_cluster/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_container_cluster/defaults/main.yml +++ b/test/integration/targets/gcp_container_cluster/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" diff --git a/test/integration/targets/gcp_container_node_pool/defaults/main.yml b/test/integration/targets/gcp_container_node_pool/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_container_node_pool/defaults/main.yml +++ b/test/integration/targets/gcp_container_node_pool/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" diff --git a/test/integration/targets/gcp_dns_managed_zone/defaults/main.yml b/test/integration/targets/gcp_dns_managed_zone/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_dns_managed_zone/defaults/main.yml +++ b/test/integration/targets/gcp_dns_managed_zone/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" diff --git a/test/integration/targets/gcp_dns_resource_record_set/defaults/main.yml b/test/integration/targets/gcp_dns_resource_record_set/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_dns_resource_record_set/defaults/main.yml +++ b/test/integration/targets/gcp_dns_resource_record_set/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" diff --git a/test/integration/targets/gcp_iam_role/defaults/main.yml b/test/integration/targets/gcp_iam_role/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_iam_role/defaults/main.yml +++ b/test/integration/targets/gcp_iam_role/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" diff --git a/test/integration/targets/gcp_iam_service_account/defaults/main.yml b/test/integration/targets/gcp_iam_service_account/defaults/main.yml index aa87a2a8e0e..5595dfb48ec 100644 --- a/test/integration/targets/gcp_iam_service_account/defaults/main.yml +++ b/test/integration/targets/gcp_iam_service_account/defaults/main.yml @@ -1,3 +1,3 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" +sa_name: sa-{{ 100000 | random }}@graphite-playground.google.com.iam.gserviceaccount.com diff --git a/test/integration/targets/gcp_iam_service_account/tasks/main.yml b/test/integration/targets/gcp_iam_service_account/tasks/main.yml index 496b31b15ba..f302e82e976 100644 --- a/test/integration/targets/gcp_iam_service_account/tasks/main.yml +++ b/test/integration/targets/gcp_iam_service_account/tasks/main.yml @@ -15,7 +15,7 @@ # Pre-test setup - name: delete a service account gcp_iam_service_account: - name: '"{{resource_name}}@{{gcp_project}}.google.com.iam.gserviceaccount.com"' + name: "{{ sa_name }}" display_name: My Ansible test key project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" @@ -24,7 +24,7 @@ #---------------------------------------------------------- - name: create a service account gcp_iam_service_account: - name: '"{{resource_name}}@{{gcp_project}}.google.com.iam.gserviceaccount.com"' + name: "{{ sa_name }}" display_name: My Ansible test key project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" @@ -50,7 +50,7 @@ # ---------------------------------------------------------------------------- - name: create a service account that already exists gcp_iam_service_account: - name: '"{{resource_name}}@{{gcp_project}}.google.com.iam.gserviceaccount.com"' + name: "{{ sa_name }}" display_name: My Ansible test key project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" @@ -64,7 +64,7 @@ #---------------------------------------------------------- - name: delete a service account gcp_iam_service_account: - name: '"{{resource_name}}@{{gcp_project}}.google.com.iam.gserviceaccount.com"' + name: "{{ sa_name }}" display_name: My Ansible test key project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" @@ -90,7 +90,7 @@ # ---------------------------------------------------------------------------- - name: delete a service account that does not exist gcp_iam_service_account: - name: '"{{resource_name}}@{{gcp_project}}.google.com.iam.gserviceaccount.com"' + name: "{{ sa_name }}" display_name: My Ansible test key project: "{{ gcp_project }}" auth_kind: "{{ gcp_cred_kind }}" diff --git a/test/integration/targets/gcp_pubsub_subscription/defaults/main.yml b/test/integration/targets/gcp_pubsub_subscription/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_pubsub_subscription/defaults/main.yml +++ b/test/integration/targets/gcp_pubsub_subscription/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" diff --git a/test/integration/targets/gcp_pubsub_topic/defaults/main.yml b/test/integration/targets/gcp_pubsub_topic/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_pubsub_topic/defaults/main.yml +++ b/test/integration/targets/gcp_pubsub_topic/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" diff --git a/test/integration/targets/gcp_redis_instance/defaults/main.yml b/test/integration/targets/gcp_redis_instance/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_redis_instance/defaults/main.yml +++ b/test/integration/targets/gcp_redis_instance/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" diff --git a/test/integration/targets/gcp_resourcemanager_project/defaults/main.yml b/test/integration/targets/gcp_resourcemanager_project/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_resourcemanager_project/defaults/main.yml +++ b/test/integration/targets/gcp_resourcemanager_project/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}" diff --git a/test/integration/targets/gcp_sourcerepo_repository/defaults/main.yml b/test/integration/targets/gcp_sourcerepo_repository/defaults/main.yml index aa87a2a8e0e..ba66644fc1c 100644 --- a/test/integration/targets/gcp_sourcerepo_repository/defaults/main.yml +++ b/test/integration/targets/gcp_sourcerepo_repository/defaults/main.yml @@ -1,3 +1,2 @@ --- -# defaults file -resource_name: '{{resource_prefix}}' +resource_name: "{{ resource_prefix }}"