-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.tf
122 lines (102 loc) · 2.77 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.38.0"
}
postgresql = {
source = "cyrilgdn/postgresql"
}
curl = {
source = "marcofranssen/curl"
}
}
cloud {
organization = "magfest"
workspaces {
name = "ubersystem-staging"
}
}
}
# -------------------------------------------------------------------
# VPC
# -------------------------------------------------------------------
resource "aws_vpc" "uber" {
cidr_block = var.cidr_block
enable_dns_hostnames = true
tags = {
Name = "Ubersystem"
}
}
# -------------------------------------------------------------------
# Subnets
# -------------------------------------------------------------------
resource "aws_subnet" "primary" {
vpc_id = aws_vpc.uber.id
cidr_block = cidrsubnet(var.cidr_block, 8, 0)
availability_zone = "us-east-1c"
map_public_ip_on_launch = true
tags = {
Name = "Ubersystem Primary"
}
}
resource "aws_subnet" "secondary" {
vpc_id = aws_vpc.uber.id
cidr_block = cidrsubnet(var.cidr_block, 8, 1)
availability_zone = "us-east-1b"
map_public_ip_on_launch = true
tags = {
Name = "Ubersystem Secondary"
}
}
resource "aws_db_subnet_group" "uber" {
name = "uber"
subnet_ids = [
aws_subnet.primary.id,
aws_subnet.secondary.id
]
tags = {
Name = "Ubersystem"
}
}
# -------------------------------------------------------------------
# Routes and Gateways
# -------------------------------------------------------------------
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.uber.id
tags = {
Name = "Ubersystem"
}
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.uber.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.igw.id}"
}
tags = {
Name = "Ubersystem"
}
}
resource "aws_route_table_association" "primary_route" {
subnet_id = aws_subnet.primary.id
route_table_id = aws_route_table.public.id
}
resource "aws_route_table_association" "secondary_route" {
subnet_id = aws_subnet.secondary.id
route_table_id = aws_route_table.public.id
}
data "curl_request" "ghcr_token" {
http_method = "GET"
uri = "https://ghcr.io/token?scope=repository:magfest/magprime:pull"
lifecycle {
postcondition {
condition = self.response_status_code == 200
error_message = "Invalid response code getting login token: ${self.response_status_code}\n\n${self.response_body}"
}
}
}
provider "curl" {
alias = "ghcr"
token = jsondecode(data.curl_request.ghcr_token.response_body).token
}