├── LINKS.md ├── README.md ├── main.tf ├── mod-lb ├── main.tf ├── outputs.tf └── variables.tf ├── mod-mig ├── main.tf ├── output.tf └── variables.tf ├── mod-template-mig ├── main.tf ├── output.tf └── variables.tf ├── old ├── datasource.tf ├── machines.tf ├── main.tf ├── mod-lb │ ├── main.tf │ ├── outputs.tf │ └── variables.tf └── modules │ └── network │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── provider.tf ├── scripts ├── asia.sh └── us.sh └── state ├── bucket.tf └── provider.tf /LINKS.md: -------------------------------------------------------------------------------- 1 | # Links 2 | 3 | ## Aula 1 4 | 5 | https://www.youtube.com/watch?v=h970ZBgKINg 6 | 7 | https://www.infracost.io/ 8 | 9 | https://www.kubecost.com/ 10 | 11 | https://blog.bryanalbuquerque.dev/posts/terraform-associate/ 12 | 13 | https://blog.4linux.com.br/teoria-do-terraform/ 14 | 15 | https://blog.gruntwork.io/a-comprehensive-guide-to-terraform-b3d32832baca#.b6sun4nkn 16 | 17 | https://github.com/bryanasdev000/Terraform-531 18 | 19 | https://registry.terraform.io/browse/providers 20 | 21 | https://www.terraform.io/docs/language/index.html 22 | 23 | https://www.terraform.io/docs/cli/index.html 24 | 25 | https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance 26 | 27 | https://t.me/terraformbr 28 | 29 | https://github.com/alexmoreno/telegram-br 30 | 31 | https://docs.oracle.com/en/solutions/infrastructure-components-siebel/ebs-configuring-terraform-windows-systems.html 32 | 33 | https://www.jlcp.com.br/como-instalar-o-terraform-no-windows/ 34 | 35 | https://cloud.google.com/dns/docs/policies 36 | 37 | https://cloud.google.com/dns/docs/policies#before_you_begin 38 | 39 | ## Aula 2 40 | 41 | https://git-scm.com/download/win 42 | 43 | https://github.com/ 44 | 45 | https://console.cloud.google.com/apis/credentials/serviceaccountkey 46 | 47 | https://registry.terraform.io/providers/hashicorp/google/latest 48 | 49 | https://www.hashicorp.com/resources/a-practitioner-s-guide-to-using-hashicorp-terraform-cloud-with-github 50 | 51 | https://tfswitch.warrensbox.com/ 52 | 53 | https://nixos.org/ 54 | 55 | http://dontpad.com/terraform-4linux-7752/ 56 | 57 | ## Aula 3 58 | 59 | https://driftctl.com/ 60 | 61 | https://www.terraform.io/docs/language/resources/provisioners/syntax.html 62 | 63 | https://github.com/GoogleCloudPlatform/terraformer 64 | 65 | ## Aula 4 66 | 67 | https://weekly.tf/ 68 | 69 | https://www.hashicorp.com/events/webinars/recorded?type=all 70 | 71 | https://www.hashicorp.com/events?type=all 72 | 73 | https://www.hashicorp.com/blog/videos-from-hashiconf-2019-keynotes-and-breakout-sessions 74 | 75 | https://www.hashicorp.com/blog/hashitalks-2020-recorded-sessions-now-live 76 | 77 | https://github.com/asdf-vm/asdf 78 | 79 | https://t.me/joinchat/a2EHkKc_aP82YzQx 80 | 81 | https://www.terraform.io/docs/language/resources/provisioners/syntax.html 82 | 83 | https://www.terraform.io/docs/language/resources/provisioners/connection.html 84 | 85 | https://www.terraform.io/docs/language/resources/provisioners/local-exec.html 86 | 87 | https://www.terraform.io/docs/language/resources/provisioners/remote-exec.html 88 | 89 | https://www.terraform.io/docs/language/resources/provisioners/null_resource.html 90 | 91 | https://github.com/bridgecrewio/checkov 92 | 93 | https://github.com/tfsec/tfsec 94 | 95 | https://github.com/shuaibiyy/awesome-terraform 96 | 97 | https://vimeo.com/520205493 98 | 99 | ## Aula 5 100 | 101 | https://www.terraform.io/docs/language/modules/syntax.html 102 | 103 | http://dontpad.com/terraform-4linux-7752-projeto/ 104 | 105 | https://blog.gruntwork.io/terraform-tips-tricks-loops-if-statements-and-gotchas-f739bbae55f9 106 | 107 | https://www.terraform.io/docs/language/meta-arguments/count.html 108 | 109 | https://www.terraform.io/docs/language/expressions/index.html 110 | 111 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Terraform-531 2 | Repositório para utilização em aula 3 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | # Descricao 2 | # Boa parte do codigo que esta aqui e "boilerplate" 3 | # em outras palavras, codigo pronto que esta na documentacao, 4 | # apenas parametrizado (variables\outputs). 5 | 6 | # Rede (VPC + Subnet) 7 | module "vpc" { 8 | source = "terraform-google-modules/network/google" 9 | version = "3.2.2" 10 | 11 | project_id = "rubeus-proxysql" 12 | network_name = "ha-final" 13 | 14 | subnets = [ 15 | { 16 | subnet_name = "subnet-us" 17 | subnet_ip = "10.10.10.0/24" 18 | subnet_region = "us-central1" 19 | }, 20 | { 21 | subnet_name = "subnet-asia" 22 | subnet_ip = "10.10.20.0/24" 23 | subnet_region = "asia-east1" 24 | } 25 | ] 26 | } 27 | 28 | # Firewall 29 | resource "google_compute_firewall" "fw-dev" { 30 | name = "fw-dev" 31 | network = module.vpc.network_self_link 32 | allow { 33 | protocol = "tcp" 34 | ports = ["22"] 35 | } 36 | source_ranges = ["0.0.0.0/0"] 37 | } 38 | 39 | resource "google_compute_firewall" "fw-lb" { 40 | name = "fw-lb" 41 | network = module.vpc.network_self_link 42 | allow { 43 | protocol = "tcp" 44 | ports = ["80", "443"] 45 | } 46 | source_ranges = ["130.211.0.0/22", "35.191.0.0/16"] 47 | } 48 | 49 | 50 | # Infos da subnet 51 | # Preciso registrar o self_link das subnets corretamente, como estou usando modulo 52 | # estou buscando por um datasource. 53 | data "google_compute_subnetwork" "subnet-us" { 54 | name = "subnet-us" 55 | region = "us-central1" 56 | depends_on = [module.vpc] 57 | } 58 | 59 | data "google_compute_subnetwork" "subnet-asia" { 60 | name = "subnet-asia" 61 | region = "asia-east1" 62 | depends_on = [module.vpc] 63 | } 64 | 65 | # Templates 66 | module "instance-template-us" { 67 | source = "./mod-template-mig" 68 | name = "us" 69 | metadata_startup_script = "./scripts/us.sh" 70 | network = module.vpc.network_self_link 71 | subnetwork = data.google_compute_subnetwork.subnet-us.self_link 72 | } 73 | 74 | module "instance-template-asia" { 75 | source = "./mod-template-mig" 76 | name = "asia" 77 | metadata_startup_script = "./scripts/asia.sh" 78 | network = module.vpc.network_self_link 79 | subnetwork = data.google_compute_subnetwork.subnet-asia.self_link 80 | } 81 | 82 | # Instance Groups 83 | module "mig-us" { 84 | source = "./mod-mig" 85 | name = "mig-us" 86 | base_instance_name = "us-web" 87 | region = "us-central1" 88 | instance_template = module.instance-template-us.self_link 89 | distribution_policy_zones = ["us-central1-a", "us-central1-b"] 90 | resource_depends_on = [module.vpc] 91 | } 92 | 93 | module "mig-asia" { 94 | source = "./mod-mig" 95 | name = "mig-asia" 96 | base_instance_name = "asia-web" 97 | region = "asia-east1" 98 | instance_template = module.instance-template-asia.self_link 99 | distribution_policy_zones = ["asia-east1-a"] 100 | resource_depends_on = [module.vpc] 101 | } 102 | 103 | # Loadbalance 104 | module "mod-lb" { 105 | source = "./mod-lb" 106 | backends = [ 107 | module.mig-us.instance_group, 108 | module.mig-asia.instance_group 109 | ] 110 | } 111 | 112 | output "lb-ip" { 113 | value = module.mod-lb.ip 114 | } 115 | 116 | 117 | # Demo count + if 118 | 119 | resource "google_compute_instance" "bastion" { 120 | count = terraform.workspace == "prd" ? 3 : 2 121 | name = format("%s-%s", "bastion", count.index) 122 | machine_type = "e2-medium" 123 | zone = "us-central1-a" 124 | 125 | boot_disk { 126 | initialize_params { 127 | image = "debian-cloud/debian-10" 128 | } 129 | } 130 | 131 | network_interface { 132 | subnetwork = data.google_compute_subnetwork.subnet-us.self_link 133 | 134 | access_config { 135 | // Ephemeral IP 136 | } 137 | } 138 | } 139 | 140 | -------------------------------------------------------------------------------- /mod-lb/main.tf: -------------------------------------------------------------------------------- 1 | resource "google_compute_global_forwarding_rule" "default" { 2 | name = "global-rule" 3 | target = google_compute_target_http_proxy.default.self_link 4 | port_range = "80" 5 | } 6 | 7 | resource "google_compute_target_http_proxy" "default" { 8 | name = "target-proxy" 9 | url_map = google_compute_url_map.default.self_link 10 | } 11 | 12 | resource "google_compute_url_map" "default" { 13 | name = "url-map-target-proxy" 14 | default_service = google_compute_backend_service.default.self_link 15 | } 16 | 17 | resource "google_compute_backend_service" "default" { 18 | name = "backend" 19 | port_name = "http" 20 | protocol = "HTTP" 21 | timeout_sec = 10 22 | # Implementacao seguindo o provider da GCP 23 | dynamic "backend" { 24 | for_each = var.backends 25 | content { 26 | group = backend.value 27 | # Garante que vai alternar mais rapidamente entre as instancais 28 | balancing_mode = var.balancing_mode 29 | max_rate_per_instance = 1 30 | } 31 | } 32 | # Implementacao se fosse seguir a API REST 33 | #backend { 34 | # group = module.mig-us.self_link, 35 | # group = module.mig-asia.self_link 36 | # } 37 | health_checks = [google_compute_http_health_check.default.self_link] 38 | } 39 | 40 | resource "google_compute_http_health_check" "default" { 41 | name = "check-backend" 42 | request_path = "/" 43 | check_interval_sec = 1 44 | timeout_sec = 1 45 | } 46 | -------------------------------------------------------------------------------- /mod-lb/outputs.tf: -------------------------------------------------------------------------------- 1 | output "ip" { 2 | value = google_compute_global_forwarding_rule.default.ip_address 3 | description = "IP do LB" 4 | } 5 | -------------------------------------------------------------------------------- /mod-lb/variables.tf: -------------------------------------------------------------------------------- 1 | variable "balancing_mode" { 2 | type = string 3 | description = "Balancing mode" 4 | default = "RATE" 5 | } 6 | 7 | variable "backends" { 8 | type = list 9 | description = "Backend config" 10 | } 11 | -------------------------------------------------------------------------------- /mod-mig/main.tf: -------------------------------------------------------------------------------- 1 | resource "google_compute_region_instance_group_manager" "this" { 2 | name = var.name 3 | 4 | base_instance_name = var.base_instance_name 5 | region = var.region 6 | distribution_policy_zones = var.distribution_policy_zones 7 | 8 | version { 9 | instance_template = var.instance_template 10 | } 11 | 12 | # Pega a quantidade de zonas, e sobe 1 maquina em cada 13 | target_size = length(var.distribution_policy_zones) 14 | 15 | # Forca a dependencia na subnet, evitando problemas na hora do destroy 16 | depends_on = [var.resource_depends_on] 17 | } 18 | -------------------------------------------------------------------------------- /mod-mig/output.tf: -------------------------------------------------------------------------------- 1 | output "instance_group" { 2 | value = google_compute_region_instance_group_manager.this.instance_group 3 | description = "URL do MIG" 4 | } 5 | 6 | output "self_link" { 7 | value = google_compute_region_instance_group_manager.this.self_link 8 | description = "Self link do MIG" 9 | } 10 | -------------------------------------------------------------------------------- /mod-mig/variables.tf: -------------------------------------------------------------------------------- 1 | variable "name" { 2 | type = string 3 | description = "Nome do grupo" 4 | } 5 | 6 | variable "base_instance_name" { 7 | type = string 8 | description = "Prefixo das instancias" 9 | } 10 | 11 | variable "region" { 12 | type = string 13 | description = "Região" 14 | } 15 | 16 | variable "distribution_policy_zones" { 17 | type = list(string) 18 | description = "Zonas do grupo" 19 | } 20 | 21 | variable "instance_template" { 22 | type = string 23 | description = "Self link do template" 24 | } 25 | 26 | variable "resource_depends_on" { 27 | type = any 28 | description = "Depends_on do modulo" 29 | default = null 30 | } 31 | -------------------------------------------------------------------------------- /mod-template-mig/main.tf: -------------------------------------------------------------------------------- 1 | resource "google_compute_instance_template" "this" { 2 | name_prefix = var.name 3 | description = var.desc 4 | 5 | tags = var.tags 6 | 7 | labels = { 8 | environment = terraform.workspace 9 | } 10 | 11 | instance_description = var.instance_description 12 | machine_type = var.machine_type 13 | can_ip_forward = var.can_ip_forward 14 | 15 | scheduling { 16 | automatic_restart = var.automatic_restart 17 | on_host_maintenance = var.on_host_maintenance 18 | } 19 | 20 | disk { 21 | source_image = var.source_image 22 | auto_delete = var.auto_delete 23 | boot = var.boot 24 | } 25 | 26 | lifecycle { 27 | create_before_destroy = true 28 | } 29 | 30 | network_interface { 31 | network = var.network 32 | subnetwork = var.subnetwork 33 | # Como teste, habilitar ips externos nas maquinas tambem 34 | # Mundo real, nao seria necessario, o loadbalance iria bater direto nas instancias 35 | # e caso fosse necessario efetuar SSH nas maquinas bastava criar uma instancia na mesma rede com 36 | # acesso de rede externo 37 | access_config { 38 | // Ephemeral IP 39 | } 40 | } 41 | 42 | metadata_startup_script = file(var.metadata_startup_script) 43 | } 44 | -------------------------------------------------------------------------------- /mod-template-mig/output.tf: -------------------------------------------------------------------------------- 1 | output "self_link" { 2 | value = google_compute_instance_template.this.self_link 3 | description = "Self link do MIG" 4 | } 5 | -------------------------------------------------------------------------------- /mod-template-mig/variables.tf: -------------------------------------------------------------------------------- 1 | variable "name" { 2 | type = string 3 | description = "Prefixo do nome do instance template" 4 | } 5 | 6 | variable "desc" { 7 | type = string 8 | default = "" 9 | description = "Descricao do instance template" 10 | } 11 | 12 | variable "machine_type" { 13 | type = string 14 | description = "Tipo de maquina" 15 | default = "f1-micro" 16 | } 17 | 18 | variable "instance_description" { 19 | default = "" 20 | type = string 21 | description = "Descricao da instancia" 22 | } 23 | 24 | variable "labels" { 25 | type = map 26 | description = "Labels da instancia" 27 | default = {} 28 | } 29 | 30 | variable "tags" { 31 | type = list 32 | description = "Tags da instancia" 33 | default = [] 34 | } 35 | 36 | variable "can_ip_forward" { 37 | type = bool 38 | description = "Roteamento de pacotes" 39 | default = false 40 | } 41 | 42 | variable "network" { 43 | type = string 44 | description = "VPC da instancia" 45 | } 46 | 47 | variable "subnetwork" { 48 | type = string 49 | description = "Subnet da instancia" 50 | } 51 | 52 | variable "metadata_startup_script" { 53 | type = string 54 | description = "Caminho do script shell do userdata" 55 | default = null 56 | } 57 | 58 | variable "on_host_maintenance" { 59 | type = string 60 | description = "Host Maintanance da instancia" 61 | default = "MIGRATE" 62 | } 63 | 64 | variable "automatic_restart" { 65 | type = bool 66 | description = "Automatic restart da instancia" 67 | default = true 68 | } 69 | 70 | variable "source_image" { 71 | type = string 72 | description = "Imagem base" 73 | default = "debian-cloud/debian-10" 74 | } 75 | 76 | variable "auto_delete" { 77 | type = bool 78 | description = "Auto delete da instancia" 79 | default = true 80 | } 81 | 82 | variable "boot" { 83 | type = bool 84 | description = "Boot disk" 85 | default = true 86 | } 87 | -------------------------------------------------------------------------------- /old/datasource.tf: -------------------------------------------------------------------------------- 1 | data "google_compute_network" "my-network" { 2 | name = "default" 3 | } 4 | 5 | data "http" "example" { 6 | url = "https://desafiotestes.free.beeceptor.com" 7 | request_headers = { 8 | Accept = "application/json" 9 | } 10 | } 11 | 12 | resource "google_compute_instance" "app" { 13 | name = format("%s-%s", "app", terraform.workspace) 14 | machine_type = "e2-medium" 15 | zone = "southamerica-east1-b" 16 | 17 | metadata = { 18 | api = data.http.example.body 19 | } 20 | 21 | boot_disk { 22 | initialize_params { 23 | image = "debian-cloud/debian-10" 24 | } 25 | } 26 | network_interface { 27 | network = data.google_compute_network.my-network.self_link # "default" 28 | 29 | access_config { 30 | // Ephemeral IP 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /old/machines.tf: -------------------------------------------------------------------------------- 1 | resource "google_compute_instance" "app" { 2 | name = format("%s-%s", "app", terraform.workspace) 3 | machine_type = "e2-medium" 4 | zone = "southamerica-east1-b" 5 | 6 | boot_disk { 7 | initialize_params { 8 | image = "debian-cloud/debian-10" 9 | } 10 | } 11 | 12 | network_interface { 13 | network = "default" 14 | 15 | access_config { 16 | // Ephemeral IP 17 | } 18 | } 19 | 20 | metadata = { 21 | ssh-keys = format("%s:%s", "root", file("chave.pub")) 22 | } 23 | } 24 | 25 | 26 | resource "google_compute_instance" "shell" { 27 | name = format("%s-%s", "shell", terraform.workspace) 28 | machine_type = "e2-medium" 29 | zone = "southamerica-east1-a" 30 | 31 | boot_disk { 32 | initialize_params { 33 | image = "debian-cloud/debian-10" 34 | } 35 | } 36 | 37 | tags = ["shellzao", "app"] 38 | 39 | network_interface { 40 | network = "default" 41 | 42 | access_config { 43 | // Ephemeral IP 44 | } 45 | } 46 | 47 | metadata = { 48 | ssh-keys = format("%s:%s", "root", file("chave.pub")) 49 | } 50 | 51 | provisioner "file" { 52 | source = "./chave" 53 | destination = "/tmp/secret" 54 | connection { 55 | type = "ssh" 56 | user = "root" 57 | host = self.network_interface.0.access_config.0.nat_ip 58 | private_key = file("chave") 59 | } 60 | } 61 | 62 | provisioner "local-exec" { 63 | command = "date > final_provisionamento" 64 | } 65 | 66 | provisioner "remote-exec" { 67 | inline = [ 68 | "cp /tmp/secret /root/.ssh/id_rsa", 69 | "chmod 400 -R /root/.ssh", 70 | "ssh-keygen -y -f /root/.ssh/id_rsa > /root/.ssh/id_rsa.pub" 71 | ] 72 | connection { 73 | type = "ssh" 74 | user = "root" 75 | host = self.network_interface.0.access_config.0.nat_ip 76 | private_key = file("chave") 77 | } 78 | } 79 | } 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /old/main.tf: -------------------------------------------------------------------------------- 1 | module "network" { 2 | source = "./modules/network" 3 | vpc_name = "rede" 4 | subnet_name = "sp" 5 | } 6 | 7 | #output "vpc_selflink" { 8 | # description = "" 9 | # #value = google_compute_network.rede.self_link 10 | # value = module.network.vpc_selflink 11 | #} 12 | 13 | resource "google_compute_instance" "app" { 14 | name = format("%s-%s", "app", terraform.workspace) 15 | machine_type = "e2-medium" 16 | zone = "southamerica-east1-b" 17 | 18 | boot_disk { 19 | initialize_params { 20 | image = "debian-cloud/debian-10" 21 | } 22 | } 23 | 24 | network_interface { 25 | subnetwork = module.network.subnet_selflink 26 | 27 | access_config { 28 | // Ephemeral IP 29 | } 30 | } 31 | } 32 | 33 | module "vpc" { 34 | source = "terraform-google-modules/network/google" 35 | version = "3.2.2" 36 | network_name = "rede-prod" 37 | project_id = "rubeus-proxysql" 38 | subnets = [ 39 | { 40 | subnet_name = "subnet-01" 41 | subnet_ip = "10.10.10.0/24" 42 | subnet_region = "us-central1" 43 | }, 44 | { 45 | subnet_name = "subnet-02" 46 | subnet_ip = "10.10.20.0/24" 47 | subnet_region = "asia-east1" 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /old/mod-lb/main.tf: -------------------------------------------------------------------------------- 1 | # Example usage 2 | #module "mod-lb" { 3 | # source = "./mod-lb" 4 | # backends = [ 5 | # module.mig-us.instance_group, 6 | # module.mig-asia.instance_group 7 | # ] 8 | #} 9 | 10 | resource "google_compute_global_forwarding_rule" "default" { 11 | name = "global-rule" 12 | target = google_compute_target_http_proxy.default.self_link 13 | port_range = "80" 14 | } 15 | 16 | resource "google_compute_target_http_proxy" "default" { 17 | name = "target-proxy" 18 | url_map = google_compute_url_map.default.self_link 19 | } 20 | 21 | resource "google_compute_url_map" "default" { 22 | name = "url-map-target-proxy" 23 | default_service = google_compute_backend_service.default.self_link 24 | } 25 | 26 | resource "google_compute_backend_service" "default" { 27 | name = "backend" 28 | port_name = "http" 29 | protocol = "HTTP" 30 | timeout_sec = 10 31 | # Implementacao seguindo o provider da GCP 32 | dynamic "backend" { 33 | for_each = var.backends 34 | content { 35 | group = backend.value 36 | # Garante que vai alternar mais rapidamente entre as instancais 37 | balancing_mode = var.balancing_mode 38 | max_rate_per_instance = 1 39 | } 40 | } 41 | 42 | # Implementacao se fosse seguir a API REST 43 | #backend { 44 | # group = module.mig-us.self_link, 45 | # group = module.mig-asia.self_link 46 | # } 47 | health_checks = [google_compute_http_health_check.default.self_link] 48 | } 49 | 50 | resource "google_compute_http_health_check" "default" { 51 | name = "check-backend" 52 | request_path = "/" 53 | check_interval_sec = 1 54 | timeout_sec = 1 55 | } 56 | -------------------------------------------------------------------------------- /old/mod-lb/outputs.tf: -------------------------------------------------------------------------------- 1 | output "ip" { 2 | value = google_compute_global_forwarding_rule.default.ip_address 3 | description = "IP do LB" 4 | } 5 | -------------------------------------------------------------------------------- /old/mod-lb/variables.tf: -------------------------------------------------------------------------------- 1 | variable "balancing_mode" { 2 | type = string 3 | description = "Balancing mode" 4 | default = "RATE" 5 | } 6 | 7 | variable "backends" { 8 | type = list 9 | description = "Backend config" 10 | } 11 | -------------------------------------------------------------------------------- /old/modules/network/main.tf: -------------------------------------------------------------------------------- 1 | resource "google_compute_network" "rede" { 2 | name = var.vpc_name 3 | auto_create_subnetworks = var.auto_create_subnetworks 4 | } 5 | 6 | resource "google_compute_subnetwork" "subrede" { 7 | name = var.subnet_name 8 | ip_cidr_range = var.subnet_cidr 9 | region = var.subnet_region 10 | network = google_compute_network.rede.self_link 11 | } 12 | 13 | -------------------------------------------------------------------------------- /old/modules/network/outputs.tf: -------------------------------------------------------------------------------- 1 | # self_link subnet 2 | # gateway subnet 3 | # CIDR subnet 4 | # region subnet 5 | 6 | output "vpc_selflink" { 7 | description = "" 8 | value = google_compute_network.rede.self_link 9 | } 10 | output "subnet_selflink" { 11 | description = "" 12 | value = google_compute_subnetwork.subrede.self_link 13 | } 14 | output "subnet_gateway" { 15 | description = "" 16 | value = google_compute_subnetwork.subrede.gateway_address 17 | } 18 | output "subnet_cidr" { 19 | description = "" 20 | value = google_compute_subnetwork.subrede.ip_cidr_range 21 | } 22 | output "subnet_region" { 23 | description = "" 24 | value = google_compute_subnetwork.subrede.region 25 | sensitive = true 26 | } 27 | 28 | -------------------------------------------------------------------------------- /old/modules/network/variables.tf: -------------------------------------------------------------------------------- 1 | variable "vpc_name" { 2 | description = "O nome a ser utilizado para a VPC" 3 | type = string 4 | } 5 | 6 | variable "auto_create_subnetworks" { 7 | description = "" 8 | default = false 9 | type = bool 10 | } 11 | 12 | variable "subnet_name" { 13 | description = "O nome a ser utilizado para a Subnet" 14 | type = string 15 | } 16 | 17 | variable "subnet_cidr" { 18 | description = "" 19 | default = "10.2.0.0/16" 20 | type = string 21 | } 22 | 23 | variable "subnet_region" { 24 | description = "" 25 | default = "southamerica-east1" 26 | type = string 27 | sensitive = true 28 | } 29 | 30 | -------------------------------------------------------------------------------- /provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | google = { 4 | source = "hashicorp/google" 5 | version = "3.69.0" 6 | } 7 | } 8 | backend "gcs" { 9 | bucket = "4linuxstateterraform" 10 | prefix = "terraform/state" 11 | } 12 | } 13 | 14 | provider "google" { 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /scripts/asia.sh: -------------------------------------------------------------------------------- 1 | #/usr/bin/env bash 2 | 3 | ZONE=$(curl http://metadata.google.internal/computeMetadata/v1/instance/zone -H "Metadata-Flavor: Google") 4 | 5 | sudo apt-get update 6 | 7 | sudo apt-get install nginx -y 8 | 9 | sudo cat < /var/www/html/index.html 10 |

Hello from WEB TIER ${ZONE}

11 | EOF 12 | -------------------------------------------------------------------------------- /scripts/us.sh: -------------------------------------------------------------------------------- 1 | #/usr/bin/env bash 2 | 3 | ZONE=$(curl http://metadata.google.internal/computeMetadata/v1/instance/zone -H "Metadata-Flavor: Google") 4 | 5 | sudo apt-get update 6 | 7 | sudo apt-get install nginx -y 8 | 9 | sudo cat < /var/www/html/index.html 10 |

Hello from WEB TIER ${ZONE}

11 | EOF 12 | -------------------------------------------------------------------------------- /state/bucket.tf: -------------------------------------------------------------------------------- 1 | resource "google_storage_bucket" "state" { 2 | name = "4linuxstateterraform" 3 | location = "US" 4 | force_destroy = true 5 | versioning { 6 | enabled = true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /state/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | google = { 4 | source = "hashicorp/google" 5 | version = "3.69.0" 6 | } 7 | } 8 | } 9 | 10 | provider "google" { 11 | # Configuration options 12 | } 13 | --------------------------------------------------------------------------------