Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Accepts service account definition the created VM #50

Merged
merged 3 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ driver:
external_access: false # chose whether to create a public IP for the VM or not - default is private IP only
instance_os_type: linux # Either windows or linux. Will be considered linux by default. You can NOT mix Windows and Linux VMs in the same scenario.
platforms:
# see src/molecule_gce/playbooks/tasks/create_linux_instance.yml for a complete list of supported keys
- name: ubuntu-instance-created-by-molecule # REQUIRED: this will be your VM name
zone: us-central1-a # Example: us-west1-b. Will default to zone b of region defined in driver (some regions do not have a zone-a)
machine_type: n1-standard-1 # If not specified, will default to n1-standard-1
Expand Down
18 changes: 18 additions & 0 deletions src/molecule_gce/playbooks/tasks/create_linux_instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@
access_configs: "{{ [{'name': 'instance_ip', 'type': 'ONE_TO_ONE_NAT'}] if molecule_yml.driver.external_access else [] }}"
tags: "{{ item.tags | default(omit) }}"
zone: "{{ item.zone | default(molecule_yml.driver.region + '-b') }}"
service_accounts: >-
[
{% for account in molecule_yml.driver.service_accounts | d([]) %}
{
{% if account.email == 'same-as-driver' and molecule_yml.driver.service_account_email is defined %}
'email': '{{ molecule_yml.driver.service_account_email }}',
{% elif account.email == 'same-as-driver' and molecule_yml.driver.service_account_file is defined %}
'email': '{{ (lookup('file', molecule_yml.driver.service_account_file) | from_json)['client_email'] }}',
{% else %}
'email': '{{ account.email }}',
{% endif %}

{% if account.scopes is defined %}
'scopes': {{ account.scopes }},
{% endif %}
},
{% endfor %}
]
project: "{{ gcp_project_id }}"
scopes: "{{ molecule_yml.driver.scopes | default(['https://www.googleapis.com/auth/compute'], True) }}"
service_account_email: "{{ molecule_yml.driver.service_account_email | default (omit, true) }}"
Expand Down