Created
October 27, 2022 20:30
-
-
Save fragaLY/5beadacb4753625adb89efb55534645a to your computer and use it in GitHub Desktop.
[GCP] Automating the Deployment of Infrastructure Using Terraform
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 --version | |
mkdir tfinfra | |
cd tfinfra | |
nano provider.tf | |
# provider "google" {} < should be added | |
terraform init | |
nano network.tf | |
# The next quoted data is about network definition | |
# Create the mynetwork network | |
# resource "google_compute_network" "mynetwork" { | |
# name = "mynetwork" | |
# auto_create_subnetworks = "true" | |
# } | |
# Add a firewall rule to allow HTTP, SSH, RDP and ICMP traffic on mynetwork | |
# resource "google_compute_firewall" "mynetwork-allow-http-ssh-rdp-icmp" { | |
# name = "mynetwork-allow-http-ssh-rdp-icmp" | |
# network = google_compute_network.mynetwork.self_link | |
# allow { | |
# protocol = "tcp" | |
# ports = ["22", "80", "3389"] | |
# } | |
# allow { | |
# protocol = "icmp" | |
# } | |
# source_ranges = ["0.0.0.0/0"] | |
# } | |
# Create the mynet-us-vm instance | |
# module "mynet-us-vm" { | |
# source = "./instance" | |
# instance_name = "mynet-us-vm" | |
# instance_zone = "us-west1-a" | |
# instance_network = google_compute_network.mynetwork.self_link | |
# } | |
# # Create the mynet-eu-vm" instance | |
# module "mynet-eu-vm" { | |
# source = "./instance" | |
# instance_name = "mynet-eu-vm" | |
# instance_zone = "europe-west1-d" | |
# instance_network = google_compute_network.mynetwork.self_link | |
# } | |
mkdir instance | |
cd instance | |
nano main.tf | |
# Add quoted sources in the file | |
# resource "google_compute_instance" "vm_instance" { | |
# name = "${var.instance_name}" | |
# zone = "${var.instance_zone}" | |
# machine_type = "${var.instance_type}" | |
# boot_disk { | |
# initialize_params { | |
# image = "debian-cloud/debian-11" | |
# } | |
# } | |
# network_interface { | |
# network = "${var.instance_network}" | |
# access_config { | |
# # Allocate a one-to-one NAT IP to the instance | |
# } | |
# } | |
# } | |
nano variables.tf | |
# variable "instance_name" {} | |
# variable "instance_zone" {} | |
# variable "instance_type" { | |
# default = "e2-micro" | |
# } | |
# variable "instance_network" {} | |
# To rewrite the Terraform configuration files to a canonical format and style, run the following command: | |
terraform fmt | |
# To initalize Terraform | |
terraform init | |
# To create execution plan | |
terraform plan | |
# To apply | |
terraform apply |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment