Cloud - Terrafom / OpenTofu

Terraform antonomase OpenTofu

Voir :

https://www.morot.fr/infrastructure-as-code-sous-aws-avec-terraform-publie-dans-glmf-216/

https://blog.gruntwork.io/terraform-tips-tricks-loops-if-statements-and-gotchas-f739bbae55f9

https://blog.gruntwork.io/an-introduction-to-terraform-f17df9c6d180

https://wiki.christophchamp.com/index.php?title=Terraform

https://dev.to/anthonylaw/terraform-for-beginner-jak

https://www.redpill-linpro.com/techblog/2018/08/14/getting-started-with-terraform.html

https://medium.com/faun/terraform-remove-element-from-ec2-list-without-destroying-others-when-terraform-plan-again-dbfe1ed291b4

Voir aussi : FIXME2

Pulumi

terraform-clean-syntax

Terragrunt

Notes

Terraform n'est plus un Logiciel Libre. Le Fork libre s'appelle OpenTofu

Install

snap install --classic opentofu
terraform fmt terraform validate
terraform plan -out plan01 terraform apply "plan01"

Pb

EBS volumes destroyed & recreated - Keep EBS without create new topology ?

Voir :

https://github.com/hashicorp/terraform/issues/5006

https://github.com/hashicorp/terraform/issues/3654

https://github.com/terraform-providers/terraform-provider-aws/issues/7796

Erreur : VPCIdNotSpecified: No default VPC for this user status code: 40

example.tf

provider "aws" {
profile = "default"
region = "eu-west-1"
}
resource "aws_instance" "example" {
ami = "ami-01b282b0f06ba5fd2"
instance_type = "t2.micro"
tags = {
Name = "Test-JBL-tf1"
}
}

terraform apply

Erreur

Error: Error launching source instance: VPCIdNotSpecified: No default VPC for this user
status code: 400, request id: c83af246-9715-4d82-a47d-d08a7941c7f6

Solution

example.tf

provider "aws" {
profile = "default"
region = "eu-west-1"
}
resource "aws_instance" "example" {
ami = "ami-01b282b0f06ba5f32"
instance_type = "t2.micro"
vpc_security_group_ids = ["sg-08bc01c0ececbc84f"]
subnet_id = "subnet-0d63fcd2f893bbb5b"
tags = {
Name = "par-web-01"
}
}

Erreur : No suitable endpoint could be found in the service

terraform apply

│ Error: Error creating OpenStack compute client: No suitable endpoint could be found in the service catalog.
│
│ with openstack_compute_keypair_v2.test_keypair,
│ on 10_test.tf line 2, in resource "openstack_compute_keypair_v2" "test_keypair":
│ 2: resource "openstack_compute_keypair_v2" "test_keypair" {

Lister le catalogue ici

openstack catalog list

Mettre la région appropriée

Autres

SFTP TO S3 - AWS Storage Gateway

Voir :

https://docs.aws.amazon.com/fr_fr/storagegateway/latest/userguide/CreatingAnSMBFileShare.html

https://github.com/terraform-providers/terraform-provider-aws/issues/5597

https://github.com/terraform-providers/terraform-provider-aws/issues/6650

https://docs.aws.amazon.com/fr_fr/storagegateway/latest/userguide/get-activation-key.html

https://medium.com/tensult/creating-aws-file-gateway-as-an-nfs-storage-for-your-ec2-instance-57c141c76409

resource "aws_storagegateway_gateway" "example" {
#gateway_ip_address = "1.2.3.4"
#activation_key = ""
gateway_name = "example"
gateway_timezone = "GMT"
gateway_type = "FILE_S3"
smb_guest_password = "pass"
}
resource "aws_storagegateway_smb_file_share" "example" {
authentication = "GuestAccess"
gateway_arn = "${aws_storagegateway_gateway.example.arn}"
location_arn = "${aws_s3_bucket.example.arn}"
role_arn = "${aws_iam_role.example.arn}"
}

Autres

~/.terraforrc

export TF_LOG=1
terraform plan ${VARS} -out="./${ENV}.tfplan" -input=false terraform apply -input=false ${ENV}.tfplan