OpenTofu 란?
OpenTofu는 Terraform의 라이센스 변경에 대한 대응으로 탄생한 오픈소스 프로젝트이다.
Terraform은 2014년에 Mozilla Public License (v2.0) 하에 오픈소스로 공개되었고, 이후 대규모의 사용자, 기여자, 고객, 실무자, 벤더, 그리고 오픈소스 모듈, 플러그인, 라이브러리, 확장 프로그램들로 이루어진 커뮤니티를 구축했다. 그러나 2023년 8월 10일, HashiCorp는 개인 사용자는 Terraform을 재가공하여 사용할 수 있지만, 상업적으로는 사용하지 못하게 하는 정책으로 Terraform의 라이센스를 Mozilla Public License에서 Business Source License (v1.1)로 변경했다. 이는 오픈소스 라이센스가 아니며, OpenTofu는 이러한 변화가 Terraform 주변에 구축된 전체 커뮤니티와 생태계를 위협한다고 본 것이다.
OpenTofu의 목표는 Terraform이 항상 진정한 오픈소스로 남을 수 있도록 하는 것이다. 이를 위해 HashiCorp에 Terraform의 라이센스를 오픈소스로 되돌리라고 요청했으나, 응답이 없자 Terraform의 기존 MPL 라이센스 버전을 포크 하고, 이를 Linux Foundation이 관리하는 OpenTofu라는 이름으로 유지하기로 했다고 한다.
(참고: https://opentofu.org/manifesto/ )
다음은 OpenTofu에 대해 자주 묻는 질문에 대한 답변이다. (FAQ)
Q. OpenTofu와 Terraform의 차이점은 무엇입니까?
|
|
Q. OpenTofu를 Terraform의 즉시 대체품으로 사용할 수 있습니까? 그리고 프로덕션 용도로 적합합니까?
|
|
Q. OpenTofu는 기존 state file과 작동합니까?
|
|
Q. OpenTofu는 Terraform과 협력하는 모든 provider와 함께 작동하나요?
|
|
(외에 다른 질문에 대한 답변 : https://opentofu.org/faq/ )
구성 환경
- Amazon EC2 : 6.1.59-84.139.amzn2023.x86_64
전제 조건
- AWS Credential
- Terraform : v1.6.2
1. Terraform에서 OpenTofu로 마이그레이션
Amazon Linux에 OpenTofu 설치를 위한 repo를 등록한다.
$ cat >/etc/yum.repos.d/opentofu.repo <<EOF
[opentofu]
name=opentofu
baseurl=https://packages.opentofu.org/opentofu/tofu/rpm_any/rpm_any/\$basearch
repo_gpgcheck=0
gpgcheck=1
enabled=1
gpgkey=https://get.opentofu.org/opentofu.gpg
https://packages.opentofu.org/opentofu/tofu/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[opentofu-source]
name=opentofu-source
baseurl=https://packages.opentofu.org/opentofu/tofu/rpm_any/rpm_any/SRPMS
repo_gpgcheck=0
gpgcheck=1
enabled=1
gpgkey=https://get.opentofu.org/opentofu.gpg
https://packages.opentofu.org/opentofu/tofu/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOF
Terraform 버전과 동일한 버전의 OpenTofu를 설치한다.
참고
현재 OpenTofu에서는 Terraform 버전 1.5.x 및 대부분의 1.6.x와 호환되므로 Terraform을 즉시 대체할 수 있다고 한다.
# Terraform 버전 확인
$ terraform version
Terraform v1.6.2
on linux_amd64
# OpenTofu 설치
$ yum install -y tofu-1.6.2
OpenTofu 버전을 확인한다.
$ tofu version
OpenTofu v1.6.2
on linux_amd64
tofu 명령을 실행하기 전 Terraform state file을 백업한다.
$ cp terraform.tfstate terraform.tfstate.terraform
tofu init 명령을 통해 OpenTofu 레지스트리에서 구성에 참조된 모든 provider와 module을 다운로드한다.
$ tofu init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/aws...
- Installing hashicorp/aws v5.44.0...
- Installed hashicorp/aws v5.44.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!
다음 명령을 통해 tofu레지스트리에서 provider가 다운로드되었는지 확인한다.
$ ls -al .terraform/providers/
total 0
#... 생략
drwxr-xr-x. 3 root root 23 Apr 5 07:41 registry.opentofu.org
drwxr-xr-x. 3 root root 23 Apr 5 03:17 registry.terraform.io
$ tofu plan
#... 생략
No changes. Your infrastructure matches the configuration.
OpenTofu has compared your real infrastructure against your configuration and found no differences, so no changes are needed.
# 추가할 ec2 인스턴스 리소스
resource "aws_instance" "ec2_instances2" {
count = var.instance_count
ami = var.ami_id
instance_type = var.instance_type
tags = {
Name = "test-ec2-tofu"
}
}
$ 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:
# aws_instance.ec2_instances2[0] will be created
+ resource "aws_instance" "ec2_instances2" {
+ ami = "ami-xxxxxxxxxxxxx"
#...생략
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
OpenTofu will perform the actions described above.
Only 'yes' will be accepted to approve.
# yes 입력 후 생성
Enter a value: yes
aws_instance.ec2_instances2[0]: Creating...
aws_instance.ec2_instances2[0]: Still creating... [10s elapsed]
aws_instance.ec2_instances2[0]: Still creating... [20s elapsed]
aws_instance.ec2_instances2[0]: Still creating... [30s elapsed]
aws_instance.ec2_instances2[0]: Creation complete after 32s [id=i-0810088d11adba904]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
![](https://blog.kakaocdn.net/dn/dBuEaQ/btsGrb1dt8F/nR5ywpFr7MNTgcY8aJH0Kk/img.jpg)
2. OpenTofu에서 Terraform으로 롤백
$ cp terraform.tfstate terraform.tfstate.tofu
$ terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/aws...
- Reusing previous version of registry.opentofu.org/hashicorp/aws from the dependency lock file
- Installing hashicorp/aws v5.44.0...
- Installed hashicorp/aws v5.44.0 (signed by HashiCorp)
- Using previously-installed registry.opentofu.org/hashicorp/aws v5.44.0
Terraform 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.
Terraform has been successfully initialized!
/*
resource "aws_instance" "ec2_instances2" {
count = var.instance_count
ami = var.ami_id
instance_type = var.instance_type
tags = {
Name = "test-ec2-tofu"
}
}
*/
$ terraform apply
#... 생략
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# aws_instance.ec2_instances2[0] will be destroyed
# (because aws_instance.ec2_instances2 is not in configuration)
- resource "aws_instance" "ec2_instances2" {
- ami = "ami-xxxxxxxx" -> null
#... 생략
Plan: 0 to add, 0 to change, 1 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
aws_instance.ec2_instances2[0]: Destroying... [id=i-0810088d11adba904]
aws_instance.ec2_instances2[0]: Still destroying... [id=i-0810088d11adba904, 10s elapsed]
aws_instance.ec2_instances2[0]: Still destroying... [id=i-0810088d11adba904, 20s elapsed]
aws_instance.ec2_instances2[0]: Still destroying... [id=i-0810088d11adba904, 30s elapsed]
aws_instance.ec2_instances2[0]: Still destroying... [id=i-0810088d11adba904, 40s elapsed]
aws_instance.ec2_instances2[0]: Destruction complete after 40s
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
마무리
OpenTofu는 Terraform의 포크 버전으로써, 기존 Terraform 사용자들이 매우 쉽게 접근할 수 있고 코드를 변경하지 않고도 OpenTofu로의 마이그레이션을 간단히 수행할 수 있다는 장점이 있다. 그러나 아직은 OpenTofu 사용에 관한 다양한 사례가 부족하고, 현재 Terraform과 기능적으로 유사하더라도 향후 서로 다른 방향으로 발전할 가능성이 있음을 고려해야 한다.
특히 마이그레이션 과정에서 예상치 못한 문제가 발생할 수 있으므로, 이에 대비한 충분한 준비와 검토를 거친 후 결정하는 것이 필요할 것 같다.
댓글