| 1 |
# Specify the provider and access details |
| 2 |
provider "aws" { |
| 3 |
version = "~> 2.0" |
| 4 |
region = "${var.aws_region}" |
| 5 |
} |
| 6 |
|
| 7 |
resource "aws_security_group" "docdbtest" { |
| 8 |
name_prefix = "docdbtest" |
| 9 |
description = "Test mongo driver on docdb" |
| 10 |
vpc_id = "${var.vpc_id}" |
| 11 |
|
| 12 |
ingress { |
| 13 |
from_port = 22 |
| 14 |
to_port = 22 |
| 15 |
protocol = "tcp" |
| 16 |
cidr_blocks = ["0.0.0.0/0"] |
| 17 |
description = "Public SSH access" |
| 18 |
} |
| 19 |
|
| 20 |
ingress { |
| 21 |
from_port = 0 |
| 22 |
to_port = 0 |
| 23 |
protocol = "-1" |
| 24 |
self = true |
| 25 |
description = "Allow traffic within the security group for port forwarding" |
| 26 |
} |
| 27 |
|
| 28 |
egress { |
| 29 |
from_port = 0 |
| 30 |
to_port = 0 |
| 31 |
protocol = "-1" |
| 32 |
cidr_blocks = ["0.0.0.0/0"] |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
# Provisioning a DocumentDB cluster with an instance. |
| 37 |
|
| 38 |
resource "aws_docdb_cluster_instance" "docdbtest" { |
| 39 |
cluster_identifier = "${aws_docdb_cluster.docdbtest.id}" |
| 40 |
identifier_prefix = "${aws_docdb_cluster.docdbtest.id}" |
| 41 |
instance_class = "db.r5.large" |
| 42 |
apply_immediately = true |
| 43 |
} |
| 44 |
|
| 45 |
resource "aws_docdb_cluster" "docdbtest" { |
| 46 |
cluster_identifier = "docstore-test-cluster" |
| 47 |
master_username = "${var.db_username}" |
| 48 |
master_password = "${var.db_password}" |
| 49 |
|
| 50 |
db_cluster_parameter_group_name = "docstore-test-pg" |
| 51 |
vpc_security_group_ids = ["${aws_security_group.docdbtest.id}"] |
| 52 |
|
| 53 |
skip_final_snapshot = true |
| 54 |
} |
| 55 |
|
| 56 |
# Provisioning an EC2 instance within the same VPC group for port forwarding. |
| 57 |
|
| 58 |
resource "aws_key_pair" "docdbtest" { |
| 59 |
key_name_prefix = "docdbtest" |
| 60 |
public_key = "${var.ssh_public_key}" |
| 61 |
} |
| 62 |
|
| 63 |
data "aws_ami" "ubuntu" { |
| 64 |
most_recent = true |
| 65 |
|
| 66 |
filter { |
| 67 |
name = "name" |
| 68 |
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"] |
| 69 |
} |
| 70 |
|
| 71 |
filter { |
| 72 |
name = "virtualization-type" |
| 73 |
values = ["hvm"] |
| 74 |
} |
| 75 |
|
| 76 |
owners = ["099720109477"] |
| 77 |
} |
| 78 |
|
| 79 |
resource "aws_instance" "docdbtest" { |
| 80 |
ami = "${data.aws_ami.ubuntu.id}" |
| 81 |
instance_type = "t2.micro" |
| 82 |
vpc_security_group_ids = ["${aws_security_group.docdbtest.id}"] |
| 83 |
key_name = "${aws_key_pair.docdbtest.key_name}" |
| 84 |
associate_public_ip_address = true |
| 85 |
} |