~nromdotcom/gemif

ref: 82bb8de4168fc18f3c6ebab80136c6ed5d7a7363 gemif/infra/ec2.tf -rw-r--r-- 1.3 KiB
82bb8de4Norm MacLennan Clean up the Terraform a bit 1 year, 1 month ago
                                                                                
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
provider "aws" {
  region = "us-east-1"
}

data "aws_ami" "amz2" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn2-ami-hvm-*-arm64-gp2"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }
}

resource "aws_instance" "gemif" {
  ami              = data.aws_ami.amz2.id
  instance_type    = var.instance_type
  user_data_base64 = data.template_cloudinit_config.config.rendered

  iam_instance_profile   = aws_iam_instance_profile.gemif.name
  vpc_security_group_ids = [aws_security_group.allow_gem.id]

  tags = {
    Name = "GemIF Server"
  }

  volume_tags = {
    "Name" = "GemIF Server"
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_security_group" "allow_gem" {
  name        = "allow_gem"
  description = "Allow Gemini inbound traffic"

  ingress {
    description = "Gemini from Internet"
    from_port   = 1965
    to_port     = 1965
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    description = "Open egress to Internet"
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_eip" "gemif" {
  instance = aws_instance.gemif.id
  vpc      = true

  tags = {
    Name = "GemIF Server"
  }
}