OpenTofu: Serving Up Infrastructure as Code the Open-Source Way
So, What is OpenTofu…?
The word suggest in name “OpenTofu is the open source infrastructure as code tool.”
Why Should you Swtich to Terraform — — → OpenTofu….?
On August 10,2023, HashiCorp changed from MPL to BUSL license on of their products, including terraform. and the question is Arries now “Terraform” is open source...? so what is the alternatives we can used and it’s also Opensource.
And then, OpenTofu is Launch
OpenTofu is a Terraform fork, created by the initiative of OpenTF supported by Gruntwork, Spacelift, Harness, Env0, Scalr, and others, as a response to HashiCorp’s switch from an open-source license to the BSL. OpenTofu is an open-source version of Terraform and a viable alternative to HashiCorp’s Terraform that will expand on Terraform’s existing concepts and offerings.
OpenTofu was forked from Terraform version 1.5.6. and retained all the features and functionalities that had made Terraform popular among developers, while also introducing improvements and enhancements. The project is now a part of the Linux Foundation, with the ultimate goal of joining the Cloud Native Computing Foundation (CNCF).
If you want more information related this, you can follow the articles.
In this blog we’ll see how to install “OpenTofu” on Ubuntu and how to create resources on “AWS” with the help of OpenTofu“
- Launch EC2 Ubuntu instance “t2.micro” also ok
2. Connect to that ec2 instance and update it
3. Install and Enable snap on ubuntu if you are using ubuntu above 18 snap is already install you are ready to install tofu
sudo apt update
sudo apt install snapd
4. Now lets install “OpenTofu”
sudo snap install opentofu --classic
opentofu.tofu --version
5. Create one directory and go inside that directory
mkdir opentofudemo
cd opentofudemo
6. then create “main.tf” file and we are launch one ec2 instance wit the help of opnetofu and save it
terraform { #this is we tell terraform we config AWS
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
provider "aws" { #give user secret access here
region = "us-east-1"
access_key = "xxxx"
secret_key = "xxxx"
}
resource "aws_instance" "web" { #give instace detail like, ami id and instance type
ami = "ami-06e46074ae430fba6"
instance_type = "t2.micro"
tags = {
Name = "Helloworld"
}
}
7. Now as we do with terraform init just do with tofu
opentofu.tofu init
8. Then run plan command to insure what resource to be created
opentofu.tofu plan
9. and its good to go to create resources
opentofu.tofu apply
10. Go to aws account and check is resources has been created or not.
11. Now destroy what we created
opentofu.tofu destroy