Skip to content

Commit

Permalink
conditional services enable
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner committed Jan 7, 2024
1 parent 0df0fa3 commit f104b82
Show file tree
Hide file tree
Showing 28 changed files with 171 additions and 88 deletions.
4 changes: 2 additions & 2 deletions examples/unfurl-artifacts/lib/shop_app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ node_types:
#
###################################################

- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ SELF.credentials }} --project {{ SELF.project }}'
when: SELF.deployment_mode == "GCP"

Expand Down Expand Up @@ -262,7 +262,7 @@ node_types:
#
###################################################

- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ SELF.credentials }} --project {{ SELF.project }}'
when: SELF.deployment_mode == "GCP"

Expand Down
18 changes: 15 additions & 3 deletions examples/unfurl-aware/lib/gcp_runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,27 @@ node_types:
inputs:
playbook:
q:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ SELF.service_account_file }} --project {{ SELF.project }}'

# https://cloud.google.com/sql/docs/mysql/connect-instance-cloud-shell
- name: Enable Cloud Build API
shell: 'gcloud services enable cloudbuild.googleapis.com'
shell: |
GCP_SERVICE=cloudbuild.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi
- name: Enable appengine.googleapis.com
shell: 'gcloud services enable appengine.googleapis.com'
shell: |
GCP_SERVICE=appengine.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi
# https://cloud.google.com/sdk/gcloud/reference/app/create
- name: Create App
Expand Down
4 changes: 2 additions & 2 deletions examples/unfurl-aware/lib/shop_component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ node_types:
#
###################################################

- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ SELF.gcp_service_account_file }} --project {{ SELF.gcp_project }}'
when: SELF.deployment_mode[0] == "GCP"

Expand Down Expand Up @@ -263,7 +263,7 @@ node_types:
#
###################################################

- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ SELF.gcp_service_account_file }} --project {{ SELF.gcp_project }}'
when: SELF.deployment_mode[0] == "GCP"

Expand Down
2 changes: 1 addition & 1 deletion examples/unfurl-aware/lib/shop_database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ node_types:
#
###################################################

- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ SELF.gcp_service_account_file }} --project {{ SELF.gcp_project }}'
when: SELF.deployment_mode == "GCP"

Expand Down
23 changes: 20 additions & 3 deletions examples/unfurl-motivation/lib/gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ node_types:
implementation: |
set -e
gcloud --no-user-output-enabled auth activate-service-account --key-file {{ SELF.service_account_file }} --project {{ SELF.project }}
gcloud services enable sqladmin.googleapis.com >/dev/null
GCP_SERVICE=sqladmin.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE} >/dev/null
fi
gcloud sql instances create {{ SELF.instance_name }} --tier {{ SELF.instance_tier }} --region {{ SELF.region }} --database-version={{ SELF.database_version }} --authorized-networks {{ SELF.authorized_networks }} --timeout unlimited >/dev/null
gcloud sql users set-password root --host=% --instance {{ SELF.instance_name }} --password {{ SELF.password }} >/dev/null
gcloud sql instances describe {{ SELF.instance_name }} --format=json
Expand Down Expand Up @@ -199,8 +205,19 @@ node_types:
implementation: |
set -e
gcloud auth activate-service-account --key-file {{ SELF.service_account_file }} --project {{ SELF.project }}
gcloud services enable cloudbuild.googleapis.com || true
gcloud services enable appengine.googleapis.com || true
GCP_SERVICE=cloudbuild.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi
GCP_SERVICE=appengine.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi

