Skip to content

Commit 0f3059e

Browse files
authored
feat(examples): update e2e to cover full vm example (#6)
1 parent 29a52b3 commit 0f3059e

File tree

2 files changed

+173
-24
lines changed

2 files changed

+173
-24
lines changed

examples/e2e/aws.tf

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# AWS provider
2+
3+
provider "aws" {
4+
# Configuration options
5+
region = "us-east-1"
6+
}
7+
8+
9+
data "aws_caller_identity" "current" {}
10+
11+
resource "aws_key_pair" "tf_key" {
12+
key_name = "tf_key"
13+
public_key = tls_private_key.rsa.public_key_openssh
14+
}
15+
16+
resource "tls_private_key" "rsa" {
17+
algorithm = "RSA"
18+
rsa_bits = 4096
19+
}
20+
21+
22+
resource "local_file" "tf_key" {
23+
content = tls_private_key.rsa.private_key_pem
24+
filename = "./tf_key.pem"
25+
}
26+
27+
# client VPC
28+
resource "aws_vpc" "client" {
29+
cidr_block = "172.16.0.0/16"
30+
31+
tags = {
32+
Name = "tf-client-vpc"
33+
}
34+
}
35+
36+
resource "aws_internet_gateway" "test_env_gw" {
37+
vpc_id = aws_vpc.client.id
38+
}
39+
40+
41+
resource "aws_subnet" "my_subnet" {
42+
vpc_id = aws_vpc.client.id
43+
cidr_block = "172.16.10.0/24"
44+
availability_zone = "us-east-1a"
45+
46+
tags = {
47+
Name = "tf-client-subnet"
48+
}
49+
}
50+
51+
resource "aws_security_group" "security" {
52+
name = "allow-all"
53+
54+
vpc_id = aws_vpc.client.id
55+
56+
ingress {
57+
cidr_blocks = [
58+
"0.0.0.0/0"
59+
]
60+
from_port = 22
61+
to_port = 22
62+
protocol = "tcp"
63+
}
64+
65+
egress {
66+
from_port = 0
67+
to_port = 0
68+
protocol = -1
69+
cidr_blocks = ["0.0.0.0/0"]
70+
}
71+
}
72+
73+
74+
resource "aws_network_interface" "primary" {
75+
subnet_id = aws_subnet.my_subnet.id
76+
private_ips = ["172.16.10.100"]
77+
78+
tags = {
79+
Name = "primary_network_interface"
80+
}
81+
}
82+
83+
# create an instance
84+
85+
resource "aws_instance" "vm" {
86+
ami = "ami-011ba4969cf2d6f9b"
87+
instance_type = "t2.micro"
88+
subnet_id = aws_subnet.my_subnet.id
89+
90+
tags = {
91+
Name = "tf-client-instance"
92+
}
93+
94+
key_name = aws_key_pair.tf_key.key_name
95+
96+
security_groups = [aws_security_group.security.id, aws_security_group.allow_dfcloud.id]
97+
98+
associate_public_ip_address = true
99+
}
100+
101+
resource "aws_route_table" "route-public" {
102+
vpc_id = aws_vpc.client.id
103+
104+
route {
105+
cidr_block = "0.0.0.0/0"
106+
gateway_id = aws_internet_gateway.test_env_gw.id
107+
}
108+
109+
tags = {
110+
Name = "public-route-table-demo"
111+
}
112+
}
113+
114+
resource "aws_route_table_association" "public_1" {
115+
subnet_id = aws_subnet.my_subnet.id
116+
route_table_id = aws_route_table.route-public.id
117+
}

examples/e2e/main.tf

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
11
terraform {
22
required_providers {
3-
aws = {
4-
source = "hashicorp/aws"
5-
version = "5.50.0"
6-
}
7-
83
dfcloud = {
9-
source = "github.com/dfcloud/terraform-provider-dfcloud"
4+
source = "dragonflydb/dfcloud"
5+
version = "0.0.5"
106
}
117
}
128
}
139

14-
provider "aws" {
15-
}
16-
1710
provider "dfcloud" {
1811
}
1912

20-
data "aws_caller_identity" "current" {}
21-
22-
# client VPC
23-
resource "aws_vpc" "client" {
24-
cidr_block = "10.0.0.0/16"
25-
26-
tags = {
27-
Name = "client"
28-
}
29-
}
30-
3113
# private network
3214
resource "dfcloud_network" "network" {
33-
name = "prod-network"
15+
name = "network"
3416
location = {
3517
region = "us-east-1"
3618
provider = "aws"
@@ -41,7 +23,7 @@ resource "dfcloud_network" "network" {
4123
resource "dfcloud_connection" "connection" {
4224
depends_on = [aws_vpc.client, dfcloud_network.network]
4325

44-
name = "frontend-connection"
26+
name = "connection"
4527
peer = {
4628
account_id = data.aws_caller_identity.current.account_id
4729
region = "us-east-1"
@@ -53,22 +35,72 @@ resource "dfcloud_connection" "connection" {
5335
resource "dfcloud_datastore" "cache" {
5436
depends_on = [dfcloud_connection.connection]
5537

56-
name = "prod-cache"
38+
name = "cache"
5739
location = {
5840
region = "us-east-1"
5941
provider = "aws"
6042
}
6143
network_id = dfcloud_network.network.id
6244
tier = {
63-
max_memory_bytes = 3000000000
45+
max_memory_bytes = 6000000000
6446
performance_tier = "dev"
6547
replicas = 1
6648
}
6749
}
6850

51+
# accept the peering connection
6952
resource "aws_vpc_peering_connection_accepter" "accepter" {
7053
depends_on = [dfcloud_connection.connection]
7154

7255
vpc_peering_connection_id = dfcloud_connection.connection.peer_connection_id
7356
auto_accept = true
7457
}
58+
59+
# add the required route to the client VPC
60+
resource "aws_route" "route" {
61+
depends_on = [aws_vpc_peering_connection_accepter.accepter]
62+
63+
route_table_id = aws_route_table.route-public.id
64+
destination_cidr_block = dfcloud_network.network.cidr_block
65+
vpc_peering_connection_id = dfcloud_connection.connection.peer_connection_id
66+
}
67+
68+
69+
resource "aws_route_table_association" "private_1" {
70+
subnet_id = aws_subnet.my_subnet.id
71+
route_table_id = aws_route_table.route-public.id
72+
}
73+
74+
75+
# now allow in the security group
76+
resource "aws_security_group" "allow_dfcloud" {
77+
depends_on = [aws_vpc.client]
78+
79+
vpc_id = aws_vpc.client.id
80+
81+
egress {
82+
from_port = 6379
83+
to_port = 6379
84+
protocol = "tcp"
85+
cidr_blocks = [dfcloud_network.network.cidr_block]
86+
}
87+
ingress {
88+
from_port = 6379
89+
to_port = 6379
90+
protocol = "tcp"
91+
cidr_blocks = [dfcloud_network.network.cidr_block]
92+
}
93+
}
94+
95+
output "redis-endpoint" {
96+
sensitive = true
97+
value = "redis://default:${dfcloud_datastore.cache.password}@${dfcloud_datastore.cache.addr}"
98+
}
99+
100+
output "instance-ip" {
101+
value = aws_instance.vm.public_ip
102+
}
103+
104+
output "instance-id" {
105+
value = aws_instance.vm.id
106+
}

0 commit comments

Comments
 (0)