├── .gitignore ├── README.md ├── dia_01 ├── aula_07_comandos_basicos │ ├── .terraform.lock.hcl │ ├── main.tf │ └── provider.tf ├── aula_08_backend │ ├── .terraform.lock.hcl │ ├── main.tf │ └── provider.tf ├── aula_09_expressions │ ├── .terraform.lock.hcl │ ├── main.tf │ └── provider.tf ├── aula_10_providers │ ├── .terraform.lock.hcl │ ├── main.tf │ └── provider.tf └── aula_11_variables │ ├── .terraform.lock.hcl │ ├── main.tf │ ├── provider.tf │ └── variables.tf ├── dia_02 ├── aula_01_state │ ├── .terraform.lock.hcl │ ├── main.tf │ └── provider.tf ├── aula_02_locking_state │ ├── .terraform.lock.hcl │ ├── dynamodb │ │ ├── .terraform.lock.hcl │ │ ├── main.tf │ │ └── provider.tf │ ├── main.tf │ └── provider.tf ├── aula_03_workspace │ ├── .terraform.lock.hcl │ ├── main.tf │ └── provider.tf ├── aula_04_import │ ├── .terraform.lock.hcl │ ├── import.tf │ └── provider.tf ├── aula_05_1_output │ ├── .terraform.lock.hcl │ ├── main.tf │ ├── outputs.tf │ └── provider.tf └── aula_05_2_terraform_remote_state │ ├── .terraform.lock.hcl │ ├── main.tf │ ├── provider.tf │ └── sg.tf ├── dia_03 ├── aula_01_modules │ ├── .terraform.lock.hcl │ ├── instancias │ │ ├── main.tf │ │ ├── outputs.tf │ │ ├── provider.tf │ │ └── variables.tf │ ├── main.tf │ └── outputs.tf ├── aula_02_movendo_state │ ├── .terraform.lock.hcl │ ├── instancias │ │ ├── main.tf │ │ ├── outputs.tf │ │ ├── provider.tf │ │ └── variables.tf │ ├── main.tf │ └── outputs.tf ├── aula_03_functions_locals_count │ ├── .terraform.lock.hcl │ ├── main.tf │ ├── modules │ │ └── groundwork │ │ │ ├── main.tf │ │ │ └── variables.tf │ └── provider.tf └── aula_04_lifecycle_depends_on │ ├── .terraform.lock.hcl │ ├── instancias │ ├── main.tf │ ├── outputs.tf │ ├── provider.tf │ └── variables.tf │ ├── main.tf │ ├── outputs.tf │ └── provider.tf ├── dia_04 ├── aula_03_for_each │ ├── .terraform.lock.hcl │ ├── instancias │ │ ├── main.tf │ │ ├── outputs.tf │ │ ├── provider.tf │ │ └── variables.tf │ ├── main.tf │ ├── outputs.tf │ └── provider.tf ├── magalu_module │ ├── main.tf │ ├── provider.tf │ └── variable.tf └── root_module │ └── dev │ ├── .terraform.lock.hcl │ ├── backend.tf │ └── main.tf ├── dia_05 ├── aula_01_modules_source │ ├── .terraform.lock.hcl │ └── iac │ │ └── terraform │ │ ├── dev │ │ ├── .terraform.lock.hcl │ │ ├── main.tf │ │ └── provider.tf │ │ └── prod │ │ ├── main.tf │ │ └── provider.tf ├── aula_02_conditionals │ ├── .terraform.lock.hcl │ ├── instancias │ │ ├── main.tf │ │ ├── outputs.tf │ │ ├── provider.tf │ │ └── variables.tf │ ├── main.tf │ ├── outputs.tf │ └── provider.tf └── aula_03_for_each │ ├── .terraform.lock.hcl │ ├── instancias │ ├── main.tf │ ├── provider.tf │ └── variables.tf │ ├── main.tf │ └── provider.tf └── dia_06 ├── aula_01_for ├── .terraform.lock.hcl ├── instancias │ ├── main.tf │ ├── outputs.tf │ ├── provider.tf │ └── variables.tf ├── main.tf ├── outputs.tf ├── plan └── provider.tf └── aula_02_dynamic_block ├── .terraform.lock.hcl ├── instancias ├── main.tf ├── outputs.tf ├── provider.tf └── variables.tf ├── main.tf ├── outputs.tf ├── plan └── provider.tf /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/terraform 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=terraform 3 | 4 | ### Terraform ### 5 | # Local .terraform directories 6 | **/.terraform/* 7 | 8 | # .tfstate files 9 | *.tfstate 10 | *.tfstate.* 11 | 12 | # Crash log files 13 | crash.log 14 | crash.*.log 15 | 16 | # Exclude all .tfvars files, which are likely to contain sensitive data, such as 17 | # password, private keys, and other secrets. These should not be part of version 18 | # control as they are data points which are potentially sensitive and subject 19 | # to change depending on the environment. 20 | *.tfvars 21 | *.tfvars.json 22 | 23 | # Ignore override files as they are usually used to override resources locally and so 24 | # are not checked in 25 | override.tf 26 | override.tf.json 27 | *_override.tf 28 | *_override.tf.json 29 | 30 | # Include override files you do wish to add to version control using negated pattern 31 | # !example_override.tf 32 | 33 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 34 | # example: *tfplan* 35 | 36 | # Ignore CLI configuration files 37 | .terraformrc 38 | terraform.rc 39 | 40 | # End of https://www.toptal.com/developers/gitignore/api/terraform 41 | 42 | plano -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # descomplicando_terraform_turma_2024 -------------------------------------------------------------------------------- /dia_01/aula_07_comandos_basicos/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.47.0" 6 | hashes = [ 7 | "h1:T0tupfn2Ubj18Y7xmO0pFMvti1Qns2K6EGXenR6Hg30=", 8 | "zh:06037a14e47e8f82d0b3b326cd188566272b808b7970a9249a11db26d475b83d", 9 | "zh:116b7dd58ca964a1056249d2b6550f399b0a6bc9a7920b7ee134242114432c9f", 10 | "zh:1aa089c81459071c1d65ba7454f1122159e1fa1b5384e6e9ef85c8264f8a9ecb", 11 | "zh:2c1471acba40c4944aa88dda761093c0c969db6408bdc1a4fb62417788cd6bb6", 12 | "zh:3b950bea06ea4bf1ec359a97a4f1745b7efca7fc2da368843666020dd0ebc5d4", 13 | "zh:7191c5c2fce834d584153dcd5269ed3042437f224d341ad85df06b2247bd09b2", 14 | "zh:76d841b3f247f9bb3899dec3b4d871613a4ae8a83a581a827655d34b1bbee0ee", 15 | "zh:7c656ce252fafc2c915dad43a0a7da17dba975207d75841a02f3f2b92d51ec25", 16 | "zh:8ec97118cbdef64139c52b719e4e22443e67a1f37ea1597cd45b2e9b97332a35", 17 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 18 | "zh:a369deca7938236a7da59f7ad1fe18137f736764c9015ed10e88edb6e8505980", 19 | "zh:a743882fb099401eae0c86d9388a6faadbbc27b2ac9477aeef643e5de4eec3f9", 20 | "zh:d5f960f58aff06fc58e244fea6e665800384cacb8cd64a556f8e145b98650372", 21 | "zh:e31ffcfd560132ffbff2f574928ba392e663202a750750ed39a8950031b75623", 22 | "zh:ebd9061b92a772144564f35a63d5a08cb45e14a9d39294fda185f2e0de9c8e28", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /dia_01/aula_07_comandos_basicos/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | } 24 | } -------------------------------------------------------------------------------- /dia_01/aula_07_comandos_basicos/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "~> 5.0" 6 | } 7 | } 8 | } 9 | 10 | # Configure the AWS Provider 11 | provider "aws" { 12 | region = "us-east-2" 13 | } -------------------------------------------------------------------------------- /dia_01/aula_08_backend/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.47.0" 6 | hashes = [ 7 | "h1:T0tupfn2Ubj18Y7xmO0pFMvti1Qns2K6EGXenR6Hg30=", 8 | "zh:06037a14e47e8f82d0b3b326cd188566272b808b7970a9249a11db26d475b83d", 9 | "zh:116b7dd58ca964a1056249d2b6550f399b0a6bc9a7920b7ee134242114432c9f", 10 | "zh:1aa089c81459071c1d65ba7454f1122159e1fa1b5384e6e9ef85c8264f8a9ecb", 11 | "zh:2c1471acba40c4944aa88dda761093c0c969db6408bdc1a4fb62417788cd6bb6", 12 | "zh:3b950bea06ea4bf1ec359a97a4f1745b7efca7fc2da368843666020dd0ebc5d4", 13 | "zh:7191c5c2fce834d584153dcd5269ed3042437f224d341ad85df06b2247bd09b2", 14 | "zh:76d841b3f247f9bb3899dec3b4d871613a4ae8a83a581a827655d34b1bbee0ee", 15 | "zh:7c656ce252fafc2c915dad43a0a7da17dba975207d75841a02f3f2b92d51ec25", 16 | "zh:8ec97118cbdef64139c52b719e4e22443e67a1f37ea1597cd45b2e9b97332a35", 17 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 18 | "zh:a369deca7938236a7da59f7ad1fe18137f736764c9015ed10e88edb6e8505980", 19 | "zh:a743882fb099401eae0c86d9388a6faadbbc27b2ac9477aeef643e5de4eec3f9", 20 | "zh:d5f960f58aff06fc58e244fea6e665800384cacb8cd64a556f8e145b98650372", 21 | "zh:e31ffcfd560132ffbff2f574928ba392e663202a750750ed39a8950031b75623", 22 | "zh:ebd9061b92a772144564f35a63d5a08cb45e14a9d39294fda185f2e0de9c8e28", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /dia_01/aula_08_backend/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | } 24 | } -------------------------------------------------------------------------------- /dia_01/aula_08_backend/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_backend" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-2" 18 | } -------------------------------------------------------------------------------- /dia_01/aula_09_expressions/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.47.0" 6 | hashes = [ 7 | "h1:T0tupfn2Ubj18Y7xmO0pFMvti1Qns2K6EGXenR6Hg30=", 8 | "zh:06037a14e47e8f82d0b3b326cd188566272b808b7970a9249a11db26d475b83d", 9 | "zh:116b7dd58ca964a1056249d2b6550f399b0a6bc9a7920b7ee134242114432c9f", 10 | "zh:1aa089c81459071c1d65ba7454f1122159e1fa1b5384e6e9ef85c8264f8a9ecb", 11 | "zh:2c1471acba40c4944aa88dda761093c0c969db6408bdc1a4fb62417788cd6bb6", 12 | "zh:3b950bea06ea4bf1ec359a97a4f1745b7efca7fc2da368843666020dd0ebc5d4", 13 | "zh:7191c5c2fce834d584153dcd5269ed3042437f224d341ad85df06b2247bd09b2", 14 | "zh:76d841b3f247f9bb3899dec3b4d871613a4ae8a83a581a827655d34b1bbee0ee", 15 | "zh:7c656ce252fafc2c915dad43a0a7da17dba975207d75841a02f3f2b92d51ec25", 16 | "zh:8ec97118cbdef64139c52b719e4e22443e67a1f37ea1597cd45b2e9b97332a35", 17 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 18 | "zh:a369deca7938236a7da59f7ad1fe18137f736764c9015ed10e88edb6e8505980", 19 | "zh:a743882fb099401eae0c86d9388a6faadbbc27b2ac9477aeef643e5de4eec3f9", 20 | "zh:d5f960f58aff06fc58e244fea6e665800384cacb8cd64a556f8e145b98650372", 21 | "zh:e31ffcfd560132ffbff2f574928ba392e663202a750750ed39a8950031b75623", 22 | "zh:ebd9061b92a772144564f35a63d5a08cb45e14a9d39294fda185f2e0de9c8e28", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /dia_01/aula_09_expressions/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | Env = "develop" 24 | } 25 | } -------------------------------------------------------------------------------- /dia_01/aula_09_expressions/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_backend" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-2" 18 | } -------------------------------------------------------------------------------- /dia_01/aula_10_providers/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.47.0" 6 | hashes = [ 7 | "h1:T0tupfn2Ubj18Y7xmO0pFMvti1Qns2K6EGXenR6Hg30=", 8 | "zh:06037a14e47e8f82d0b3b326cd188566272b808b7970a9249a11db26d475b83d", 9 | "zh:116b7dd58ca964a1056249d2b6550f399b0a6bc9a7920b7ee134242114432c9f", 10 | "zh:1aa089c81459071c1d65ba7454f1122159e1fa1b5384e6e9ef85c8264f8a9ecb", 11 | "zh:2c1471acba40c4944aa88dda761093c0c969db6408bdc1a4fb62417788cd6bb6", 12 | "zh:3b950bea06ea4bf1ec359a97a4f1745b7efca7fc2da368843666020dd0ebc5d4", 13 | "zh:7191c5c2fce834d584153dcd5269ed3042437f224d341ad85df06b2247bd09b2", 14 | "zh:76d841b3f247f9bb3899dec3b4d871613a4ae8a83a581a827655d34b1bbee0ee", 15 | "zh:7c656ce252fafc2c915dad43a0a7da17dba975207d75841a02f3f2b92d51ec25", 16 | "zh:8ec97118cbdef64139c52b719e4e22443e67a1f37ea1597cd45b2e9b97332a35", 17 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 18 | "zh:a369deca7938236a7da59f7ad1fe18137f736764c9015ed10e88edb6e8505980", 19 | "zh:a743882fb099401eae0c86d9388a6faadbbc27b2ac9477aeef643e5de4eec3f9", 20 | "zh:d5f960f58aff06fc58e244fea6e665800384cacb8cd64a556f8e145b98650372", 21 | "zh:e31ffcfd560132ffbff2f574928ba392e663202a750750ed39a8950031b75623", 22 | "zh:ebd9061b92a772144564f35a63d5a08cb45e14a9d39294fda185f2e0de9c8e28", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /dia_01/aula_10_providers/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | Env = "develop" 24 | } 25 | } 26 | 27 | resource "aws_instance" "webwest" { 28 | ami = data.aws_ami.ubuntu.id 29 | instance_type = "t3.micro" 30 | provider = aws.west 31 | 32 | tags = { 33 | Name = "HelloWorld" 34 | Env = "develop" 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /dia_01/aula_10_providers/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_backend" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-2" 18 | } 19 | 20 | provider "aws" { 21 | alias = "west" 22 | region = "us-west-2" 23 | } -------------------------------------------------------------------------------- /dia_01/aula_11_variables/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.47.0" 6 | hashes = [ 7 | "h1:T0tupfn2Ubj18Y7xmO0pFMvti1Qns2K6EGXenR6Hg30=", 8 | "zh:06037a14e47e8f82d0b3b326cd188566272b808b7970a9249a11db26d475b83d", 9 | "zh:116b7dd58ca964a1056249d2b6550f399b0a6bc9a7920b7ee134242114432c9f", 10 | "zh:1aa089c81459071c1d65ba7454f1122159e1fa1b5384e6e9ef85c8264f8a9ecb", 11 | "zh:2c1471acba40c4944aa88dda761093c0c969db6408bdc1a4fb62417788cd6bb6", 12 | "zh:3b950bea06ea4bf1ec359a97a4f1745b7efca7fc2da368843666020dd0ebc5d4", 13 | "zh:7191c5c2fce834d584153dcd5269ed3042437f224d341ad85df06b2247bd09b2", 14 | "zh:76d841b3f247f9bb3899dec3b4d871613a4ae8a83a581a827655d34b1bbee0ee", 15 | "zh:7c656ce252fafc2c915dad43a0a7da17dba975207d75841a02f3f2b92d51ec25", 16 | "zh:8ec97118cbdef64139c52b719e4e22443e67a1f37ea1597cd45b2e9b97332a35", 17 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 18 | "zh:a369deca7938236a7da59f7ad1fe18137f736764c9015ed10e88edb6e8505980", 19 | "zh:a743882fb099401eae0c86d9388a6faadbbc27b2ac9477aeef643e5de4eec3f9", 20 | "zh:d5f960f58aff06fc58e244fea6e665800384cacb8cd64a556f8e145b98650372", 21 | "zh:e31ffcfd560132ffbff2f574928ba392e663202a750750ed39a8950031b75623", 22 | "zh:ebd9061b92a772144564f35a63d5a08cb45e14a9d39294fda185f2e0de9c8e28", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /dia_01/aula_11_variables/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = var.image_id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | Env = "develop" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /dia_01/aula_11_variables/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_backend" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-2" 18 | } 19 | 20 | provider "aws" { 21 | alias = "west" 22 | region = "us-west-2" 23 | } -------------------------------------------------------------------------------- /dia_01/aula_11_variables/variables.tf: -------------------------------------------------------------------------------- 1 | variable "image_id" { 2 | type = string 3 | description = "O ID da AMI usada" 4 | validation { 5 | condition = length(var.image_id) > 4 && substr(var.image_id, 0, 4) == "ami-" 6 | error_message = "O valor passado para variavel image_id precisa começar com ami-" 7 | } 8 | sensitive = false 9 | } -------------------------------------------------------------------------------- /dia_02/aula_01_state/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.47.0" 6 | hashes = [ 7 | "h1:T0tupfn2Ubj18Y7xmO0pFMvti1Qns2K6EGXenR6Hg30=", 8 | "zh:06037a14e47e8f82d0b3b326cd188566272b808b7970a9249a11db26d475b83d", 9 | "zh:116b7dd58ca964a1056249d2b6550f399b0a6bc9a7920b7ee134242114432c9f", 10 | "zh:1aa089c81459071c1d65ba7454f1122159e1fa1b5384e6e9ef85c8264f8a9ecb", 11 | "zh:2c1471acba40c4944aa88dda761093c0c969db6408bdc1a4fb62417788cd6bb6", 12 | "zh:3b950bea06ea4bf1ec359a97a4f1745b7efca7fc2da368843666020dd0ebc5d4", 13 | "zh:7191c5c2fce834d584153dcd5269ed3042437f224d341ad85df06b2247bd09b2", 14 | "zh:76d841b3f247f9bb3899dec3b4d871613a4ae8a83a581a827655d34b1bbee0ee", 15 | "zh:7c656ce252fafc2c915dad43a0a7da17dba975207d75841a02f3f2b92d51ec25", 16 | "zh:8ec97118cbdef64139c52b719e4e22443e67a1f37ea1597cd45b2e9b97332a35", 17 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 18 | "zh:a369deca7938236a7da59f7ad1fe18137f736764c9015ed10e88edb6e8505980", 19 | "zh:a743882fb099401eae0c86d9388a6faadbbc27b2ac9477aeef643e5de4eec3f9", 20 | "zh:d5f960f58aff06fc58e244fea6e665800384cacb8cd64a556f8e145b98650372", 21 | "zh:e31ffcfd560132ffbff2f574928ba392e663202a750750ed39a8950031b75623", 22 | "zh:ebd9061b92a772144564f35a63d5a08cb45e14a9d39294fda185f2e0de9c8e28", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /dia_02/aula_01_state/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | Env = "develop" 24 | Plataforma = data.aws_ami.ubuntu.platform_details 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dia_02/aula_01_state/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_backend" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-2" 18 | } 19 | 20 | provider "aws" { 21 | alias = "west" 22 | region = "us-west-2" 23 | } -------------------------------------------------------------------------------- /dia_02/aula_02_locking_state/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.47.0" 6 | hashes = [ 7 | "h1:T0tupfn2Ubj18Y7xmO0pFMvti1Qns2K6EGXenR6Hg30=", 8 | "zh:06037a14e47e8f82d0b3b326cd188566272b808b7970a9249a11db26d475b83d", 9 | "zh:116b7dd58ca964a1056249d2b6550f399b0a6bc9a7920b7ee134242114432c9f", 10 | "zh:1aa089c81459071c1d65ba7454f1122159e1fa1b5384e6e9ef85c8264f8a9ecb", 11 | "zh:2c1471acba40c4944aa88dda761093c0c969db6408bdc1a4fb62417788cd6bb6", 12 | "zh:3b950bea06ea4bf1ec359a97a4f1745b7efca7fc2da368843666020dd0ebc5d4", 13 | "zh:7191c5c2fce834d584153dcd5269ed3042437f224d341ad85df06b2247bd09b2", 14 | "zh:76d841b3f247f9bb3899dec3b4d871613a4ae8a83a581a827655d34b1bbee0ee", 15 | "zh:7c656ce252fafc2c915dad43a0a7da17dba975207d75841a02f3f2b92d51ec25", 16 | "zh:8ec97118cbdef64139c52b719e4e22443e67a1f37ea1597cd45b2e9b97332a35", 17 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 18 | "zh:a369deca7938236a7da59f7ad1fe18137f736764c9015ed10e88edb6e8505980", 19 | "zh:a743882fb099401eae0c86d9388a6faadbbc27b2ac9477aeef643e5de4eec3f9", 20 | "zh:d5f960f58aff06fc58e244fea6e665800384cacb8cd64a556f8e145b98650372", 21 | "zh:e31ffcfd560132ffbff2f574928ba392e663202a750750ed39a8950031b75623", 22 | "zh:ebd9061b92a772144564f35a63d5a08cb45e14a9d39294fda185f2e0de9c8e28", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /dia_02/aula_02_locking_state/dynamodb/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.50.0" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:LevuTzPS4S7t+Vh6Kpz77pBNDAwChaos91/6+CVnD4w=", 9 | "zh:19be42f5a545d6712dee4bdb704b018d23bacf5d902ac3cb061eb1750dfe6a20", 10 | "zh:1d880bdba95ce96efde37e5bcf457a57df2c1effa9b47bc67fa29c1a264ae53b", 11 | "zh:1e9c78e324d7492be5e7744436ed71d66fe4eca3fb6af07a28efd0d1e3bf7640", 12 | "zh:27ac672aa61b3795931561fdbe4a306ad1132af517d7711c14569429b2cc694f", 13 | "zh:3b978423dead02f9a98d25de118adf264a2331acdc4550ea93bed01feabc12e7", 14 | "zh:490d7eb4b922ba1b57e0ab8dec1a08df6517485febcab1e091fd6011281c3472", 15 | "zh:64e7c84e18dac1af5778d6f516e01a46f9c91d710867c39fbc7efa3cd972dc62", 16 | "zh:73867ac2956dcdd377121b3aa8fe2e1085e77fae9b61d018f56a863277ea4b6e", 17 | "zh:7ed899d0d5c49f009b445d7816e4bf702d9c48205c24cf884cd2ae0247160455", 18 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 19 | "zh:9b93784b3fb13d08cf95a4131c49b56bf7e1cd35daad6156b3658a89ce6fb58f", 20 | "zh:b29d77eb75de474e46eb47e539c48916628d85599bcf14e5cc500b14a4578e75", 21 | "zh:bbd9cec8ca705452e4a3d21d56474eacb8cc7b1b74b7f310fdea4bdcffebab32", 22 | "zh:c352eb3169efa0e27a29b99a2630e8298710a084453c519caa39e5972ff6d1fc", 23 | "zh:e32f4744b43be1708b309a734e0ac10b5c0f9f92e5849298cf1a90f2b906f6f3", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_02/aula_02_locking_state/dynamodb/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_dynamodb_table" "dynamodb" { 2 | name = "descomplicando-terraform-turma-2024" 3 | hash_key = "LockID" 4 | read_capacity = 20 5 | write_capacity = 20 6 | 7 | attribute { 8 | name = "LockID" 9 | type = "S" 10 | } 11 | } -------------------------------------------------------------------------------- /dia_02/aula_02_locking_state/dynamodb/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_dynamodb" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-1" 18 | } -------------------------------------------------------------------------------- /dia_02/aula_02_locking_state/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | Env = "develop" 24 | Plataforma = data.aws_ami.ubuntu.platform_details 25 | } 26 | } 27 | 28 | resource "aws_instance" "web2" { 29 | ami = data.aws_ami.ubuntu.id 30 | instance_type = "t3.micro" 31 | 32 | tags = { 33 | Name = "HelloWorld" 34 | Env = "develop" 35 | Plataforma = data.aws_ami.ubuntu.platform_details 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /dia_02/aula_02_locking_state/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_backend" 5 | region = "us-east-1" 6 | dynamodb_table = "descomplicando-terraform-turma-2024" 7 | } 8 | required_providers { 9 | aws = { 10 | source = "hashicorp/aws" 11 | version = "~> 5.0" 12 | } 13 | } 14 | } 15 | 16 | # Configure the AWS Provider 17 | provider "aws" { 18 | region = "us-east-1" 19 | } -------------------------------------------------------------------------------- /dia_02/aula_03_workspace/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.47.0" 6 | hashes = [ 7 | "h1:T0tupfn2Ubj18Y7xmO0pFMvti1Qns2K6EGXenR6Hg30=", 8 | "zh:06037a14e47e8f82d0b3b326cd188566272b808b7970a9249a11db26d475b83d", 9 | "zh:116b7dd58ca964a1056249d2b6550f399b0a6bc9a7920b7ee134242114432c9f", 10 | "zh:1aa089c81459071c1d65ba7454f1122159e1fa1b5384e6e9ef85c8264f8a9ecb", 11 | "zh:2c1471acba40c4944aa88dda761093c0c969db6408bdc1a4fb62417788cd6bb6", 12 | "zh:3b950bea06ea4bf1ec359a97a4f1745b7efca7fc2da368843666020dd0ebc5d4", 13 | "zh:7191c5c2fce834d584153dcd5269ed3042437f224d341ad85df06b2247bd09b2", 14 | "zh:76d841b3f247f9bb3899dec3b4d871613a4ae8a83a581a827655d34b1bbee0ee", 15 | "zh:7c656ce252fafc2c915dad43a0a7da17dba975207d75841a02f3f2b92d51ec25", 16 | "zh:8ec97118cbdef64139c52b719e4e22443e67a1f37ea1597cd45b2e9b97332a35", 17 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 18 | "zh:a369deca7938236a7da59f7ad1fe18137f736764c9015ed10e88edb6e8505980", 19 | "zh:a743882fb099401eae0c86d9388a6faadbbc27b2ac9477aeef643e5de4eec3f9", 20 | "zh:d5f960f58aff06fc58e244fea6e665800384cacb8cd64a556f8e145b98650372", 21 | "zh:e31ffcfd560132ffbff2f574928ba392e663202a750750ed39a8950031b75623", 22 | "zh:ebd9061b92a772144564f35a63d5a08cb45e14a9d39294fda185f2e0de9c8e28", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /dia_02/aula_03_workspace/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | Env = "develop" 24 | Workspace = terraform.workspace 25 | Plataforma = data.aws_ami.ubuntu.platform_details 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dia_02/aula_03_workspace/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_workspace" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | provider "aws" { 16 | region = "us-east-2" 17 | } -------------------------------------------------------------------------------- /dia_02/aula_04_import/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.50.0" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:LevuTzPS4S7t+Vh6Kpz77pBNDAwChaos91/6+CVnD4w=", 9 | "zh:19be42f5a545d6712dee4bdb704b018d23bacf5d902ac3cb061eb1750dfe6a20", 10 | "zh:1d880bdba95ce96efde37e5bcf457a57df2c1effa9b47bc67fa29c1a264ae53b", 11 | "zh:1e9c78e324d7492be5e7744436ed71d66fe4eca3fb6af07a28efd0d1e3bf7640", 12 | "zh:27ac672aa61b3795931561fdbe4a306ad1132af517d7711c14569429b2cc694f", 13 | "zh:3b978423dead02f9a98d25de118adf264a2331acdc4550ea93bed01feabc12e7", 14 | "zh:490d7eb4b922ba1b57e0ab8dec1a08df6517485febcab1e091fd6011281c3472", 15 | "zh:64e7c84e18dac1af5778d6f516e01a46f9c91d710867c39fbc7efa3cd972dc62", 16 | "zh:73867ac2956dcdd377121b3aa8fe2e1085e77fae9b61d018f56a863277ea4b6e", 17 | "zh:7ed899d0d5c49f009b445d7816e4bf702d9c48205c24cf884cd2ae0247160455", 18 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 19 | "zh:9b93784b3fb13d08cf95a4131c49b56bf7e1cd35daad6156b3658a89ce6fb58f", 20 | "zh:b29d77eb75de474e46eb47e539c48916628d85599bcf14e5cc500b14a4578e75", 21 | "zh:bbd9cec8ca705452e4a3d21d56474eacb8cc7b1b74b7f310fdea4bdcffebab32", 22 | "zh:c352eb3169efa0e27a29b99a2630e8298710a084453c519caa39e5972ff6d1fc", 23 | "zh:e32f4744b43be1708b309a734e0ac10b5c0f9f92e5849298cf1a90f2b906f6f3", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_02/aula_04_import/import.tf: -------------------------------------------------------------------------------- 1 | import { 2 | to = aws_instance.web 3 | id = "i-097f2cdb756716d15" 4 | } 5 | -------------------------------------------------------------------------------- /dia_02/aula_04_import/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_import" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | provider "aws" { 16 | region = "us-east-1" 17 | } -------------------------------------------------------------------------------- /dia_02/aula_05_1_output/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.51.1" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:KY/uPHIa+bHgMOAqoA2BnjIlIDuFRFwbLjLkf1gbeDk=", 9 | "zh:03d524b70ab300d90dc4dccad0c28b18d797b8986722b7a93e40a41500450eaa", 10 | "zh:04dbcb7ab52181a784877c409f6c882df34bda686d8c884d511ebd4abf493f0c", 11 | "zh:2b068f7838e0f3677829258df05d8b9d73fe6434a1a809f8710956cc1c01ea03", 12 | "zh:41a4b1e4adbf7c90015ebff17a719fc08133b8a2c4dcefd2fa281552126e59a8", 13 | "zh:48b1adf57f695a72c88c598f99912171ef7067638fd63fb0c6ad3fa397b3f7c3", 14 | "zh:5c2fb26ecb83adac90d06dcf5f97edbc944824c2821816b1653e1a2b9d37b3c4", 15 | "zh:93df05f53702df829d9b9335e559ad8b313808dbd2fad8b2ff14f176732e693d", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:b5da39898602e44551b56e2803a42d92ea7115e35b1792efbf6649da37ef597b", 18 | "zh:b7ab7f743f864ed8d479a7cb04fd3ce00c376f867ee5b53c4c1acaef6e286c54", 19 | "zh:e7e7b2d8ee486415481a25ac7bdded20bd2897d5dd0790741798f31935b9528d", 20 | "zh:e8008e3f5ef560fd9004d1ed1738f0f53e99b0ce961d967e95fc7c02e5954e4e", 21 | "zh:f1296f648b8608ffa930b52519b00ed01eebedde9fdaf94205b365536e6c3916", 22 | "zh:f8539960fd978a54990740ee984c6f7f743c9c32c7734e2601e92abfe54367e9", 23 | "zh:fd182e6e20bb52982752a5d8c4b16887565f413a9d50d9d394d2c06eea8a195e", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_02/aula_05_1_output/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | Env = "develop" 24 | Plataforma = data.aws_ami.ubuntu.platform_details 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dia_02/aula_05_1_output/outputs.tf: -------------------------------------------------------------------------------- 1 | output "instance_ip_addr" { 2 | value = aws_instance.web.private_ip 3 | } 4 | 5 | -------------------------------------------------------------------------------- /dia_02/aula_05_1_output/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_output" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-1" 18 | } 19 | -------------------------------------------------------------------------------- /dia_02/aula_05_2_terraform_remote_state/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.51.1" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:KY/uPHIa+bHgMOAqoA2BnjIlIDuFRFwbLjLkf1gbeDk=", 9 | "zh:03d524b70ab300d90dc4dccad0c28b18d797b8986722b7a93e40a41500450eaa", 10 | "zh:04dbcb7ab52181a784877c409f6c882df34bda686d8c884d511ebd4abf493f0c", 11 | "zh:2b068f7838e0f3677829258df05d8b9d73fe6434a1a809f8710956cc1c01ea03", 12 | "zh:41a4b1e4adbf7c90015ebff17a719fc08133b8a2c4dcefd2fa281552126e59a8", 13 | "zh:48b1adf57f695a72c88c598f99912171ef7067638fd63fb0c6ad3fa397b3f7c3", 14 | "zh:5c2fb26ecb83adac90d06dcf5f97edbc944824c2821816b1653e1a2b9d37b3c4", 15 | "zh:93df05f53702df829d9b9335e559ad8b313808dbd2fad8b2ff14f176732e693d", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:b5da39898602e44551b56e2803a42d92ea7115e35b1792efbf6649da37ef597b", 18 | "zh:b7ab7f743f864ed8d479a7cb04fd3ce00c376f867ee5b53c4c1acaef6e286c54", 19 | "zh:e7e7b2d8ee486415481a25ac7bdded20bd2897d5dd0790741798f31935b9528d", 20 | "zh:e8008e3f5ef560fd9004d1ed1738f0f53e99b0ce961d967e95fc7c02e5954e4e", 21 | "zh:f1296f648b8608ffa930b52519b00ed01eebedde9fdaf94205b365536e6c3916", 22 | "zh:f8539960fd978a54990740ee984c6f7f743c9c32c7734e2601e92abfe54367e9", 23 | "zh:fd182e6e20bb52982752a5d8c4b16887565f413a9d50d9d394d2c06eea8a195e", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_02/aula_05_2_terraform_remote_state/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = "HelloWorld" 23 | Env = "develop" 24 | Plataforma = data.aws_ami.ubuntu.platform_details 25 | } 26 | } 27 | 28 | data "terraform_remote_state" "aula_output" { 29 | backend = "s3" 30 | config = { 31 | bucket = "descomplicando-terraform-turma-2024" 32 | key = "aula_output" 33 | region = "us-east-1" 34 | } 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /dia_02/aula_05_2_terraform_remote_state/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_output_e_terraform_remote_state" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-1" 18 | } 19 | -------------------------------------------------------------------------------- /dia_02/aula_05_2_terraform_remote_state/sg.tf: -------------------------------------------------------------------------------- 1 | data "aws_vpc" "selected" { 2 | tags = { 3 | Environment = "production" 4 | } 5 | } 6 | 7 | 8 | resource "aws_security_group" "allow_tls" { 9 | name = "allow_tls" 10 | description = "Allow TLS inbound traffic and all outbound traffic" 11 | vpc_id = data.aws_vpc.selected.id 12 | 13 | tags = { 14 | Name = "allow_tls" 15 | } 16 | } 17 | 18 | resource "aws_vpc_security_group_ingress_rule" "allow_tls_ipv4" { 19 | security_group_id = aws_security_group.allow_tls.id 20 | cidr_ipv4 = "${data.terraform_remote_state.aula_output.outputs.instance_ip_addr}/32" 21 | from_port = 443 22 | ip_protocol = "tcp" 23 | to_port = 443 24 | } 25 | 26 | 27 | resource "aws_vpc_security_group_egress_rule" "allow_all_traffic_ipv4" { 28 | security_group_id = aws_security_group.allow_tls.id 29 | cidr_ipv4 = "0.0.0.0/0" 30 | ip_protocol = "-1" # semantically equivalent to all ports 31 | } -------------------------------------------------------------------------------- /dia_03/aula_01_modules/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.51.1" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:KY/uPHIa+bHgMOAqoA2BnjIlIDuFRFwbLjLkf1gbeDk=", 9 | "zh:03d524b70ab300d90dc4dccad0c28b18d797b8986722b7a93e40a41500450eaa", 10 | "zh:04dbcb7ab52181a784877c409f6c882df34bda686d8c884d511ebd4abf493f0c", 11 | "zh:2b068f7838e0f3677829258df05d8b9d73fe6434a1a809f8710956cc1c01ea03", 12 | "zh:41a4b1e4adbf7c90015ebff17a719fc08133b8a2c4dcefd2fa281552126e59a8", 13 | "zh:48b1adf57f695a72c88c598f99912171ef7067638fd63fb0c6ad3fa397b3f7c3", 14 | "zh:5c2fb26ecb83adac90d06dcf5f97edbc944824c2821816b1653e1a2b9d37b3c4", 15 | "zh:93df05f53702df829d9b9335e559ad8b313808dbd2fad8b2ff14f176732e693d", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:b5da39898602e44551b56e2803a42d92ea7115e35b1792efbf6649da37ef597b", 18 | "zh:b7ab7f743f864ed8d479a7cb04fd3ce00c376f867ee5b53c4c1acaef6e286c54", 19 | "zh:e7e7b2d8ee486415481a25ac7bdded20bd2897d5dd0790741798f31935b9528d", 20 | "zh:e8008e3f5ef560fd9004d1ed1738f0f53e99b0ce961d967e95fc7c02e5954e4e", 21 | "zh:f1296f648b8608ffa930b52519b00ed01eebedde9fdaf94205b365536e6c3916", 22 | "zh:f8539960fd978a54990740ee984c6f7f743c9c32c7734e2601e92abfe54367e9", 23 | "zh:fd182e6e20bb52982752a5d8c4b16887565f413a9d50d9d394d2c06eea8a195e", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_03/aula_01_modules/instancias/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = var.nome 23 | Env = var.environment 24 | Plataforma = data.aws_ami.ubuntu.platform_details 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dia_03/aula_01_modules/instancias/outputs.tf: -------------------------------------------------------------------------------- 1 | output "instance_ip_addr" { 2 | value = aws_instance.web.private_ip 3 | } 4 | 5 | -------------------------------------------------------------------------------- /dia_03/aula_01_modules/instancias/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "~> 5.0" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dia_03/aula_01_modules/instancias/variables.tf: -------------------------------------------------------------------------------- 1 | variable "nome" { 2 | type = string 3 | description = "Nome da instancia" 4 | } 5 | 6 | variable "environment" { 7 | type = string 8 | description = "Ambiente da instancia" 9 | default = "dev" 10 | } -------------------------------------------------------------------------------- /dia_03/aula_01_modules/main.tf: -------------------------------------------------------------------------------- 1 | module "projetoa" { 2 | source = "./instancias" 3 | nome = "projetoA" 4 | environment = "Production" 5 | } -------------------------------------------------------------------------------- /dia_03/aula_01_modules/outputs.tf: -------------------------------------------------------------------------------- 1 | output "instance_ip_addr" { 2 | value = module.projetoa.instance_ip_addr 3 | } 4 | 5 | -------------------------------------------------------------------------------- /dia_03/aula_02_movendo_state/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.52.0" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:ucZxfJtHMHBp4Amnk0K3Bdr7Umbk6he8byey/+u41Lc=", 9 | "zh:22c4599d47cd59e5519c52afc528fa2aec43b4434f369870ee2806daa071449d", 10 | "zh:3c2edc482662a654f84db4cd3f2cdd8f200147207d053d2e95082744b7814e6d", 11 | "zh:57edc36f908c64de37e92a978f3d675604315a725268da936fcd1e270199db47", 12 | "zh:79e7afd5fb161f2eb2b7f8e7fd5cbb7f56a2c64f141b56f511ec69337ad3e96b", 13 | "zh:82c6ae9a7f971b6ee8c476b6eb7f1be9d24ddd183cbf025f52628084ddb3a5ae", 14 | "zh:92faecc0a8f573f57f37d24415862380a40341eb13d66beb738dd0873899a58e", 15 | "zh:963d3c0e1aa22c872cd96f04ceb41c388137b972f714efbde989221bf7f6f723", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:af6d3bb94aa8a84d740e3731d2379cc5e12aa48d5db0f7489c4639f3814a22d7", 18 | "zh:b9f7aceeaf5daf71394eab9bf0f9f56fdc762cac90e4d62e63aa3fcdf6c1c127", 19 | "zh:c3dcfc2569edae4f36b798c76da7f7633e7bf322505d447d7c370a56c2a30dd2", 20 | "zh:c8abb21c5ceba857f0eaff9e531d781dc655f8cdfae1cf056066daae72546a7f", 21 | "zh:d92004a6a2a770d2542fd9c01b685418ab8d7ab422cf2cdce35dde789bc8593c", 22 | "zh:dc794660b1d6d8f26a917e0ffab1875aa75144736875efaa60f29c72bf02afbf", 23 | "zh:df931c4905e35ae43d558f6cda15f05710a7a24ecbb94533f8822e7572126512", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_03/aula_02_movendo_state/instancias/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "this" { 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = var.nome 23 | Env = var.environment 24 | Plataforma = data.aws_ami.ubuntu.platform_details 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dia_03/aula_02_movendo_state/instancias/outputs.tf: -------------------------------------------------------------------------------- 1 | output "instance_ip_addr" { 2 | value = aws_instance.this.private_ip 3 | } 4 | 5 | -------------------------------------------------------------------------------- /dia_03/aula_02_movendo_state/instancias/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "~> 5.0" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dia_03/aula_02_movendo_state/instancias/variables.tf: -------------------------------------------------------------------------------- 1 | variable "nome" { 2 | type = string 3 | description = "Nome da instancia" 4 | } 5 | 6 | variable "environment" { 7 | type = string 8 | description = "Ambiente da instancia" 9 | default = "dev" 10 | } -------------------------------------------------------------------------------- /dia_03/aula_02_movendo_state/main.tf: -------------------------------------------------------------------------------- 1 | module "projetoa" { 2 | source = "./instancias" 3 | nome = "movendo_state" 4 | } 5 | 6 | moved { 7 | from = module.projetoa.aws_instance.web 8 | to = module.projetoa.aws_instance.this 9 | } 10 | -------------------------------------------------------------------------------- /dia_03/aula_02_movendo_state/outputs.tf: -------------------------------------------------------------------------------- 1 | output "instance_ip_addr" { 2 | value = module.projetoa.instance_ip_addr 3 | } 4 | 5 | -------------------------------------------------------------------------------- /dia_03/aula_03_functions_locals_count/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.52.0" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:ucZxfJtHMHBp4Amnk0K3Bdr7Umbk6he8byey/+u41Lc=", 9 | "zh:22c4599d47cd59e5519c52afc528fa2aec43b4434f369870ee2806daa071449d", 10 | "zh:3c2edc482662a654f84db4cd3f2cdd8f200147207d053d2e95082744b7814e6d", 11 | "zh:57edc36f908c64de37e92a978f3d675604315a725268da936fcd1e270199db47", 12 | "zh:79e7afd5fb161f2eb2b7f8e7fd5cbb7f56a2c64f141b56f511ec69337ad3e96b", 13 | "zh:82c6ae9a7f971b6ee8c476b6eb7f1be9d24ddd183cbf025f52628084ddb3a5ae", 14 | "zh:92faecc0a8f573f57f37d24415862380a40341eb13d66beb738dd0873899a58e", 15 | "zh:963d3c0e1aa22c872cd96f04ceb41c388137b972f714efbde989221bf7f6f723", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:af6d3bb94aa8a84d740e3731d2379cc5e12aa48d5db0f7489c4639f3814a22d7", 18 | "zh:b9f7aceeaf5daf71394eab9bf0f9f56fdc762cac90e4d62e63aa3fcdf6c1c127", 19 | "zh:c3dcfc2569edae4f36b798c76da7f7633e7bf322505d447d7c370a56c2a30dd2", 20 | "zh:c8abb21c5ceba857f0eaff9e531d781dc655f8cdfae1cf056066daae72546a7f", 21 | "zh:d92004a6a2a770d2542fd9c01b685418ab8d7ab422cf2cdce35dde789bc8593c", 22 | "zh:dc794660b1d6d8f26a917e0ffab1875aa75144736875efaa60f29c72bf02afbf", 23 | "zh:df931c4905e35ae43d558f6cda15f05710a7a24ecbb94533f8822e7572126512", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_03/aula_03_functions_locals_count/main.tf: -------------------------------------------------------------------------------- 1 | module "groundwork" { 2 | source = "./modules/groundwork" 3 | cidr_block = "10.1.0.0/16" 4 | } -------------------------------------------------------------------------------- /dia_03/aula_03_functions_locals_count/modules/groundwork/main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | cidr_block_subnets = cidrsubnets(aws_vpc.main.cidr_block, 8, 8) 3 | } 4 | 5 | resource "aws_vpc" "main" { 6 | cidr_block = var.cidr_block 7 | } 8 | 9 | resource "aws_subnet" "main" { 10 | count = 2 11 | vpc_id = aws_vpc.main.id 12 | cidr_block = local.cidr_block_subnets[count.index] 13 | 14 | tags = { 15 | Name = "Main" 16 | } 17 | } -------------------------------------------------------------------------------- /dia_03/aula_03_functions_locals_count/modules/groundwork/variables.tf: -------------------------------------------------------------------------------- 1 | variable "cidr_block" { 2 | type = string 3 | description = "Bloco CIDR para criação da VPC" 4 | } -------------------------------------------------------------------------------- /dia_03/aula_03_functions_locals_count/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_functions_locals_count" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-1" 18 | } 19 | -------------------------------------------------------------------------------- /dia_03/aula_04_lifecycle_depends_on/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.52.0" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:ucZxfJtHMHBp4Amnk0K3Bdr7Umbk6he8byey/+u41Lc=", 9 | "zh:22c4599d47cd59e5519c52afc528fa2aec43b4434f369870ee2806daa071449d", 10 | "zh:3c2edc482662a654f84db4cd3f2cdd8f200147207d053d2e95082744b7814e6d", 11 | "zh:57edc36f908c64de37e92a978f3d675604315a725268da936fcd1e270199db47", 12 | "zh:79e7afd5fb161f2eb2b7f8e7fd5cbb7f56a2c64f141b56f511ec69337ad3e96b", 13 | "zh:82c6ae9a7f971b6ee8c476b6eb7f1be9d24ddd183cbf025f52628084ddb3a5ae", 14 | "zh:92faecc0a8f573f57f37d24415862380a40341eb13d66beb738dd0873899a58e", 15 | "zh:963d3c0e1aa22c872cd96f04ceb41c388137b972f714efbde989221bf7f6f723", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:af6d3bb94aa8a84d740e3731d2379cc5e12aa48d5db0f7489c4639f3814a22d7", 18 | "zh:b9f7aceeaf5daf71394eab9bf0f9f56fdc762cac90e4d62e63aa3fcdf6c1c127", 19 | "zh:c3dcfc2569edae4f36b798c76da7f7633e7bf322505d447d7c370a56c2a30dd2", 20 | "zh:c8abb21c5ceba857f0eaff9e531d781dc655f8cdfae1cf056066daae72546a7f", 21 | "zh:d92004a6a2a770d2542fd9c01b685418ab8d7ab422cf2cdce35dde789bc8593c", 22 | "zh:dc794660b1d6d8f26a917e0ffab1875aa75144736875efaa60f29c72bf02afbf", 23 | "zh:df931c4905e35ae43d558f6cda15f05710a7a24ecbb94533f8822e7572126512", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_03/aula_04_lifecycle_depends_on/instancias/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | ami = var.ami 19 | instance_type = "t3.micro" 20 | 21 | tags = { 22 | Name = var.nome 23 | Env = var.environment 24 | Plataforma = data.aws_ami.ubuntu.platform_details 25 | } 26 | 27 | lifecycle { 28 | create_before_destroy = true 29 | ignore_changes = [ 30 | tags, 31 | ] 32 | } 33 | 34 | depends_on = [ 35 | aws_instance.bd 36 | ] 37 | } 38 | 39 | resource "aws_instance" "bd" { 40 | ami = var.ami_bd 41 | instance_type = "t3.micro" 42 | 43 | tags = { 44 | Name = var.nome 45 | Env = var.environment 46 | Plataforma = data.aws_ami.ubuntu.platform_details 47 | } 48 | 49 | lifecycle { 50 | create_before_destroy = true 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /dia_03/aula_04_lifecycle_depends_on/instancias/outputs.tf: -------------------------------------------------------------------------------- 1 | output "instance_ip_addr" { 2 | value = aws_instance.web.private_ip 3 | } 4 | 5 | -------------------------------------------------------------------------------- /dia_03/aula_04_lifecycle_depends_on/instancias/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "~> 5.0" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dia_03/aula_04_lifecycle_depends_on/instancias/variables.tf: -------------------------------------------------------------------------------- 1 | variable "nome" { 2 | type = string 3 | description = "Nome da instancia" 4 | } 5 | 6 | variable "environment" { 7 | type = string 8 | description = "Ambiente da instancia" 9 | default = "dev" 10 | } 11 | 12 | variable "ami" { 13 | type = string 14 | description = "AMI da instancia" 15 | } 16 | 17 | variable "ami_bd" { 18 | type = string 19 | description = "AMI da instancia" 20 | } -------------------------------------------------------------------------------- /dia_03/aula_04_lifecycle_depends_on/main.tf: -------------------------------------------------------------------------------- 1 | module "projetob" { 2 | source = "./instancias" 3 | nome = "projetoA" 4 | environment = "Develop" 5 | ami = "ami-0b6278baa6691172d" 6 | ami_bd = "ami-0e001c9271cf7f3b9" 7 | } -------------------------------------------------------------------------------- /dia_03/aula_04_lifecycle_depends_on/outputs.tf: -------------------------------------------------------------------------------- 1 | output "instance_ip_addr" { 2 | value = module.projetob.instance_ip_addr 3 | } 4 | 5 | -------------------------------------------------------------------------------- /dia_03/aula_04_lifecycle_depends_on/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_mv_lifecycle_dependes_on" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-1" 18 | } 19 | -------------------------------------------------------------------------------- /dia_04/aula_03_for_each/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.51.1" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:KY/uPHIa+bHgMOAqoA2BnjIlIDuFRFwbLjLkf1gbeDk=", 9 | "zh:03d524b70ab300d90dc4dccad0c28b18d797b8986722b7a93e40a41500450eaa", 10 | "zh:04dbcb7ab52181a784877c409f6c882df34bda686d8c884d511ebd4abf493f0c", 11 | "zh:2b068f7838e0f3677829258df05d8b9d73fe6434a1a809f8710956cc1c01ea03", 12 | "zh:41a4b1e4adbf7c90015ebff17a719fc08133b8a2c4dcefd2fa281552126e59a8", 13 | "zh:48b1adf57f695a72c88c598f99912171ef7067638fd63fb0c6ad3fa397b3f7c3", 14 | "zh:5c2fb26ecb83adac90d06dcf5f97edbc944824c2821816b1653e1a2b9d37b3c4", 15 | "zh:93df05f53702df829d9b9335e559ad8b313808dbd2fad8b2ff14f176732e693d", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:b5da39898602e44551b56e2803a42d92ea7115e35b1792efbf6649da37ef597b", 18 | "zh:b7ab7f743f864ed8d479a7cb04fd3ce00c376f867ee5b53c4c1acaef6e286c54", 19 | "zh:e7e7b2d8ee486415481a25ac7bdded20bd2897d5dd0790741798f31935b9528d", 20 | "zh:e8008e3f5ef560fd9004d1ed1738f0f53e99b0ce961d967e95fc7c02e5954e4e", 21 | "zh:f1296f648b8608ffa930b52519b00ed01eebedde9fdaf94205b365536e6c3916", 22 | "zh:f8539960fd978a54990740ee984c6f7f743c9c32c7734e2601e92abfe54367e9", 23 | "zh:fd182e6e20bb52982752a5d8c4b16887565f413a9d50d9d394d2c06eea8a195e", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_04/aula_03_for_each/instancias/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | for_each = var.map_instancias 19 | ami = data.aws_ami.ubuntu.id 20 | instance_type = each.value["instance_type"] 21 | tags = { 22 | Name = each.key 23 | Env = var.environment 24 | Plataforma = data.aws_ami.ubuntu.platform_details 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /dia_04/aula_03_for_each/instancias/outputs.tf: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /dia_04/aula_03_for_each/instancias/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "~> 5.0" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dia_04/aula_03_for_each/instancias/variables.tf: -------------------------------------------------------------------------------- 1 | variable "nome" { 2 | type = string 3 | description = "Nome da instancia" 4 | } 5 | 6 | variable "environment" { 7 | type = string 8 | description = "Ambiente da instancia" 9 | default = "dev" 10 | } 11 | 12 | variable "map_instancias" { 13 | type = map(object({ 14 | instance_type = string 15 | })) 16 | description = "Set de nome das instancias para criação das maquinas" 17 | default = {} 18 | } -------------------------------------------------------------------------------- /dia_04/aula_03_for_each/main.tf: -------------------------------------------------------------------------------- 1 | module "projetoa" { 2 | source = "./instancias" 3 | nome = "projetoA" 4 | environment = "production" 5 | map_instancias = { 6 | web = { 7 | instance_type = "t3.micro" 8 | }, 9 | bd = { 10 | instance_type = "t2.micro" 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /dia_04/aula_03_for_each/outputs.tf: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /dia_04/aula_03_for_each/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_conditional" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-2" 18 | } 19 | 20 | provider "aws" { 21 | alias = "west" 22 | region = "us-west-2" 23 | } -------------------------------------------------------------------------------- /dia_04/magalu_module/main.tf: -------------------------------------------------------------------------------- 1 | resource "mgc_virtual-machine_instances" "basic_instance" { 2 | name = var.name 3 | delete_public_ip = true 4 | ssh_key_name = var.ssh_key_name 5 | 6 | machine_type = { 7 | name = var.machine_type 8 | } 9 | image = { 10 | name = "cloud-ubuntu-22.04 LTS" 11 | } 12 | network = { 13 | associate_public_ip = var.associate_public_ip 14 | } 15 | 16 | } 17 | 18 | resource "mgc_dbaas_instances" "basic_bd" { 19 | engine_id = "mysql8" 20 | flavor_id = "cloud-dbaas-bs1.small" 21 | name = var.name 22 | password = var.db_password 23 | user = var.db_user 24 | volume = { 25 | size = "100" 26 | } 27 | } -------------------------------------------------------------------------------- /dia_04/magalu_module/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | mgc = { 4 | source = "MagaluCloud/mgc" 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /dia_04/magalu_module/variable.tf: -------------------------------------------------------------------------------- 1 | variable "name" { 2 | type = string 3 | description = "Nome do projeto" 4 | } 5 | 6 | variable "environment" { 7 | type = string 8 | description = "Nome do ambiente (ex. dev)" 9 | default = "dev" 10 | } 11 | 12 | variable "ssh_key_name" { 13 | type = string 14 | description = "Nome da chave SSH" 15 | default = "gomex" 16 | } 17 | 18 | variable "machine_type" { 19 | type = string 20 | description = "Nome do tipo da instância" 21 | default = "cloud-bs1.xsmall" 22 | } 23 | 24 | variable "associate_public_ip" { 25 | type = bool 26 | description = "Habilitar ou não o IP público" 27 | default = false 28 | } 29 | 30 | variable "db_password" { 31 | type = string 32 | sensitive = true 33 | description = "Senha para o banco de dados" 34 | } 35 | 36 | variable "db_user" { 37 | type = string 38 | description = "Usuário para o banco de dados" 39 | } -------------------------------------------------------------------------------- /dia_04/root_module/dev/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/magalucloud/mgc" { 5 | version = "0.18.10" 6 | hashes = [ 7 | "h1:W/LhN6IuB1ClTAMLmRupOEtWHNl7oZp+UJFLMmyQ4hs=", 8 | "zh:0ba24f337e177ee258c62f1ebe6004351eed31dcd63bd38aee187b653d327838", 9 | "zh:3c3fb50f3511b5667d2b6b9fa8d2f83ffc568e0d0523d5eafe6af7c0f61728a9", 10 | "zh:64b28f176b4ff320d6e6cc95a9ac43fd758ad155789158ad456b59ebc6b085a8", 11 | "zh:6a50e2a4ac2bc24cf8c300ad8b9c743f642b3f110ffe59181a9e1607e07fc37d", 12 | "zh:761632b5df03693675248daafa30b342a86c71acfca326c09ae363cd33e4a435", 13 | "zh:890df766e9b839623b1f0437355032a3c006226a6c200cd911e15ee1a9014e9f", 14 | "zh:97168bfd748622f0c5b583bd04ae668ddcd312f55f1195597ff8f5e7b01fe998", 15 | "zh:a42199bfaee2c222647bdf6062a02175a590152613979a6d732e860884ac9736", 16 | "zh:efdd13c1b308364f3285e23bd88bd284b53ab101f220a548fb1c7e2bef13eff0", 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /dia_04/root_module/dev/backend.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | mgc = { 4 | source = "MagaluCloud/mgc" 5 | } 6 | } 7 | } 8 | 9 | provider "mgc" { 10 | region = "br-ne1" 11 | } -------------------------------------------------------------------------------- /dia_04/root_module/dev/main.tf: -------------------------------------------------------------------------------- 1 | module "projeto_alpha" { 2 | source = "../../magalu_module" 3 | name = "alpha" 4 | environment = "dev" 5 | ssh_key_name = "gomex" 6 | associate_public_ip = true 7 | db_password = "password" 8 | db_user = "user" 9 | } -------------------------------------------------------------------------------- /dia_05/aula_01_modules_source/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.51.1" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:KY/uPHIa+bHgMOAqoA2BnjIlIDuFRFwbLjLkf1gbeDk=", 9 | "zh:03d524b70ab300d90dc4dccad0c28b18d797b8986722b7a93e40a41500450eaa", 10 | "zh:04dbcb7ab52181a784877c409f6c882df34bda686d8c884d511ebd4abf493f0c", 11 | "zh:2b068f7838e0f3677829258df05d8b9d73fe6434a1a809f8710956cc1c01ea03", 12 | "zh:41a4b1e4adbf7c90015ebff17a719fc08133b8a2c4dcefd2fa281552126e59a8", 13 | "zh:48b1adf57f695a72c88c598f99912171ef7067638fd63fb0c6ad3fa397b3f7c3", 14 | "zh:5c2fb26ecb83adac90d06dcf5f97edbc944824c2821816b1653e1a2b9d37b3c4", 15 | "zh:93df05f53702df829d9b9335e559ad8b313808dbd2fad8b2ff14f176732e693d", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:b5da39898602e44551b56e2803a42d92ea7115e35b1792efbf6649da37ef597b", 18 | "zh:b7ab7f743f864ed8d479a7cb04fd3ce00c376f867ee5b53c4c1acaef6e286c54", 19 | "zh:e7e7b2d8ee486415481a25ac7bdded20bd2897d5dd0790741798f31935b9528d", 20 | "zh:e8008e3f5ef560fd9004d1ed1738f0f53e99b0ce961d967e95fc7c02e5954e4e", 21 | "zh:f1296f648b8608ffa930b52519b00ed01eebedde9fdaf94205b365536e6c3916", 22 | "zh:f8539960fd978a54990740ee984c6f7f743c9c32c7734e2601e92abfe54367e9", 23 | "zh:fd182e6e20bb52982752a5d8c4b16887565f413a9d50d9d394d2c06eea8a195e", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_05/aula_01_modules_source/iac/terraform/dev/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.54.1" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:+aq386lQCaPX7wR6EPf3PPZvCiI6dRwnjb1wR6lNa8E=", 9 | "zh:37c09b9a0a0a2f7854fe52c6adb15f71593810b458a8283ed71d68036af7ba3a", 10 | "zh:42fe11d87723d4e43b9c6224ae6bacdcb53faee8abc58f0fc625a161d1f71cb1", 11 | "zh:57c6dfc46f28c9c2737559bd84acbc05aeae90431e731bb72a0024028a2d2412", 12 | "zh:5ba9665a4ca0e182effd75575b19a4d47383ec02662024b9fe26f78286c36619", 13 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 14 | "zh:b55980be0237644123a02a30b56d4cc03863ef29036c47d6e8ab5429ab45adf5", 15 | "zh:b81e7664f10855a3a6fc234a18b4c4f1456273126a40c41516f2061696fb9870", 16 | "zh:bd09736ffafd92af104c3c34b5add138ae8db4402eb687863ce472ca7e5ff2e2", 17 | "zh:cc2eb1c62fba2a11d1f239e650cc2ae94bcab01c907384dcf2e213a6ee1bd5b2", 18 | "zh:e5dc40205d9cf6f353c0ca532ae29afc6c83928bc9bcca47d74b640d3bb5a38c", 19 | "zh:ebf1acdcd13f10db1b9c85050ddaadc70ab269c47c5a240753362446442d8371", 20 | "zh:f2fc28a4ad94af5e6144a7309286505e3eb7a94d9dc106722b506c372ff7f591", 21 | "zh:f49445e8435944df122aa89853260a2716ba8b73d6a6a70cae1661554926d5a2", 22 | "zh:fc3b5046e60ae7cab20715be23de8436eb12736136fd6d0f0cc1549ebda6cc73", 23 | "zh:fdb98a53500e245a3b5bec077b994da6959dba8fc4eb7534528658d820e06bd5", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_05/aula_01_modules_source/iac/terraform/dev/main.tf: -------------------------------------------------------------------------------- 1 | module "projeto_alpha" { 2 | source = "git@github.com:gomex/modulo_instancias.git?ref=v2.0.0" 3 | nome = var.nome 4 | environment = var.environment 5 | } 6 | 7 | -------------------------------------------------------------------------------- /dia_05/aula_01_modules_source/iac/terraform/dev/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_modules_source_dev" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-1" 18 | } -------------------------------------------------------------------------------- /dia_05/aula_01_modules_source/iac/terraform/prod/main.tf: -------------------------------------------------------------------------------- 1 | module "projetoa" { 2 | source = "git@github.com:gomex/modulo_instancias.git" 3 | nome = "projetoA" 4 | environment = "Production" 5 | } -------------------------------------------------------------------------------- /dia_05/aula_01_modules_source/iac/terraform/prod/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_modules_source" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-1" 18 | } -------------------------------------------------------------------------------- /dia_05/aula_02_conditionals/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.51.1" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:KY/uPHIa+bHgMOAqoA2BnjIlIDuFRFwbLjLkf1gbeDk=", 9 | "zh:03d524b70ab300d90dc4dccad0c28b18d797b8986722b7a93e40a41500450eaa", 10 | "zh:04dbcb7ab52181a784877c409f6c882df34bda686d8c884d511ebd4abf493f0c", 11 | "zh:2b068f7838e0f3677829258df05d8b9d73fe6434a1a809f8710956cc1c01ea03", 12 | "zh:41a4b1e4adbf7c90015ebff17a719fc08133b8a2c4dcefd2fa281552126e59a8", 13 | "zh:48b1adf57f695a72c88c598f99912171ef7067638fd63fb0c6ad3fa397b3f7c3", 14 | "zh:5c2fb26ecb83adac90d06dcf5f97edbc944824c2821816b1653e1a2b9d37b3c4", 15 | "zh:93df05f53702df829d9b9335e559ad8b313808dbd2fad8b2ff14f176732e693d", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:b5da39898602e44551b56e2803a42d92ea7115e35b1792efbf6649da37ef597b", 18 | "zh:b7ab7f743f864ed8d479a7cb04fd3ce00c376f867ee5b53c4c1acaef6e286c54", 19 | "zh:e7e7b2d8ee486415481a25ac7bdded20bd2897d5dd0790741798f31935b9528d", 20 | "zh:e8008e3f5ef560fd9004d1ed1738f0f53e99b0ce961d967e95fc7c02e5954e4e", 21 | "zh:f1296f648b8608ffa930b52519b00ed01eebedde9fdaf94205b365536e6c3916", 22 | "zh:f8539960fd978a54990740ee984c6f7f743c9c32c7734e2601e92abfe54367e9", 23 | "zh:fd182e6e20bb52982752a5d8c4b16887565f413a9d50d9d394d2c06eea8a195e", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_05/aula_02_conditionals/instancias/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | count = var.criar_instancia ? 1 : 0 19 | ami = data.aws_ami.ubuntu.id 20 | instance_type = "t3.micro" 21 | 22 | tags = { 23 | Name = var.nome 24 | Env = var.environment 25 | Plataforma = data.aws_ami.ubuntu.platform_details 26 | } 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /dia_05/aula_02_conditionals/instancias/outputs.tf: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /dia_05/aula_02_conditionals/instancias/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "~> 5.0" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dia_05/aula_02_conditionals/instancias/variables.tf: -------------------------------------------------------------------------------- 1 | variable "nome" { 2 | type = string 3 | description = "Nome da instancia" 4 | } 5 | 6 | variable "environment" { 7 | type = string 8 | description = "Ambiente da instancia" 9 | default = "dev" 10 | } 11 | 12 | variable "criar_instancia" { 13 | type = bool 14 | description = "Opção para criar instancia ou não" 15 | default = false 16 | } -------------------------------------------------------------------------------- /dia_05/aula_02_conditionals/main.tf: -------------------------------------------------------------------------------- 1 | module "projetoa" { 2 | source = "./instancias" 3 | nome = "projetoA" 4 | environment = "production" 5 | criar_instancia = true 6 | } -------------------------------------------------------------------------------- /dia_05/aula_02_conditionals/outputs.tf: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /dia_05/aula_02_conditionals/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_conditional" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-2" 18 | } 19 | 20 | provider "aws" { 21 | alias = "west" 22 | region = "us-west-2" 23 | } -------------------------------------------------------------------------------- /dia_05/aula_03_for_each/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.51.1" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:KY/uPHIa+bHgMOAqoA2BnjIlIDuFRFwbLjLkf1gbeDk=", 9 | "zh:03d524b70ab300d90dc4dccad0c28b18d797b8986722b7a93e40a41500450eaa", 10 | "zh:04dbcb7ab52181a784877c409f6c882df34bda686d8c884d511ebd4abf493f0c", 11 | "zh:2b068f7838e0f3677829258df05d8b9d73fe6434a1a809f8710956cc1c01ea03", 12 | "zh:41a4b1e4adbf7c90015ebff17a719fc08133b8a2c4dcefd2fa281552126e59a8", 13 | "zh:48b1adf57f695a72c88c598f99912171ef7067638fd63fb0c6ad3fa397b3f7c3", 14 | "zh:5c2fb26ecb83adac90d06dcf5f97edbc944824c2821816b1653e1a2b9d37b3c4", 15 | "zh:93df05f53702df829d9b9335e559ad8b313808dbd2fad8b2ff14f176732e693d", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:b5da39898602e44551b56e2803a42d92ea7115e35b1792efbf6649da37ef597b", 18 | "zh:b7ab7f743f864ed8d479a7cb04fd3ce00c376f867ee5b53c4c1acaef6e286c54", 19 | "zh:e7e7b2d8ee486415481a25ac7bdded20bd2897d5dd0790741798f31935b9528d", 20 | "zh:e8008e3f5ef560fd9004d1ed1738f0f53e99b0ce961d967e95fc7c02e5954e4e", 21 | "zh:f1296f648b8608ffa930b52519b00ed01eebedde9fdaf94205b365536e6c3916", 22 | "zh:f8539960fd978a54990740ee984c6f7f743c9c32c7734e2601e92abfe54367e9", 23 | "zh:fd182e6e20bb52982752a5d8c4b16887565f413a9d50d9d394d2c06eea8a195e", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_05/aula_03_for_each/instancias/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "web" { 18 | for_each = var.instancias 19 | ami = data.aws_ami.ubuntu.id 20 | instance_type = each.value["instance_type"] 21 | 22 | tags = { 23 | Name = each.key 24 | Env = each.value["environment"] 25 | Plataforma = data.aws_ami.ubuntu.platform_details 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dia_05/aula_03_for_each/instancias/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "~> 5.0" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dia_05/aula_03_for_each/instancias/variables.tf: -------------------------------------------------------------------------------- 1 | variable "nome" { 2 | type = string 3 | description = "Nome da instancia" 4 | } 5 | 6 | variable "environment" { 7 | type = string 8 | description = "Ambiente da instancia" 9 | default = "dev" 10 | } 11 | 12 | variable "instancias" { 13 | type = map(object({ 14 | instance_type = string 15 | environment = string 16 | }) 17 | ) 18 | description = "Mapa de instancias" 19 | default = {} 20 | } -------------------------------------------------------------------------------- /dia_05/aula_03_for_each/main.tf: -------------------------------------------------------------------------------- 1 | module "projetoa" { 2 | source = "./instancias" 3 | nome = "projetoA" 4 | environment = "production" 5 | instancias = { 6 | web = { 7 | instance_type = "t3.micro" 8 | environment = "dev" 9 | }, 10 | bd = { 11 | instance_type = "t2.micro" 12 | environment = "dev" 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /dia_05/aula_03_for_each/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_for_each" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-2" 18 | } 19 | 20 | provider "aws" { 21 | alias = "west" 22 | region = "us-west-2" 23 | } -------------------------------------------------------------------------------- /dia_06/aula_01_for/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.55.0" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:vChl08zNYLVzuSzfxz3wp3wNSx+vjwl/jPuyPbg59Ks=", 9 | "zh:06fbb1cc4b61b9d6370d391bf7538aa6ef8b60b91c67d125a6be60a70b1d49f0", 10 | "zh:1d52acd2184f379433a0fce2c29d5ed8fc7958d6a9d1b403310dcc36b2a3f626", 11 | "zh:290bbce092f8836a1db530ac86d933cfea27d52b827639974a81bc48dfba8c34", 12 | "zh:3531f2822c2de3ba837381c4ee4816c5b437fd204c07d659526a04d9154a65e8", 13 | "zh:56d70db4c8c6c0ec1b665380b87726275f4ab3665b4b78ac86dc90e1010c0fe3", 14 | "zh:8251d713c0b2c8c51b6858e51c70d083b484342ff9782a88c39e7eaa966c3da2", 15 | "zh:9a7d1f7207e51382a7dd139dfd5786e7e905edf9bf89bbee4b59ad41365e87be", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:a529c78dfc60063289524690af78794e99a768835b88e27cdfec15bc85439f7c", 18 | "zh:b6da1843355db05c5d412126406fd97db2a6ff9edc166b81c1cea2994535b4eb", 19 | "zh:bfc08cd23b1556b3287d1b28ac7f12c7d459471d97a0592bf2579ea68d11bae7", 20 | "zh:c382088faf05894191636b57861069a21de10a5ff4eb8f7cc122e764ccf7a4a8", 21 | "zh:e27f99f389921314ee428b24990d3a829057ce532b2beb33c69387458722edd9", 22 | "zh:ef11285eedb45ffc3fb2ecdfefa206e64eb2760a87fff15c44dee42de9703436", 23 | "zh:fedc4ebee0d6fe196691127004db5d1ff8bd22e3b667a74026bb92c607589b6c", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_06/aula_01_for/instancias/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | 4 | filter { 5 | name = "name" 6 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 7 | } 8 | 9 | filter { 10 | name = "virtualization-type" 11 | values = ["hvm"] 12 | } 13 | 14 | owners = ["099720109477"] # Canonical 15 | } 16 | 17 | resource "aws_instance" "this" { 18 | for_each = var.instancias 19 | ami = data.aws_ami.ubuntu.id 20 | instance_type = each.value["instance_type"] 21 | 22 | tags = { 23 | Name = each.key 24 | Env = each.value["environment"] 25 | Plataforma = data.aws_ami.ubuntu.platform_details 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dia_06/aula_01_for/instancias/outputs.tf: -------------------------------------------------------------------------------- 1 | output "public_ip" { 2 | description = "IPs públicos" 3 | value = { for key, instance in aws_instance.this : instance.tags["Env"] => instance.public_ip... } 4 | } 5 | 6 | -------------------------------------------------------------------------------- /dia_06/aula_01_for/instancias/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "~> 5.0" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dia_06/aula_01_for/instancias/variables.tf: -------------------------------------------------------------------------------- 1 | variable "nome" { 2 | type = string 3 | description = "Nome da instancia" 4 | } 5 | 6 | variable "environment" { 7 | type = string 8 | description = "Ambiente da instancia" 9 | default = "dev" 10 | } 11 | 12 | variable "instancias" { 13 | type = map(object({ 14 | instance_type = string 15 | environment = string 16 | }) 17 | ) 18 | description = "Mapa de instancias" 19 | default = {} 20 | } -------------------------------------------------------------------------------- /dia_06/aula_01_for/main.tf: -------------------------------------------------------------------------------- 1 | module "projetoa" { 2 | source = "./instancias" 3 | nome = "projetoA" 4 | environment = "production" 5 | instancias = { 6 | web = { 7 | instance_type = "t3.micro" 8 | environment = "dev" 9 | }, 10 | bd = { 11 | instance_type = "t2.micro" 12 | environment = "dev" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /dia_06/aula_01_for/outputs.tf: -------------------------------------------------------------------------------- 1 | output "public_ip" { 2 | description = "IPs públicos" 3 | value = module.projetoa.public_ip 4 | } -------------------------------------------------------------------------------- /dia_06/aula_01_for/plan: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gomex/descomplicando_terraform_turma_2024/eb9f03e338c8668c3baef36691d78305611d335e/dia_06/aula_01_for/plan -------------------------------------------------------------------------------- /dia_06/aula_01_for/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_for_test" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-1" 18 | } 19 | -------------------------------------------------------------------------------- /dia_06/aula_02_dynamic_block/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "5.57.0" 6 | constraints = "~> 5.0" 7 | hashes = [ 8 | "h1:KMPhyxoRthbmc11+RbClq5bricmGDICh1NgE3nPjN7U=", 9 | "zh:03761bedb72290599aef0040d3cefb77842f0ef4338673a7e5b53557b0ca4960", 10 | "zh:1c70c050116370688abd239979b06f33c5c8cb7f6e59e89f60cf08ee01666064", 11 | "zh:1cc3b259028a65b2f68ffc25df876bbb0f46d108f262b8ec7c56fc597ac697af", 12 | "zh:3bcdf1415b37f39b71e07d4d92977cf8697f07602382d63687d5f683fee0231a", 13 | "zh:40b1774a2cacc84002ac88ef30fb017c273009456d7a1f9f7c5a4a057041ec75", 14 | "zh:46d51fa066c6441594a1e242c9491cc31dbb2dc85f1acf8bc54ad6faa4de524b", 15 | "zh:550e5635b0cd5d98fa66c2afd5dbb1563a8e019be9f760bd1543fbcca763f0c1", 16 | "zh:7acc8357b5e02ed3eb478125614d049511d6faeb9850c084d6e6519db875f0d1", 17 | "zh:7f7367299811ddf5560a0586e525d57dd52f1a0ca37e42e2c5284308069bf2b6", 18 | "zh:8766cc10c83b1fc2e971c4e645bc4d3c871d4758eb54b0a3216600c66e3db681", 19 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 20 | "zh:a1e85b1fb9004d8ffab7600304e02bce4aa14cea9f0ad77fbd7b84aae6390760", 21 | "zh:bcf2fc83bd9e20e5a930d9d596eb813c319f2b007c620b1818e574c1702eb9a9", 22 | "zh:d2538fcb20dc2afc04b716f67969944eef7f4fc4296410116d5b7af1811100f2", 23 | "zh:e0e47c5d8710bbfcfe4db1cfa81c67e320056006d08063e69640cd2d492c6f64", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /dia_06/aula_02_dynamic_block/instancias/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ami" "ubuntu" { 2 | most_recent = true 3 | owners = ["099720109477"] # Canonical 4 | 5 | dynamic "filter" { 6 | for_each = var.ami_data_filters 7 | iterator = filtro 8 | content { 9 | name = filtro.value["name"] 10 | values = filtro.value["values"] 11 | } 12 | } 13 | 14 | } 15 | 16 | resource "aws_instance" "this" { 17 | for_each = var.instancias 18 | ami = data.aws_ami.ubuntu.id 19 | instance_type = each.value["instance_type"] 20 | 21 | dynamic "ebs_block_device" { 22 | for_each = var.ebs_block_devices 23 | iterator = device 24 | content { 25 | device_name = device.value["device_name"] 26 | encrypted = device.value["encrypted"] 27 | volume_size = device.value["volume_size"] 28 | } 29 | } 30 | 31 | tags = { 32 | Name = each.key 33 | Env = each.value["environment"] 34 | Plataforma = data.aws_ami.ubuntu.platform_details 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /dia_06/aula_02_dynamic_block/instancias/outputs.tf: -------------------------------------------------------------------------------- 1 | output "public_ip" { 2 | description = "IPs públicos" 3 | value = { for key, instance in aws_instance.this : instance.tags["Env"] => instance.public_ip... } 4 | } 5 | 6 | -------------------------------------------------------------------------------- /dia_06/aula_02_dynamic_block/instancias/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | aws = { 4 | source = "hashicorp/aws" 5 | version = "~> 5.0" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dia_06/aula_02_dynamic_block/instancias/variables.tf: -------------------------------------------------------------------------------- 1 | variable "nome" { 2 | type = string 3 | description = "Nome da instancia" 4 | } 5 | 6 | variable "environment" { 7 | type = string 8 | description = "Ambiente da instancia" 9 | default = "dev" 10 | } 11 | 12 | variable "instancias" { 13 | type = map(object({ 14 | instance_type = string 15 | environment = string 16 | }) 17 | ) 18 | description = "Mapa de instancias" 19 | default = {} 20 | } 21 | 22 | variable "ami_data_filters" { 23 | description = "lista de filtros para data ami" 24 | type = list(any) 25 | } 26 | 27 | variable "ebs_block_devices" { 28 | description = "lista de volumes ebs para ser criado e montando na instancia" 29 | type = list(any) 30 | } -------------------------------------------------------------------------------- /dia_06/aula_02_dynamic_block/main.tf: -------------------------------------------------------------------------------- 1 | module "projetoa" { 2 | source = "./instancias" 3 | nome = "projetoA" 4 | environment = "production" 5 | instancias = { 6 | web = { 7 | instance_type = "t3.micro" 8 | environment = "dev" 9 | }, 10 | bd = { 11 | instance_type = "t2.micro" 12 | environment = "dev" 13 | } 14 | } 15 | ami_data_filters = [ 16 | { 17 | name = "name" 18 | values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] 19 | }, 20 | { 21 | name = "virtualization-type" 22 | values = ["hvm"] 23 | } 24 | ] 25 | ebs_block_devices = [ 26 | { 27 | device_name = "/dev/sdh" 28 | encrypted = true 29 | volume_size = 10 30 | }, 31 | { 32 | device_name = "/dev/sdi" 33 | encrypted = true 34 | volume_size = 10 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /dia_06/aula_02_dynamic_block/outputs.tf: -------------------------------------------------------------------------------- 1 | output "public_ip" { 2 | description = "IPs públicos" 3 | value = module.projetoa.public_ip 4 | } -------------------------------------------------------------------------------- /dia_06/aula_02_dynamic_block/plan: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gomex/descomplicando_terraform_turma_2024/eb9f03e338c8668c3baef36691d78305611d335e/dia_06/aula_02_dynamic_block/plan -------------------------------------------------------------------------------- /dia_06/aula_02_dynamic_block/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "s3" { 3 | bucket = "descomplicando-terraform-turma-2024" 4 | key = "aula_dynamic_block" 5 | region = "us-east-1" 6 | } 7 | required_providers { 8 | aws = { 9 | source = "hashicorp/aws" 10 | version = "~> 5.0" 11 | } 12 | } 13 | } 14 | 15 | # Configure the AWS Provider 16 | provider "aws" { 17 | region = "us-east-1" 18 | } 19 | --------------------------------------------------------------------------------