gcloud app create --region {{ SELF.region }} || true
inputs:
keeplines: true
2 changes: 1 addition & 1 deletion examples/unfurl-motivation/lib/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ node_types:
cd {{ SELF.application_directory }}
sudo npm install --unsafe-perm
sudo pm2 start --name {{ SELF.application_name }} start.sh
EOF
EOF
exit 0
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/unfurl-motivation/scripts/configuration.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
TEMPLATE_NAME="motivation"
VINTNER="yarn vintner"
DEPLOYMENT_VARIANT="prod"
DEPLOYMENT_VARIANT="dev"
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
---
- name: Create GCP App Engine
hosts: all
gather_facts: false
tasks:
- name: active service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'
- name: Create GCP App Engine
hosts: all
gather_facts: false
tasks:
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/connect-instance-cloud-shell
- name: Enable Cloud Build API
shell: 'gcloud services enable cloudbuild.googleapis.com'
# https://cloud.google.com/sql/docs/mysql/connect-instance-cloud-shell
- name: Enable Cloud Build API
shell: |
GCP_SERVICE=cloudbuild.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi
- name: Enable appengine.googleapis.com
shell: 'gcloud services enable appengine.googleapis.com'
- name: Enable appengine.googleapis.com
shell: |
GCP_SERVICE=appengine.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi
# https://cloud.google.com/sdk/gcloud/reference/app/create
- name: Create App
shell: 'gcloud app create --region {{ region }}'
register: app_create_command
failed_when:
- "'Created' not in app_create_command.stderr"
- "'already contains' not in app_create_command.stderr"
# https://cloud.google.com/sdk/gcloud/reference/app/create
- name: Create App
shell: 'gcloud app create --region {{ region }}'
register: app_create_command
failed_when:
- "'Created' not in app_create_command.stderr"
- "'already contains' not in app_create_command.stderr"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/create-manage-databases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/create-manage-databases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/connect-instance-cloud-shell
- name: Enable Cloud SQL Admin API
shell: 'gcloud services enable sqladmin.googleapis.com'
shell: |
GCP_SERVICE=sqladmin.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi
# https://cloud.google.com/sql/docs/mysql/create-instance
- name: Create Instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }}'

- name: Delete Instnace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ gcp_service_account_file }} --project {{ gcp_project }}'

- name: Create working directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ gcp_service_account_file }} --project {{ gcp_project }}'

- name: Create App
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/create-manage-databases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/create-manage-databases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/connect-instance-cloud-shell
- name: Enable Cloud SQL Admin API
shell: 'gcloud services enable sqladmin.googleapis.com'
shell: |
GCP_SERVICE=sqladmin.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi
# https://cloud.google.com/sql/docs/mysql/create-instance
# https://cloud.google.com/sdk/gcloud/reference/sql/instances/create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }}'

- name: Delete Instnace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
---
- name: Create GCP App Engine
hosts: all
gather_facts: false
tasks:
- name: active service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'
- name: Create GCP App Engine
hosts: all
gather_facts: false
tasks:
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/connect-instance-cloud-shell
- name: Enable Cloud Build API
shell: 'gcloud services enable cloudbuild.googleapis.com'
# https://cloud.google.com/sql/docs/mysql/connect-instance-cloud-shell
- name: Enable Cloud Build API
shell: |
GCP_SERVICE=cloudbuild.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi
- name: Enable appengine.googleapis.com
shell: 'gcloud services enable appengine.googleapis.com'
- name: Enable appengine.googleapis.com
shell: |
GCP_SERVICE=appengine.googleapis.com
GCP_SERVICE_ENABLED=$(gcloud services list --filter ${GCP_SERVICE} --format json --enabled | jq length)
if [ ${GCP_SERVICE_ENABLED} == 0 ]; then
gcloud services enable ${GCP_SERVICE}
fi
# https://cloud.google.com/sdk/gcloud/reference/app/create
- name: Create App
shell: 'gcloud app create --region {{ region }}'
register: app_create_command
failed_when:
- "'Created' not in app_create_command.stderr"
- "'already contains' not in app_create_command.stderr"
# https://cloud.google.com/sdk/gcloud/reference/app/create
- name: Create App
shell: 'gcloud app create --region {{ region }}'
register: app_create_command
failed_when:
- "'Created' not in app_create_command.stderr"
- "'already contains' not in app_create_command.stderr"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ gcp_service_account_file }} --project {{ gcp_project }}'

- name: Create working directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ gcp_service_account_file }} --project {{ gcp_project }}'

- name: Create App
Expand Down
2 changes: 1 addition & 1 deletion examples/xopera-pruning/lib/gcp/database/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/create-manage-databases
Expand Down
2 changes: 1 addition & 1 deletion examples/xopera-pruning/lib/gcp/database/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: all
gather_facts: false
tasks:
- name: active service account
- name: Activate service account
shell: 'gcloud auth activate-service-account --key-file {{ service_account_file }} --project {{ project }}'

# https://cloud.google.com/sql/docs/mysql/create-manage-databases
Expand Down
Loading

0 comments on commit f104b82

Please sign in to comment.