This repository was archived by the owner on Jul 3, 2024. It is now read-only.
forked from sabre1041/sigstore-ansible
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
147 lines (123 loc) · 3.41 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
variable "vpc_id" {
type = string
}
variable "ssh_public_key_path" {
type = string
default = "~/.ssh/id_rsa.pub"
}
variable "ssh_private_key_path" {
type = string
default = "~/.ssh/id_rsa"
}
variable "base_domain" {
type = string
}
data "aws_route53_zone" "domain" {
name = var.base_domain
private_zone = false
}
variable "ami_id" {
type = string
default = "ami-0d77c9d87c7e619f9"
}
variable "rh_username" {
sensitive = true
type = string
}
variable "rh_password" {
sensitive = true
type = string
}
// generate a new security group to allow ssh and https traffic
resource "aws_security_group" "sigstore-access" {
name = "sigstore-access"
description = "Allow ssh and https traffic"
vpc_id = var.vpc_id
ingress {
description = "SSH from VPC"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTPS from VPC"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_key_pair" "sigkey" {
key_name = uuid()
public_key = file(var.ssh_public_key_path)
}
resource "aws_instance" "sigstore" {
ami = var.ami_id
instance_type = "m5.large"
associate_public_ip_address = true
vpc_security_group_ids = [aws_security_group.sigstore-access.id]
key_name = aws_key_pair.sigkey.key_name
provisioner "remote-exec" {
inline = [
"sudo cloud-init status --wait",
"echo 'Connection Established'",
"sudo dnf -y update",
]
}
connection {
type = "ssh"
user = "ec2-user"
host = self.public_ip
private_key = file(var.ssh_private_key_path)
}
}
resource "null_resource" "configure-sigstore" {
depends_on = [aws_instance.sigstore]
provisioner "local-exec" {
command = "sed -i.bak 's/<REMOTE_IP_ADDRESS>/${aws_instance.sigstore.public_ip}/g' inventory"
}
provisioner "local-exec" {
command = "sed -i.bak 's/ansible_user=<remote_user>/ansible_user=ec2-user/g' inventory"
}
provisioner "local-exec" {
command = "ansible-galaxy collection install -r requirements.yml"
}
provisioner "local-exec" {
command = "ansible-playbook -i inventory playbooks/install.yml -e registry_username='${var.rh_username}' -e registry_password='${var.rh_password}' -e base_hostname=${var.base_domain}"
}
}
resource "aws_route53_record" "rekor" {
name = "rekor.${var.base_domain}"
type = "A"
zone_id = data.aws_route53_zone.domain.zone_id
records = [aws_instance.sigstore.public_ip]
allow_overwrite = true
ttl = "300"
}
resource "aws_route53_record" "fulcio" {
name = "fulcio.${var.base_domain}"
type = "A"
zone_id = data.aws_route53_zone.domain.zone_id
records = [aws_instance.sigstore.public_ip]
allow_overwrite = true
ttl = "300"
}
resource "aws_route53_record" "tuf" {
name = "tuf.${var.base_domain}"
type = "A"
zone_id = data.aws_route53_zone.domain.zone_id
records = [aws_instance.sigstore.public_ip]
allow_overwrite = true
ttl = "300"
}
// Output public ip address
output "public_ip" {
value = aws_instance.sigstore.public_ip
}