Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/run with service account #6

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ terraform.rc


.terraform.lock.hcl
terraform-service-key.json
10 changes: 9 additions & 1 deletion chap01/cloudshell/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# main.tf

provider "google" {
credentials = file("terraform-service-key.json")
project = "using-terraf-157-8db7dc35"
region = "us-central1"
}

resource "google_compute_instance" "this" {
name = "cloudshell"
machine_type = "e2-small"
Expand All @@ -12,4 +20,4 @@ resource "google_compute_instance" "this" {
network_interface {
network = "default"
}
}
}
51 changes: 51 additions & 0 deletions chap01/cloudshell/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#!/bin/bash

# Update the package list
sudo apt-get update
# sudo yum check-update # red-hat version

# Upgrade all installed packages including kernel and kernel headers
sudo apt-get upgrade -y
# sudo yum upgrade -y # red-hat version

# Install wget and unzip
sudo apt-get install wget unzip -y
# sudo yum install wget unzip -y # red-hat version

# Download and install Terraform (used 1.5.7 because latest version)
wget https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip

# Unzip the downloaded file
unzip terraform_1.5.7_linux_amd64.zip

# Move the executable to a directory in your path
sudo mv terraform /usr/local/bin/

# log version of Google Cloud SDK (assuming /usr/local/bin/ is in your PATH)
gcloud --version

# log out Terraform version (assuming /usr/local/bin/ is in your PATH)
terraform --version

# Assuming you have already downloaded and installed Google Cloud SDK authenticate with a service account (later we use an environment variable)
gcloud auth activate-service-account --key-file=~/terraform-service-account.json

# ensure gcloud.sh is executable
chmod +x gcloud.sh

# run gcloud.sh
./gcloud.sh

# run terraform

terraform init

terraform plan --out=plan.txt

terraform apply -auto-approve

terrform destroy



51 changes: 51 additions & 0 deletions chap01/environment-variable/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#!/bin/bash

# Update the package list
sudo apt-get update
# sudo yum check-update # red-hat version

# Upgrade all installed packages including kernel and kernel headers
sudo apt-get upgrade -y
# sudo yum upgrade -y # red-hat version

# Install wget and unzip
sudo apt-get install wget unzip -y
# sudo yum install wget unzip -y # red-hat version

# Download and install Terraform (used 1.6.0 because latest version)
wget https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip

# Unzip the downloaded file
unzip terraform_1.6.0_linux_amd64.zip

# Move the executable to a directory in your path
sudo mv terraform /usr/local/bin/

# log version of Google Cloud SDK (assuming /usr/local/bin/ is in your PATH)
gcloud --version

# log out Terraform version (assuming /usr/local/bin/ is in your PATH)
terraform --version

# Assuming you have already downloaded and installed Google Cloud SDK authenticate with a service account (later we use an environment variable)
gcloud auth activate-service-account --key-file=~/terraform-service-account.json

# ensure gcloud.sh is executable
chmod +x gcloud.sh

# run gcloud.sh
./gcloud.sh

# run terraform

terraform init

terraform plan --out=plan.txt

terraform apply -auto-approve

terrform destroy