Setting up OpenTofu

OpenTofu is a fork of Terraform that is open source, community-driven, and managed by the Linux Foundation. OpenTofu is an infrastructure as code tool that lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share. You can then use a consistent workflow to provision and manage all of your infrastructure throughout its lifecycle. OpenTofu can manage low-level components like compute, storage, and networking resources, as well as high-level components like DNS entries and SaaS features.

  1. OpenTofu is available on Snapcraft; we will install it by running:
snap install --classic opentofu
opentofu 1.6.2 from OpenTofu Core Team installed
  1. Verify by executing :
tofu -version
OpenTofu v1.6.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v5.19.0
  1. Making use of the same main.tf used in the previous exercise, let’s initialize and create the Google Cloud compute engine.
tofu init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/google...
- Installing hashicorp/google v5.19.0...
- Installed hashicorp/google v5.19.0 (signed, key ID 0C0AF313E5FD9F80)
Providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://opentofu.org/docs/cli/plugins/signing/
OpenTofu has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version control system if they represent changes you intended to make.
OpenTofu has been successfully initialized!
You may now begin working with OpenTofu. Try running "tofu plan" to see
any changes that are required for your infrastructure. All OpenTofu commands
should now work.
If you ever set or change modules or backend configuration for OpenTofu,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
  1. Make a plan and apply to create the infrastructure.
tofu plan

OpenTofu used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
+ create
OpenTofu will perform the following actions:
# google_compute_instance.my_instance will be created
+ resource "google_compute_instance" "my_instance" {
+ can_ip_forward = false
+ cpu_platform = (known after apply)
+ current_status = (known after apply)
+ deletion_protection = false
.
.
.
Plan: 1 to add, 0 to change, 0 to destroy.
─────────────────────────────────────────────────────────────────────────────────
─────────────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
Note: You didn't use the -out option to save this plan, so OpenTofu can't
guarantee to take exactly these actions if you run "tofu apply" now.

tofu apply

OpenTofu used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
+ create
OpenTofu will perform the following actions:
# google_compute_instance.my_instance will be created
+ resource "google_compute_instance" "my_instance" {
+ can_ip_forward = false
+ cpu_platform = (known after apply)
+ current_status = (known after apply)
+ deletion_protection = false
..
.
.
.
Do you want to perform these actions?
OpenTofu will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
google_compute_instance.my_instance: Creating...
google_compute_instance.my_instance: Still creating... [10s elapsed]
google_compute_instance.my_instance: Creation complete after 12s
[id=projects/calm-bliss-375608/zones/us-central1-a/instances/my-instance]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Congratulations, you have successfully created the infrastructure using OpenTofu.
  1. Clean up destroying the infrastructure created with a simple command.
tofu destroy

Do you really want to destroy all resources?
OpenTofu will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.
Enter a value: yes
google_compute_instance.my_instance: Destroying...
[id=projects/calm-bliss-375608/zones/us-central1-a/instances/my-instance]
google_compute_instance.my_instance: Still destroying...
[id=projects/calm-bliss-375608/zones/us-central1-a/instances/my-instance, 10s
elapsed]
google_compute_instance.my_instance: Still destroying...
[id=projects/calm-bliss-375608/zones/us-central1-a/instances/my-instance, 20s
elapsed]
google_compute_instance.my_instance: Destruction complete after 21s
Destroy complete! Resources: 1 destroyed.