please refer : https://github.com/saikumar-123/elk-rhel/blob/master/graph.svg
Here is the template I am having issues with.
Main.tf - Tries to launch 4 EC2 instances. But all of them need to be executed in sequential order defined in main.tf. I have issues finding the depends_on conditions.
provider “aws” {
region = “us-east-1”
shared_credentials_file = “/home/sai.d/.aws/credentials”
profile = “default”
}
resource “aws_instance” “ansible-elastic” {
ami = “{var.ami_id}"
instance_type = "{var.elastic_instance_type}”
key_name = “{var.key_name}"
subnet_id = "subnet-0de41be2xxxxxxxx"
iam_instance_profile = "ec2_role_for_maagc"
root_block_device {
volume_type= "standard"
volume_size = "30"
}
tags = { Name = "Enabling-elasticsearch" }
security_groups = "{compact(split(”,", var.security_groups[“security_groups”]))}"
provisioner "local-exec" {
command = " echo 'elastic_server_ip: ${aws_instance.ansible-elastic.private_ip}' > elk-vars.yml"
}
provisioner "local-exec" {
command = "ansible-playbook --private-key=/home/sai.d/maagcpoc.pem -u ec2-user -i ${aws_instance.ansible-elastic.private_ip}, playbooks/elastic.yml --extra-vars '@elk-vars.yml'"
}
}
resource “aws_instance” “ansible-kibana” {
ami = “{var.ami_id}"
instance_type = "{var.kibana_instance_type}”
key_name = “{var.key_name}"
subnet_id = "subnet-0de41xxxxxxxxxxx"
iam_instance_profile = "ec2_role_for_maagc"
root_block_device {
volume_type= "standard"
volume_size = "30"
}
tags = { Name = "Enabling-kibana" }
security_groups = "{compact(split(”,", var.security_groups[“security_groups”]))}"
provisioner "local-exec" {
command = " echo 'kibana_server_ip: ${aws_instance.ansible-kibana.private_ip}' > elk-vars.yml"
}
provisioner "local-exec" {
command = "ansible-playbook --private-key=/home/sai.d/maagcpoc.pem -u ec2-user -i ${aws_instance.ansible-logstash.private_ip}, playbooks/kibana.yml --extra-vars '@elk-vars.yml'"
}
depends_on = [aws_instance.ansible-elastic]
}
resource “aws_instance” “ansible-beats” {
ami = “{var.ami_id}"
instance_type = "{var.beats_instance_type}”
key_name = “{var.key_name}"
subnet_id = "subnet-0de41bexxxxxxxxx"
iam_instance_profile = "ec2_role_for_maagc"
root_block_device {
volume_type= "standard"
volume_size = "30"
}
tags = { Name = "Enabling-beats" }
security_groups = "{compact(split(”,", var.security_groups[“security_groups”]))}"
provisioner "local-exec" {
command = " echo 'beats_server_ip: ${aws_instance.ansible-beats.private_ip}' > elk-vars.yml"
}
provisioner "local-exec" {
command = "ansible-playbook --private-key=/home/sai.d/maagcpoc.pem -u ec2-user -i ${aws_instance.ansible-beats.private_ip}, playbooks/beats.yml --extra-vars '@elk-vars.yml'"
}
depends_on = [aws_instance.ansible-elastic,aws_instance.ansible-kibana]
}
resource “aws_instance” “ansible-logstash” {
ami = “{var.ami_id}"
instance_type = "{var.logstash_instance_type}”
key_name = “{var.key_name}"
subnet_id = "subnet-0de41bexxxxxxxxxx"
iam_instance_profile = "ec2_role_for_maagc"
root_block_device {
volume_type= "standard"
volume_size = "30"
}
tags = { Name = "Enabling-logstash" }
security_groups = "{compact(split(”,", var.security_groups[“security_groups”]))}"
provisioner "local-exec" {
command = " echo 'logstash_server_ip: ${aws_instance.ansible-logstash.private_ip}' > elk-vars.yml"
}
provisioner "local-exec" {
command = "ansible-playbook --private-key=/home/sai.d/maagcpoc.pem -u ec2-user -i ${aws_instance.ansible-logstash.private_ip}, playbooks/logstash.yml --extra-vars '@elk-vars.yml'"
}
depends_on = [aws_instance.ansible-elastic,aws_instance.ansible-kibana,aws_instance.ansible-beats]
}