V10_11-Terraform Provisioners_Modules
Datasources in Terraform
provider.tf file contents
provider "aws" { region = "us-west-2" access_key = "xyz" secret_key = "xyz" }
main.tf file contents
data "aws_vpc" "vpc_info" { filter { name = "tag:Name" values = ["myvpc"] } } resource "aws_subnet" "main" { vpc_id = data.aws_vpc.vpc_info.id cidr_block = "10.0.2.0/24" tags = { Name = "Subnet-2" } }
Provisioners in Terraform
provider.tf file contents
provider "aws" { region = "us-west-2" access_key = "xyz" secret_key = "xyz" }
main.tf file contents
resource "aws_instance" "web" { ami = "ami-0e5b6b6a9f3db6db8" instance_type = "t2.micro" key_name = "remote_exec" #Create this pem key in aws vpc_security_group_ids = ["sg-groupidnum"] #replace it with sec group id , which should allow 22,80 ports provisioner "remote-exec" { inline = [ "sudo yum install httpd -y", "sudo systemctl start httpd" ] connection { type = "ssh" user = "ec2-user" private_key = file("./remote_exec.pem") #download and place the pem key in the same dir host = self.public_ip } } }
Presentation Link : Terraform_V10-11-Terraform_Datasources_Provisioners
0 Comments