Hi, The thing is I'm going to have such a requirement where I need to create a delphix engine in one server and add a server to the same VPC and subnet. So I'm just trying like this now.
my first tf is:
#VERSION=017
terraform {
required_version = ">= 0.8.2"
}
# Specify the provider and access details
provider "aws" {
region = "${var.aws_region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
}
data "aws_ami" "de_ami" {
most_recent = true
filter {
name = "name"
values = ["Delphix Engine 5.1.4.0 Free Trial"]
}
owners = ["180093685553"]
}
resource "aws_security_group" "landshark" {
name = "${var.instance_name}-${aws_vpc.main.id}"
description = "Allow all inbound traffic"
vpc_id = "${aws_vpc.main.id}"
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["10.0.1.0/24", "${var.your_ip}/32"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags {
Name = "${var.instance_name}-${var.image_base}-allow_all"
}
}
resource "aws_instance" "de" {
instance_type = "m4.xlarge"
ami = "${data.aws_ami.de_ami.id}"
key_name = "${var.key_name}"
vpc_security_group_ids = ["${aws_security_group.landshark.id}"]
subnet_id = "${element(aws_subnet.aw_sub.*.id, 0)}"
private_ip = "10.0.1.10"
#Instance tags
tags {
Name = "${var.instance_name}_${var.image_base}_DE"
}
}
resource "aws_vpc" "main" {
cidr_block = "10.0.1.0/24"
enable_dns_hostnames = true
tags {
Name = "${var.instance_name}_${var.image_base}_vpc"
}
}
resource "aws_route" "r"{
route_table_id = "${aws_vpc.main.main_route_table_id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.main.id}"
}
resource "aws_internet_gateway" "main" {
vpc_id = "${aws_vpc.main.id}"
tags {
Name = "${var.instance_name}_${var.image_base}_ig"
}
}
resource "aws_subnet" "aw_sub" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
tags {
Name = "${var.instance_name}_${var.image_base}_sub}"
}
}
output "DE" {
value = "${
formatlist(
"Delphix Engine - Public IP: %s Private IP: %s\n Access via
http://%s\n Username: delphix_admin Password: landshark",
aws_instance.de.*.public_ip,
aws_instance.de.*.private_ip,
aws_instance.de.*.public_ip
)}"
}
variables declaration from here --- im just leaving them
my second tf is (As I have already created necessary one VPC, subnet, Internet Gateway and route
#VERSION=017
terraform {
required_version = ">= 0.8.2"
}
# Specify the provider and access details
provider "aws" {
region = "${var.aws_region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
}
data "aws_ami" "ls_ami" {
most_recent = true
filter {
name = "name"
values = ["Delphix Oracle 11G Linux Source"]
}
owners = ["180093685553"]
}
resource "aws_security_group" "default" {
vpc_id = "${var.vpc_id}"
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["10.0.1.0/24", "${var.your_ip}/32"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "ls" {
instance_type = "m4.large"
# Lookup the correct AMI based on the region
# we specified
ami = "${data.aws_ami.ls_ami.id}"
connection {
type = "ssh"
user = "centos"
private_key = "${file("${var.key_name}.pem")}"
timeout = "10m"
}
key_name = "${var.key_name}"
# Our Security group to allow HTTP and SSH access
vpc_security_group_ids = ["${aws_security_group.default.id}"]
subnet_id = "${var.subnet_id}"
private_ip = "10.0.1.20"
depends_on = ["aws_internet_gateway.main"]
user_data = "service dbora start"
provisioner "remote-exec" {
inline = [
"sudo cp /usr/bin/tput /usr/bin/tput.bak; sudo cp /dev/null /usr/bin/tput"
]
}
provisioner "remote-exec" {
inline = [
"sudo sed -i -e 's|^MODULE_BASE=.*|MODULE_BASE=GA|' /home/delphix/.ls/config; sleep 60; sudo /u02/app/content/landshark_fetch free_trial -F y"
]
}
provisioner "remote-exec" {
inline = [
"sudo mv /usr/bin/tput.bak /usr/bin/tput"
]
}
#Instance tags
tags {
Name = "${var.instance_name}_${var.image_base}_LS"
}
}
resource "aws_route" "r"{
route_table_id = "rtb-51083135"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "igw-3ca6a459"
}
output "LS" {
value = "${
formatlist(
"Linux Source - Public IP: %s Private IP: %s\n Access via SSH @%s\n Username: delphix Password: delphix\n Prod Employee App:
http://%s:1080";,
aws_instance.ls.*.public_ip,
aws_instance.ls.*.private_ip,
aws_instance.ls.*.public_ip,
aws_instance.ls.*.public_ip
)}"
}
variables declaration here ------ the below two are added by me and given the vpc and subnet details in terraform.tfvars file
variable "vpc_id" {}
variable "subnet_id" {}
Either the internet gateway is modifying itself and destroying the instaces associated with it. In this case, the DE which I created in the first step.
I almost got succeeded at one point, but an error with aws_internet_gateway popped up and ruined everything.