-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
80 lines (62 loc) · 1.68 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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
provider "aws" {
region = var.aws_region
}
resource "aws_secretsmanager_secret" "kubeconfig_secret" {
name = "ec2dev-kubeconfig"
description = "ec2dev kubeconfig file"
tags = { "Name" = "ec2dev-kubeconfig" }
}
data "aws_ami" "ubuntu" {
most_recent = true
owners = ["099720109477"]
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
}
}
data "cloudinit_config" "k3s" {
gzip = true
base64_encode = true
part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/install-k3s.sh", {
certmanager_email_address = "[email protected]",
k3s_url = aws_eip.k8s_eip.public_ip,
k3s_tls_san = aws_eip.k8s_eip.public_dns,
})
}
}
resource "aws_eip" "k8s_eip" {
vpc = true
}
resource "aws_instance" "k8s" {
ami = data.aws_ami.ubuntu.image_id
instance_type = "t3.medium"
iam_instance_profile = aws_iam_instance_profile.e2_custom_profile.name
root_block_device {
volume_size = 30
}
associate_public_ip_address = true
key_name = aws_key_pair.ec2_dev_key.key_name
vpc_security_group_ids = [aws_security_group.admin.id]
user_data = data.cloudinit_config.k3s.rendered
}
resource "aws_eip_association" "eip_assoc" {
instance_id = aws_instance.k8s.id
allocation_id = aws_eip.k8s_eip.id
}
resource "aws_ecr_repository" "ec2dev" {
name = "ec2dev"
image_tag_mutability = "MUTABLE"
force_delete = true
image_scanning_configuration {
scan_on_push = false
}
}