This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task 1: Create a project jumphost instance | |
Navigation menu > Compute engine > VM Instance | |
Task 2: Create a Kubernetes service cluster | |
gcloud config set compute/zone us-east1-b | |
gcloud container clusters create nucleus-webserver1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "google" { | |
credentials = file("./Credentials.json") | |
project = "project-id" | |
region = "us-central1" | |
zone = "us-central1-c" | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
backend "gcs" { | |
bucket = "bucket-name" | |
prefix = "terraform/state1" | |
credentials = "Credentials.json" #mention here the name and add service account key inside same folder | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "google_compute_instance" "web" { | |
name = "webserver" | |
machine_type = "f1-micro" | |
tags = ["http-server"] | |
boot_disk { | |
initialize_params { | |
image = "debian-cloud/debian-9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo apt-get update && sudo apt -y install apache2 | |
echo '<!doctype html><html><body><h1>Hello You Successfully was able to run a webserver on GCP with Terraform!</h1></body></html>' | sudo tee /var/www/html/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\GCP on Terraform> terraform plan | |
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: | |
+ create | |
Terraform will perform the following actions: | |
# google_compute_instance.test will be created | |
+ resource "google_compute_instance" "test" { | |
+ can_ip_forward = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcloud projects add-iam-policy-binding <project-name> --member serviceAccount:<service account name>@<project-name>.iam.gserviceaccount.com --role roles/compute.admin | |
gcloud projects add-iam-policy-binding <project-name> --member serviceAccount:<service account name>@<project-name>.iam.gserviceaccount.com --role roles/iam.serviceAccountUser | |
gcloud projects add-iam-policy-binding <project-name> --member serviceAccount:<service account name>@<project-name>.iam.gserviceaccount.com --role roles/resourcemanager.projectIamAdmin | |
gcloud projects add-iam-policy-binding <project-name> --member serviceAccount:<service account name>@<project-name>.iam.gserviceaccount.com --role roles/container.clusterAdmin | |
gcloud projects add-iam-policy-binding <project-name> --member serviceAccount:<service account name>@<project-name>.iam.gserviceaccount.com --role roles/compute.viewer | |
gcloud projects add-iam-policy-binding <project-name> --member se |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcloud services enable compute.googleapis.com | |
gcloud services enable container.googleapis.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
backend "gcs" { | |
bucket = "<bucket-name>" | |
prefix = "terraform/state" | |
credentials = "./terraform-gke-keyfile.json" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "google" { | |
project = var.project_id | |
region = var.region | |
credentials = "${file(var.credentials)}" | |
} |
OlderNewer