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
credentials = "./terraform-gke-keyfile.json" # service account json file name & path | |
project_id = "<project-name>" # make sure you enter your project id from gcp | |
region = "<region>" # region where you wanna create in | |
zones = ["<region>-a", "<region>-b", "<region>-c"] # zone | |
name = "terraform-gke" # name of your cluster | |
machine_type = "<machine_type>" # type of compute size | |
min_count = 1 | |
max_count = 3 | |
disk_size_gb = 10 | |
service_account = "<service-account-name>@<project-name>.iam.gserviceaccount.com" # service account name which we created |
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
variable "credentials" { | |
type = string | |
description = "Location of the credential keyfile." | |
} | |
variable "project_id" { | |
type = string | |
description = "The project ID to create the cluster." | |
} |
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
module "gke" { | |
source = "terraform-google-modules/kubernetes-engine/google" | |
project_id = var.project_id | |
name = var.name | |
region = var.region | |
zones = var.zones | |
network = "default" | |
subnetwork = "default" | |
ip_range_pods = "" | |
ip_range_services = "" |
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
module "gke" { | |
source = "terraform-google-modules/kubernetes-engine/google" | |
project_id = var.project_id | |
name = var.name | |
region = var.region | |
zones = var.zones | |
network = "default" | |
subnetwork = "default" | |
ip_range_pods = "" | |
ip_range_services = "" |
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)}" | |
} |
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
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
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
\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
#!/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 |
NewerOlder