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

Commit

Permalink
Better resourceref flexibility (#149)
Browse files Browse the repository at this point in the history
<!-- This change is generated by MagicModules. -->
/cc @rambleraptor
  • Loading branch information
modular-magician authored and rambleraptor committed Dec 14, 2018
1 parent 7d0eb7b commit 07425f6
Show file tree
Hide file tree
Showing 64 changed files with 368 additions and 404 deletions.
10 changes: 9 additions & 1 deletion 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 Down
11 changes: 5 additions & 6 deletions lib/ansible/modules/cloud/google/gcp_compute_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@
- This field can only be used with INTERNAL type with GCE_ENDPOINT/DNS_RESOLVER
purposes.
- 'This field represents a link to a Subnetwork resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_compute_subnetwork
task and then set this subnetwork field to "{{ name-of-resource }}" Alternatively,
you can set this subnetwork to a dictionary with the selfLink key where the
value is the selfLink of your Subnetwork'
in two ways. First, you can place in the selfLink of the resource here as a
string Alternatively, you can add `register: name-of-resource` to a gcp_compute_subnetwork
task and then set this subnetwork field to "{{ name-of-resource }}"'
required: false
version_added: 2.7
region:
Expand Down Expand Up @@ -183,7 +182,7 @@
- This field can only be used with INTERNAL type with GCE_ENDPOINT/DNS_RESOLVER
purposes.
returned: success
type: dict
type: str
users:
description:
- The URLs of the resources that are using this address.
Expand Down Expand Up @@ -221,7 +220,7 @@ def main():
description=dict(type='str'),
name=dict(required=True, type='str'),
network_tier=dict(type='str', choices=['PREMIUM', 'STANDARD']),
subnetwork=dict(type='dict'),
subnetwork=dict(),
region=dict(required=True, type='str')
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
- This field can only be used with INTERNAL type with GCE_ENDPOINT/DNS_RESOLVER
purposes.
returned: success
type: dict
type: str
users:
description:
- The URLs of the resources that are using this address.
Expand Down
12 changes: 6 additions & 6 deletions lib/ansible/modules/cloud/google/gcp_compute_backend_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@
- When the BackendService has load balancing scheme INTERNAL, the instance
group must be in a zone within the same region as the BackendService.
- 'This field represents a link to a InstanceGroup resource in GCP. It can
be specified in two ways. You can add `register: name-of-resource` to a
gcp_compute_instance_group task and then set this group field to "{{ name-of-resource
}}" Alternatively, you can set this group to a dictionary with the selfLink
key where the value is the selfLink of your InstanceGroup'
be specified in two ways. First, you can place in the selfLink of the resource
here as a string Alternatively, you can add `register: name-of-resource`
to a gcp_compute_instance_group task and then set this group field to "{{
name-of-resource }}"'
required: false
max_connections:
description:
Expand Down Expand Up @@ -387,7 +387,7 @@
- When the BackendService has load balancing scheme INTERNAL, the instance group
must be in a zone within the same region as the BackendService.
returned: success
type: dict
type: str
maxConnections:
description:
- The max number of simultaneous connections for the group. Can be used with
Expand Down Expand Up @@ -626,7 +626,7 @@ def main():
balancing_mode=dict(type='str', choices=['UTILIZATION', 'RATE', 'CONNECTION']),
capacity_scaler=dict(type='str'),
description=dict(type='str'),
group=dict(type='dict'),
group=dict(),
max_connections=dict(type='int'),
max_connections_per_instance=dict(type='int'),
max_rate=dict(type='int'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
- When the BackendService has load balancing scheme INTERNAL, the instance
group must be in a zone within the same region as the BackendService.
returned: success
type: dict
type: str
maxConnections:
description:
- The max number of simultaneous connections for the group. Can be used
Expand Down
11 changes: 5 additions & 6 deletions lib/ansible/modules/cloud/google/gcp_compute_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@
- The source snapshot used to create this disk. You can provide this as a partial
or full URL to the resource.
- 'This field represents a link to a Snapshot resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_compute_snapshot
task and then set this source_snapshot field to "{{ name-of-resource }}" Alternatively,
you can set this source_snapshot to a dictionary with the selfLink key where
the value is the selfLink of your Snapshot'
in two ways. First, you can place in the selfLink of the resource here as a
string Alternatively, you can add `register: name-of-resource` to a gcp_compute_snapshot
task and then set this source_snapshot field to "{{ name-of-resource }}"'
required: false
source_snapshot_encryption_key:
description:
Expand Down Expand Up @@ -351,7 +350,7 @@
- The source snapshot used to create this disk. You can provide this as a partial
or full URL to the resource.
returned: success
type: dict
type: str
sourceSnapshotEncryptionKey:
description:
- The customer-supplied encryption key of the source snapshot. Required if the source
Expand Down Expand Up @@ -418,7 +417,7 @@ def main():
raw_key=dict(type='str'),
sha256=dict(type='str')
)),
source_snapshot=dict(type='dict'),
source_snapshot=dict(),
source_snapshot_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
sha256=dict(type='str')
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/google/gcp_compute_disk_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
- The source snapshot used to create this disk. You can provide this as a partial
or full URL to the resource.
returned: success
type: dict
type: str
sourceSnapshotEncryptionKey:
description:
- The customer-supplied encryption key of the source snapshot. Required if the
Expand Down
11 changes: 5 additions & 6 deletions lib/ansible/modules/cloud/google/gcp_compute_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@
networks/my-network projects/myproject/global/networks/my-network global/networks/default
.'
- 'This field represents a link to a Network resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_compute_network
task and then set this network field to "{{ name-of-resource }}" Alternatively,
you can set this network to a dictionary with the selfLink key where the value
is the selfLink of your Network'
in two ways. First, you can place in the selfLink of the resource here as a
string Alternatively, you can add `register: name-of-resource` to a gcp_compute_network
task and then set this network field to "{{ name-of-resource }}"'
required: false
default:
selfLink: global/networks/default
Expand Down Expand Up @@ -343,7 +342,7 @@
networks/my-network projects/myproject/global/networks/my-network global/networks/default
.'
returned: success
type: dict
type: str
priority:
description:
- Priority for this rule. This is an integer between 0 and 65535, both inclusive.
Expand Down Expand Up @@ -441,7 +440,7 @@ def main():
direction=dict(type='str', choices=['INGRESS', 'EGRESS']),
disabled=dict(type='bool'),
name=dict(required=True, type='str'),
network=dict(default={'selfLink': 'global/networks/default'}, type='dict'),
network=dict(default={'selfLink': 'global/networks/default'}),
priority=dict(default=1000, type='int'),
source_ranges=dict(type='list', elements='str'),
source_service_accounts=dict(type='list', elements='str'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
networks/my-network projects/myproject/global/networks/my-network global/networks/default
.'
returned: success
type: dict
type: str
priority:
description:
- Priority for this rule. This is an integer between 0 and 65535, both inclusive.
Expand Down
45 changes: 21 additions & 24 deletions lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@
- This is used for internal load balancing.
- "(not used for external load balancing) ."
- 'This field represents a link to a BackendService resource in GCP. It can be
specified in two ways. You can add `register: name-of-resource` to a gcp_compute_backend_service
task and then set this backend_service field to "{{ name-of-resource }}" Alternatively,
you can set this backend_service to a dictionary with the selfLink key where
the value is the selfLink of your BackendService'
specified in two ways. First, you can place in the selfLink of the resource
here as a string Alternatively, you can add `register: name-of-resource` to
a gcp_compute_backend_service task and then set this backend_service field to
"{{ name-of-resource }}"'
required: false
ip_version:
description:
Expand Down Expand Up @@ -136,10 +136,9 @@
specified, the default network will be used.
- This field is not used for external load balancing.
- 'This field represents a link to a Network resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_compute_network
task and then set this network field to "{{ name-of-resource }}" Alternatively,
you can set this network to a dictionary with the selfLink key where the value
is the selfLink of your Network'
in two ways. First, you can place in the selfLink of the resource here as a
string Alternatively, you can add `register: name-of-resource` to a gcp_compute_network
task and then set this network field to "{{ name-of-resource }}"'
required: false
port_range:
description:
Expand Down Expand Up @@ -172,10 +171,9 @@
if the network is in custom subnet mode, a subnetwork must be specified.
- This field is not used for external load balancing.
- 'This field represents a link to a Subnetwork resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_compute_subnetwork
task and then set this subnetwork field to "{{ name-of-resource }}" Alternatively,
you can set this subnetwork to a dictionary with the selfLink key where the
value is the selfLink of your Subnetwork'
in two ways. First, you can place in the selfLink of the resource here as a
string Alternatively, you can add `register: name-of-resource` to a gcp_compute_subnetwork
task and then set this subnetwork field to "{{ name-of-resource }}"'
required: false
target:
description:
Expand All @@ -186,10 +184,9 @@
target object.
- This field is not used for internal load balancing.
- 'This field represents a link to a TargetPool resource in GCP. It can be specified
in two ways. You can add `register: name-of-resource` to a gcp_compute_target_pool
task and then set this target field to "{{ name-of-resource }}" Alternatively,
you can set this target to a dictionary with the selfLink key where the value
is the selfLink of your TargetPool'
in two ways. First, you can place in the selfLink of the resource here as a
string Alternatively, you can add `register: name-of-resource` to a gcp_compute_target_pool
task and then set this target field to "{{ name-of-resource }}"'
required: false
version_added: 2.7
network_tier:
Expand Down Expand Up @@ -301,7 +298,7 @@
- This is used for internal load balancing.
- "(not used for external load balancing) ."
returned: success
type: dict
type: str
ipVersion:
description:
- The IP Version that will be used by this forwarding rule. Valid options are IPV4
Expand Down Expand Up @@ -334,7 +331,7 @@
the default network will be used.
- This field is not used for external load balancing.
returned: success
type: dict
type: str
portRange:
description:
- This field is used along with the target field for TargetHttpProxy, TargetHttpsProxy,
Expand Down Expand Up @@ -367,7 +364,7 @@
if the network is in custom subnet mode, a subnetwork must be specified.
- This field is not used for external load balancing.
returned: success
type: dict
type: str
target:
description:
- A reference to a TargetPool resource to receive the matched traffic.
Expand All @@ -377,7 +374,7 @@
target object.
- This field is not used for internal load balancing.
returned: success
type: dict
type: str
networkTier:
description:
- 'The networking tier used for configuring this address. This field can take the
Expand Down Expand Up @@ -415,15 +412,15 @@ def main():
description=dict(type='str'),
ip_address=dict(type='str'),
ip_protocol=dict(type='str', choices=['TCP', 'UDP', 'ESP', 'AH', 'SCTP', 'ICMP']),
backend_service=dict(type='dict'),
backend_service=dict(),
ip_version=dict(type='str', choices=['IPV4', 'IPV6']),
load_balancing_scheme=dict(type='str', choices=['INTERNAL', 'EXTERNAL']),
name=dict(required=True, type='str'),
network=dict(type='dict'),
network=dict(),
port_range=dict(type='str'),
ports=dict(type='list', elements='str'),
subnetwork=dict(type='dict'),
target=dict(type='dict'),
subnetwork=dict(),
target=dict(),
network_tier=dict(type='str', choices=['PREMIUM', 'STANDARD']),
region=dict(required=True, type='str')
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
- This is used for internal load balancing.
- "(not used for external load balancing) ."
returned: success
type: dict
type: str
ipVersion:
description:
- The IP Version that will be used by this forwarding rule. Valid options are
Expand Down Expand Up @@ -156,7 +156,7 @@
specified, the default network will be used.
- This field is not used for external load balancing.
returned: success
type: dict
type: str
portRange:
description:
- This field is used along with the target field for TargetHttpProxy, TargetHttpsProxy,
Expand Down Expand Up @@ -191,7 +191,7 @@
if the network is in custom subnet mode, a subnetwork must be specified.
- This field is not used for external load balancing.
returned: success
type: dict
type: str
target:
description:
- A reference to a TargetPool resource to receive the matched traffic.
Expand All @@ -201,7 +201,7 @@
to the target object.
- This field is not used for internal load balancing.
returned: success
type: dict
type: str
networkTier:
description:
- 'The networking tier used for configuring this address. This field can take
Expand Down
Loading

0 comments on commit 07425f6

Please sign in to comment.