Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Tags update on Instance #154

Open
wants to merge 92 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
8d286d7
Initial MM commit
rambleraptor May 2, 2018
4d233d5
Ansible support on the Magician. (#7)
modular-magician May 29, 2018
c389004
Bringing Ansible to HEAD (#9)
modular-magician May 29, 2018
59d2b2f
Generates DefaultObjectACL and ObjectAccessControl resources.
nat-henderson Jun 1, 2018
c403181
SQL Databases (#12)
modular-magician Jun 1, 2018
d07f2ac
Ansible: SQL Users (#16)
modular-magician Jun 5, 2018
d09a4be
Added autogenerated header check (#18)
modular-magician Jun 5, 2018
43627db
Magic Modules changes.
rosbo Jun 5, 2018
1884c7e
Add description field to Route resource, make non-updateable.
nat-henderson Jun 14, 2018
a8232a0
Ansible doesn't need save_api_results
rambleraptor Jun 13, 2018
09a67bc
Magic Modules changes.
rambleraptor Jun 18, 2018
7c52a15
removing integration folders for deleted storage
rambleraptor Jun 18, 2018
1d509b2
Adding fetch back on certain places.
rambleraptor Jun 18, 2018
7976cf0
Spanner Instances + Databases
rambleraptor Jun 26, 2018
651edb5
Example refactor
modular-magician Jul 20, 2018
802d3ad
Adding Compute Facts (#60)
modular-magician Aug 6, 2018
9256c2f
Object.input should == noneditable (#62)
modular-magician Aug 15, 2018
3d115c2
add RegionDiskType
danawillow Aug 16, 2018
3a2805f
Partial updates (#63)
modular-magician Aug 20, 2018
3a57677
Add a few new fields to firewalls, and use PATCH instead of PUT for u…
danawillow Aug 20, 2018
57bd543
Magic Modules changes. (#79)
modular-magician Aug 27, 2018
2e06037
Minor updates to HealthCheck description, default values. (#78)
modular-magician Aug 28, 2018
c92e418
removed kind checks (#76)
modular-magician Aug 28, 2018
9fcb94b
BackendService LoadBalancingScheme + IAP support
modular-magician Aug 28, 2018
0c5df16
InstanceGroup should add/remove instances (#82)
modular-magician Aug 30, 2018
6f80bb4
Add settingsVersion property to Cloud SQL instance settings (#84)
modular-magician Sep 5, 2018
e724a08
make vpnTunnel.router into a ResourceRef
danawillow Sep 7, 2018
0df5fc4
examples showing an improper auth value (#87)
modular-magician Sep 7, 2018
e3b3514
Adding ability to override classes (#92)
modular-magician Sep 12, 2018
e834048
Minor schema/docs update to SslCertificate. (#89)
modular-magician Sep 12, 2018
e826a4b
Magic Modules changes. (#91)
modular-magician Sep 12, 2018
16124a5
Express project name in env variable (#94)
modular-magician Sep 20, 2018
aed81a8
Pubsub + DNS Facts (#75)
modular-magician Sep 21, 2018
6c32e1f
return_if_object should only allow 404 on certain situations (#93)
modular-magician Sep 21, 2018
cbffb78
Return values should be camelcase instead of underscored (#95)
modular-magician Sep 21, 2018
8e73ec0
2.8 changes (#98)
modular-magician Sep 21, 2018
84ff815
Magic Modules changes. (#97)
modular-magician Sep 24, 2018
3bd384f
Better documentation for how a resourceref works (#96)
modular-magician Sep 24, 2018
fb5ed3a
Add additional properties to VPC Network.
rileykarson Sep 25, 2018
ddd7347
Metadata encoder/decoder should allow empty values
modular-magician Sep 28, 2018
d139fa7
Reverting template change (#104)
modular-magician Sep 28, 2018
d77223f
Update urlMap properties
rileykarson Sep 28, 2018
7192f73
Merge pull request #102 from modular-magician/codegen-pr-475
rileykarson Oct 1, 2018
f13fc0a
remove min_version from a bunch of fields that are in GA now
danawillow Oct 4, 2018
3952f86
Merge pull request #107 from modular-magician/codegen-pr-524
danawillow Oct 4, 2018
5df6e5b
Merge pull request #106 from modular-magician/codegen-pr-514
rileykarson Oct 8, 2018
f8c46d6
labelfingerprint is beta for resources where labels are beta
danawillow Oct 9, 2018
9d250b6
Removing the <|extra|> marker because it's only used in DNS custom co…
modular-magician Oct 11, 2018
30caf7f
Magic Modules changes. (#101)
modular-magician Oct 11, 2018
8da785e
WIP: Add interconnect attachments.
nat-henderson Oct 11, 2018
b3f1256
Merge pull request #109 from modular-magician/codegen-pr-540
danawillow Oct 11, 2018
a7ab778
Merge pull request #13 from modular-magician/codegen-pr-210
nat-henderson Oct 11, 2018
d6c8fca
Minor docs changes for UrlMap
rileykarson Oct 12, 2018
9720967
Merge pull request #111 from modular-magician/codegen-pr-545
rileykarson Oct 15, 2018
f83c565
The Last of the Facts Modules
modular-magician Oct 16, 2018
6de55cb
Improve schema and docs for Google Cloud Storage ObjectAccessControl
rileykarson Oct 17, 2018
e50c3ed
Merge pull request #112 from modular-magician/codegen-pr-562
rileykarson Oct 17, 2018
d7ae9f0
Documentation Refactor
modular-magician Oct 23, 2018
624266e
Empty commit with no code changes
chrisst Oct 24, 2018
e42eba0
Merge pull request #121 from modular-magician/codegen-pr-616
chrisst Oct 24, 2018
f62665e
Changed scopes defaults on Facts modules
modular-magician Nov 2, 2018
c8c031f
Adding minCpuPlatform to InstanceTemplate
modular-magician Nov 2, 2018
4c814ba
Creating Service Accounts (#125)
modular-magician Nov 5, 2018
adf6ec9
Ansible Projects (#116)
modular-magician Nov 6, 2018
16447d0
Add labels and updates to DNS managed zone
drebes Nov 13, 2018
55324dc
Merge pull request #128 from modular-magician/codegen-pr-697
danawillow Nov 16, 2018
4d4db52
Splitting out a small typo fix unrelated from #697 (#130)
modular-magician Nov 19, 2018
20af191
Remove bad network update calls on Ansible
modular-magician Nov 26, 2018
d33f9be
Ansible: Instance On/Off
modular-magician Nov 27, 2018
074b753
Ansible Storage Upload/Download
modular-magician Nov 27, 2018
c0cb734
Add sslPolicy to a few resources.
danawillow Nov 28, 2018
5cbc78f
Fix bad type for Network routing_config.routing_mode (#136)
modular-magician Nov 29, 2018
7c0cd26
Ansible: Service Account Keys (#135)
modular-magician Nov 29, 2018
c77d5cb
Add support for content-based load balancing to HealthCheck (#138)
modular-magician Nov 30, 2018
54a2ed7
Fixing firewall issues on Ansible (#137)
modular-magician Dec 3, 2018
2260ac5
Conflicts-with (#133)
modular-magician Dec 4, 2018
29020a2
Ansible: Auth fix for scopes (#140)
modular-magician Dec 5, 2018
6d759b2
Ansible: `false`s being lost in network requests (#141)
modular-magician Dec 5, 2018
aa2beb8
Fixing integration tests on SQL + DNS (#139)
modular-magician Dec 5, 2018
9988260
Not Suppressing values accidentally (#143)
modular-magician Dec 6, 2018
2ee8c7b
removing interconnect tests
rambleraptor Dec 6, 2018
42abba7
Bigquery (#127)
modular-magician Dec 6, 2018
415ad93
Integration test fixes (#142)
modular-magician Dec 6, 2018
3395f14
Removing unused puppet code (#144)
modular-magician Dec 7, 2018
807b879
Merge pull request #134 from modular-magician/codegen-pr-952
danawillow Dec 7, 2018
eacb799
Allowing address to be settable
chrisst Dec 8, 2018
659fbbb
Merge pull request #146 from modular-magician/codegen-pr-1014
chrisst Dec 11, 2018
7d0eb7b
Ansible integration test fixes - pt 2 (#147)
modular-magician Dec 14, 2018
07425f6
Better resourceref flexibility (#149)
modular-magician Dec 14, 2018
8aff6fc
Misc. typo fixes (#150)
modular-magician Dec 19, 2018
8263c82
Initial addition of generated Image to Terraform. (#151)
modular-magician Jan 3, 2019
537ef9f
Tags update on Instance
rambleraptor Jan 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions lib/ansible/module_utils/gcp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ansible.module_utils.basic import AnsibleModule, env_fallback
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_text
import ast
import os


Expand Down Expand Up @@ -60,8 +61,15 @@ def replace_resource_dict(item, value):
else:
if not item:
return item
return item.get(value)
if isinstance(item, dict):
return item.get(value)

# Item could be a string or a string representing a dictionary.
try:
new_item = ast.literal_eval(item)
return replace_resource_dict(new_item, value)
except ValueError:
return new_item

# Handles all authentation and HTTP sessions for GCP API calls.
class GcpSession(object):
Expand All @@ -77,12 +85,19 @@ def get(self, url, body=None, **kwargs):
except getattr(requests.exceptions, 'RequestException') as inst:
self.module.fail_json(msg=inst.message)

def post(self, url, body=None):
def post(self, url, body=None, headers={}, **kwargs):
kwargs.update({'json': body, 'headers': self._merge_dictionaries(headers, self._headers())})
try:
return self.session().post(url, json=body, headers=self._headers())
except getattr(requests.exceptions, 'RequestException') as inst:
self.module.fail_json(msg=inst.message)

def post_contents(self, url, file_contents=None, headers={}, **kwargs):
try:
return self.session().post(url, data=file_contents, headers=self._headers())
except getattr(requests.exceptions, 'RequestException') as inst:
self.module.fail_json(msg=inst.message)

def delete(self, url, body=None):
try:
return self.session().delete(url, json=body, headers=self._headers())
Expand All @@ -104,7 +119,7 @@ def patch(self, url, body=None, **kwargs):

def session(self):
return AuthorizedSession(
self._credentials().with_scopes(self.module.params['scopes']))
self._credentials())

def _validate(self):
if not HAS_REQUESTS:
Expand All @@ -126,11 +141,11 @@ def _validate(self):
def _credentials(self):
cred_type = self.module.params['auth_kind']
if cred_type == 'application':
credentials, project_id = google.auth.default()
credentials, project_id = google.auth.default(scopes=self.module.params['scopes'])
return credentials
elif cred_type == 'serviceaccount':
path = os.path.realpath(os.path.expanduser(self.module.params['service_account_file']))
return service_account.Credentials.from_service_account_file(path)
return service_account.Credentials.from_service_account_file(path).with_scopes(self.module.params['scopes'])
elif cred_type == 'machineaccount':
return google.auth.compute_engine.Credentials(
self.module.params['service_account_email'])
Expand All @@ -142,6 +157,11 @@ def _headers(self):
'User-Agent': "Google-Ansible-MM-{0}".format(self.product)
}

def _merge_dictionaries(self, a, b):
new = a.copy()
new.update(b)
return new


class GcpModule(AnsibleModule):
def __init__(self, *args, **kwargs):
Expand All @@ -152,7 +172,10 @@ def __init__(self, *args, **kwargs):
kwargs['argument_spec'] = self._merge_dictionaries(
arg_spec,
dict(
project=dict(required=True, type='str'),
project=dict(
required=False,
type='str',
fallback=(env_fallback, ['GCP_PROJECT'])),
auth_kind=dict(
required=False,
fallback=(env_fallback, ['GCP_AUTH_KIND']),
Expand Down
Loading