Installation Terraform Centos 8 : sudo yum install -y yum-utils yum-config-mana
Installation Terraform Centos 8 : sudo yum install -y yum-utils yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo sudo dnf repolist sudo yum -y install terraform terraform version Commandes : Terraform init : pour scanner le code Terraform plan : pour créer un plan d’exécution Terraform apply : pour Amélioration : *Main.tf : provider "aws" { region = var.AWS_REGION access_key = var.AWS_ACCESS_KEY secret_key = var.AWS_SECRET_KEY } resource "aws_security_group" "instance_sg" { name = "terraform-test-sg" egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } } resource "aws_instance" "my_ec2_instance" { ami = var.AWS_AMIS[var.AWS_REGION] instance_type = "t2.micro" vpc_security_group_ids = [aws_security_group.instance_sg.id] user_data = <<-EOF #!/bin/bash sudo apt-get update sudo apt-get install -y apache2 sudo systemctl start apache2 sudo systemctl enable apache2 sudo echo "<h1>Hello devopssec</h1>" > /var/www/html/index.html EOF tags = { Name = "terraform test" } } output "public_ip" { value = aws_instance.my_ec2_instance.public_ip } Vars.tf : variable "AWS_ACCESS_KEY" {} variable "AWS_SECRET_KEY" {} variable "AWS_REGION" { default = "us-east-1" } variable "AWS_AMIS" { type = "map" default = { "us-east-1" = "ami-085925f297f89fce1" "us-east-2" = "ami-07c1207a9d40bc3bd" } } terraform.tfvars: AWS_ACCESS_KEY="votre_cle_dacces" AWS_SECRET_KEY="votre_cle_secrete" *Provisionner: -Local-exec: provider "aws" { profile = "default" region = "us-west-2" } resource "aws_instance" "my_ec2" { ami = "ami-06ffade19910cbfc0" instance_type = "t2.micro" } provisioner "local-exec" { command = "echo ${aws_instance.my_ec2.public_ip} > ip_address.txt" } -Remote-exec: provider "aws" { region = "us-west-2" } resource "aws_key_pair" "my_ec2" { key_name = "terraform-key" public_key = file("./terraform.pub") } resource "aws_security_group" "instance_sg" { name = "terraform-test-sg" egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } } resource "aws_instance" "my_ec2" { key_name = aws_key_pair.my_ec2.key_name ami = "ami-06ffade19910cbfc0" instance_type = "t2.micro" vpc_security_group_ids = [aws_security_group.instance_sg.id] connection { type = "ssh" user = "ubuntu" private_key = file("./terraform") host = self.public_ip } provisioner "remote-exec" { inline = [ "sudo apt-get -f -y update", "sudo apt-get install -f -y apache2", "sudo systemctl start apache2", "sudo systemctl enable apache2", "sudo sh -c 'echo \"<h1>Hello devopssec</h1>\" > /var/www/html/index.html'", ] } } -Le provisioner File: provider "aws" { region = "us-west-2" } resource "aws_key_pair" "my_ec2" { key_name = "terraform-key" public_key = file("./terraform.pub") } resource "aws_instance" "my_ec2" { key_name = aws_key_pair.my_ec2.key_name ami = "ami-06ffade19910cbfc0" instance_type = "t2.micro" connection { type = "ssh" user = "ubuntu" private_key = file("./terraform") host = self.public_ip } provisioner "file" { source = "apache2.conf" destination = "/etc/apache2/apache2.conf" } provisioner "file" { content = "Options All -Indexes" destination = "/var/www/html/.htaccess" } } uploads/Ingenierie_Lourd/ installation-terraform-centos-8.pdf
Documents similaires
-
15
-
0
-
0
Licence et utilisation
Gratuit pour un usage personnel Attribution requise- Détails
- Publié le Aoû 04, 2021
- Catégorie Heavy Engineering/...
- Langue French
- Taille du fichier 0.7910MB