lesson_terraform_cgp_02
Differences
This shows you the differences between two versions of the page.
| lesson_terraform_cgp_02 [2025/07/26 17:09] – - Imported by DokuWiki Advanced Plugin wikiadm | lesson_terraform_cgp_02 [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Lição Terraform GCP 02 ====== | ||
| - | ===== Arquivos ===== | ||
| - | <file tf provider.tf> | ||
| - | terraform { | ||
| - | required_providers { | ||
| - | google = { | ||
| - | source | ||
| - | version = " | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | |||
| - | provider " | ||
| - | credentials = "/ | ||
| - | project | ||
| - | region | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | <file tf network.tf> | ||
| - | resource " | ||
| - | name = " | ||
| - | auto_create_subnetworks = false | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | <file tf firewall.tf> | ||
| - | resource " | ||
| - | name = " | ||
| - | network = google_compute_network.vpc_network.self_link | ||
| - | |||
| - | allow { | ||
| - | protocol = " | ||
| - | } | ||
| - | |||
| - | allow { | ||
| - | protocol = " | ||
| - | ports = [" | ||
| - | } | ||
| - | |||
| - | source_ranges = [" | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | |||
| - | <file tf subnet.tf> | ||
| - | resource " | ||
| - | name = " | ||
| - | ip_cidr_range = " | ||
| - | region | ||
| - | network | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | <file tf disk.tf> | ||
| - | resource " | ||
| - | name = " | ||
| - | type = " | ||
| - | zone = " | ||
| - | size = 30 | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | <file tf instance.tf> | ||
| - | resource " | ||
| - | name = " | ||
| - | machine_type = " | ||
| - | zone = " | ||
| - | |||
| - | boot_disk { | ||
| - | initialize_params { | ||
| - | image = " | ||
| - | } | ||
| - | } | ||
| - | |||
| - | network_interface { | ||
| - | network | ||
| - | subnetwork = google_compute_subnetwork.subnetwork_internal_ipv4.self_link | ||
| - | |||
| - | access_config { | ||
| - | |||
| - | } | ||
| - | } | ||
| - | |||
| - | attached_disk { | ||
| - | source = google_compute_disk.default.self_link | ||
| - | } | ||
| - | |||
| - | allow_stopping_for_update = true | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ===== Levantar a infra ===== | ||
| - | |||
| - | <code bash> | ||
| - | $ terraform init | ||
| - | |||
| - | Initializing the backend... | ||
| - | |||
| - | Initializing provider plugins... | ||
| - | - Reusing previous version of hashicorp/ | ||
| - | - Using previously-installed hashicorp/ | ||
| - | |||
| - | Terraform has been successfully initialized! | ||
| - | |||
| - | You may now begin working with Terraform. Try running " | ||
| - | any changes that are required for your infrastructure. All Terraform commands | ||
| - | should now work. | ||
| - | |||
| - | If you ever set or change modules or backend configuration for Terraform, | ||
| - | rerun this command to reinitialize your working directory. If you forget, other | ||
| - | commands will detect it and remind you to do so if necessary. | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | $ terraform fmt | ||
| - | $ terraform validate | ||
| - | Success! The configuration is valid. | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | $ terraform plan | ||
| - | |||
| - | Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: | ||
| - | + create | ||
| - | |||
| - | Terraform will perform the following actions: | ||
| - | |||
| - | # google_compute_disk.default will be created | ||
| - | + resource " | ||
| - | + creation_timestamp | ||
| - | + id = (known after apply) | ||
| - | + label_fingerprint | ||
| - | + last_attach_timestamp | ||
| - | + last_detach_timestamp | ||
| - | + name = " | ||
| - | + physical_block_size_bytes = (known after apply) | ||
| - | + project | ||
| - | + provisioned_iops | ||
| - | + self_link | ||
| - | + size = 30 | ||
| - | + source_disk_id | ||
| - | + source_image_id | ||
| - | + source_snapshot_id | ||
| - | + type = " | ||
| - | + users = (known after apply) | ||
| - | + zone = " | ||
| - | } | ||
| - | |||
| - | # google_compute_firewall.allow-icmp-ssh will be created | ||
| - | + resource " | ||
| - | + creation_timestamp = (known after apply) | ||
| - | + destination_ranges = (known after apply) | ||
| - | + direction | ||
| - | + enable_logging | ||
| - | + id = (known after apply) | ||
| - | + name = " | ||
| - | + network | ||
| - | + priority | ||
| - | + project | ||
| - | + self_link | ||
| - | + source_ranges | ||
| - | + " | ||
| - | ] | ||
| - | |||
| - | + allow { | ||
| - | + ports = [ | ||
| - | + " | ||
| - | ] | ||
| - | + protocol = " | ||
| - | } | ||
| - | + allow { | ||
| - | + ports = [] | ||
| - | + protocol = " | ||
| - | } | ||
| - | } | ||
| - | |||
| - | # google_compute_instance.default will be created | ||
| - | + resource " | ||
| - | + allow_stopping_for_update = true | ||
| - | + can_ip_forward | ||
| - | + cpu_platform | ||
| - | + current_status | ||
| - | + deletion_protection | ||
| - | + guest_accelerator | ||
| - | + id = (known after apply) | ||
| - | + instance_id | ||
| - | + label_fingerprint | ||
| - | + machine_type | ||
| - | + metadata_fingerprint | ||
| - | + min_cpu_platform | ||
| - | + name = " | ||
| - | + project | ||
| - | + self_link | ||
| - | + tags_fingerprint | ||
| - | + zone = " | ||
| - | |||
| - | + attached_disk { | ||
| - | + device_name | ||
| - | + disk_encryption_key_sha256 = (known after apply) | ||
| - | + kms_key_self_link | ||
| - | + mode = " | ||
| - | + source | ||
| - | } | ||
| - | |||
| - | + boot_disk { | ||
| - | + auto_delete | ||
| - | + device_name | ||
| - | + disk_encryption_key_sha256 = (known after apply) | ||
| - | + kms_key_self_link | ||
| - | + mode = " | ||
| - | + source | ||
| - | |||
| - | + initialize_params { | ||
| - | + image = " | ||
| - | + labels = (known after apply) | ||
| - | + size = (known after apply) | ||
| - | + type = (known after apply) | ||
| - | } | ||
| - | } | ||
| - | |||
| - | + confidential_instance_config { | ||
| - | + enable_confidential_compute = (known after apply) | ||
| - | } | ||
| - | |||
| - | + network_interface { | ||
| - | + ipv6_access_type | ||
| - | + name = (known after apply) | ||
| - | + network | ||
| - | + network_ip | ||
| - | + stack_type | ||
| - | + subnetwork | ||
| - | + subnetwork_project = (known after apply) | ||
| - | } | ||
| - | |||
| - | + reservation_affinity { | ||
| - | + type = (known after apply) | ||
| - | |||
| - | + specific_reservation { | ||
| - | + key = (known after apply) | ||
| - | + values = (known after apply) | ||
| - | } | ||
| - | } | ||
| - | |||
| - | + scheduling { | ||
| - | + automatic_restart | ||
| - | + instance_termination_action = (known after apply) | ||
| - | + min_node_cpus | ||
| - | + on_host_maintenance | ||
| - | + preemptible | ||
| - | + provisioning_model | ||
| - | |||
| - | + node_affinities { | ||
| - | + key = (known after apply) | ||
| - | + operator = (known after apply) | ||
| - | + values | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | |||
| - | # google_compute_network.vpc_network will be created | ||
| - | + resource " | ||
| - | + auto_create_subnetworks | ||
| - | + delete_default_routes_on_create = false | ||
| - | + gateway_ipv4 | ||
| - | + id = (known after apply) | ||
| - | + internal_ipv6_range | ||
| - | + mtu = (known after apply) | ||
| - | + name = " | ||
| - | + project | ||
| - | + routing_mode | ||
| - | + self_link | ||
| - | } | ||
| - | |||
| - | # google_compute_subnetwork.subnetwork_internal_ipv4 will be created | ||
| - | + resource " | ||
| - | + creation_timestamp | ||
| - | + external_ipv6_prefix | ||
| - | + fingerprint | ||
| - | + gateway_address | ||
| - | + id = (known after apply) | ||
| - | + ip_cidr_range | ||
| - | + ipv6_cidr_range | ||
| - | + name = " | ||
| - | + network | ||
| - | + private_ip_google_access | ||
| - | + private_ipv6_google_access = (known after apply) | ||
| - | + project | ||
| - | + purpose | ||
| - | + region | ||
| - | + secondary_ip_range | ||
| - | + self_link | ||
| - | + stack_type | ||
| - | } | ||
| - | |||
| - | Plan: 5 to add, 0 to change, 0 to destroy. | ||
| - | |||
| - | ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | ||
| - | |||
| - | Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run " | ||
| - | now. | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | $ terraform apply -auto-approve | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | $ terraform state list | ||
| - | google_compute_disk.default | ||
| - | google_compute_firewall.allow-icmp-ssh | ||
| - | google_compute_instance.default | ||
| - | google_compute_network.vpc_network | ||
| - | google_compute_subnetwork.subnetwork_internal_ipv4 | ||
| - | </ | ||
| - | |||
| - | ===== Para destruir ===== | ||
| - | <code bash> | ||
| - | $ terraform destroy -auto-approve | ||
| - | </ | ||
| - | ===== Referências ===== | ||
| - | - [[https:// | ||
lesson_terraform_cgp_02.1753560544.txt.gz · Last modified: by wikiadm
