From 029a535f523d9441b6f7b82f4c4950033a3819c5 Mon Sep 17 00:00:00 2001 From: James Blair Date: Wed, 13 Jan 2021 14:44:40 +1300 Subject: [PATCH] Added create virtual machine section. --- 2-configure-gcp-project.sh | 8 ++++++++ 3-create-virtual-machine.sh | 14 ++++++++++++++ README.org | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100755 3-create-virtual-machine.sh diff --git a/2-configure-gcp-project.sh b/2-configure-gcp-project.sh index 38e5eed..332706f 100755 --- a/2-configure-gcp-project.sh +++ b/2-configure-gcp-project.sh @@ -1,8 +1,13 @@ #!/bin/bash + # Once we have authenticated we can create a project and then create a new virtual machine instance within that project. +# Firstly let's create a new project, a project is the logical boundary all our cloud resources for this deployment will live within. To be able to deploy resources we also need to enable billing. + +# Tangle the shell block below to a shell script by pressing *, b t* in emacs command mode: + # #+NAME: Create a new google cloud project # Create a project id based on date @@ -14,3 +19,6 @@ gcloud projects create $gcp_project_id # Ensure billing is enabled for the project export gcp_billing_account=$(gcloud alpha billing accounts list --limit=1 --format='value(name.basename())') gcloud alpha billing projects link $gcp_project_id --billing-account $gcp_billing_account + +# Make sure the project is set active +gcloud config set project $gcp_project_id diff --git a/3-create-virtual-machine.sh b/3-create-virtual-machine.sh new file mode 100755 index 0000000..925a080 --- /dev/null +++ b/3-create-virtual-machine.sh @@ -0,0 +1,14 @@ +#!/bin/bash + + + +# Once we have a project we can create a new virtual machine. + +# Tangle the shell block below to a shell script by pressing *, b t* in emacs command mode: + + +# Create name for virtual machine based on date +export gcp_machine_name="gitlab-gcp-"$(date +"%Y-%m-%d") + +# Create the new machine +gcloud compute instances create $gcp_machine_name diff --git a/README.org b/README.org index 1364a88..6384dec 100644 --- a/README.org +++ b/README.org @@ -46,8 +46,13 @@ In future we could automate this process as part of a continous delivery pipelin gcloud auth login #+END_SRC + Once we have authenticated we can create a project and then create a new virtual machine instance within that project. +Firstly let's create a new project, a project is the logical boundary all our cloud resources for this deployment will live within. To be able to deploy resources we also need to enable billing. + +Tangle the shell block below to a shell script by pressing *, b t* in emacs command mode: + #+NAME: Create a new google cloud project #+begin_src bash :shebang #!/bin/bash :tangle 2-configure-gcp-project.sh # Create a project id based on date @@ -59,4 +64,20 @@ gcloud projects create $gcp_project_id # Ensure billing is enabled for the project export gcp_billing_account=$(gcloud alpha billing accounts list --limit=1 --format='value(name.basename())') gcloud alpha billing projects link $gcp_project_id --billing-account $gcp_billing_account + +# Make sure the project is set active +gcloud config set project $gcp_project_id +#+end_src + + +Once we have a project we can create a new virtual machine. + +Tangle the shell block below to a shell script by pressing *, b t* in emacs command mode: + +#+begin_src bash :shebang #!/bin/bash :tangle 3-create-virtual-machine.sh +# Create name for virtual machine based on date +export gcp_machine_name="gitlab-gcp-"$(date +"%Y-%m-%d") + +# Create the new machine +gcloud compute instances create $gcp_machine_name #+end_src