diff options
author | clarkzjw <[email protected]> | 2022-12-09 17:22:10 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2022-12-09 17:22:10 -0800 |
commit | cb5f8087f8c69c920f87fd5c219906f0796d6938 (patch) | |
tree | 8103290af0e2e14feb4fd1f1c5374fbdb1cdab75 /jinwei.me/infra/main.tf | |
parent | 0a8d79e00ebf51965b102b883e72d9e7987d50ae (diff) | |
download | jinwei.me-cb5f8087f8c69c920f87fd5c219906f0796d6938.tar.gz |
aws infra: add ec2, rds, vpc
Diffstat (limited to 'jinwei.me/infra/main.tf')
-rw-r--r-- | jinwei.me/infra/main.tf | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/jinwei.me/infra/main.tf b/jinwei.me/infra/main.tf new file mode 100644 index 0000000..235aba0 --- /dev/null +++ b/jinwei.me/infra/main.tf | |||
@@ -0,0 +1,44 @@ | |||
1 | locals { | ||
2 | name = var.name | ||
3 | } | ||
4 | |||
5 | data "aws_subnet" "ec2" { | ||
6 | filter { | ||
7 | name = "availability-zone" | ||
8 | values = [aws_db_instance.jinwei-me.availability_zone] | ||
9 | } | ||
10 | filter { | ||
11 | name = "subnet-id" | ||
12 | values = module.vpc.public_subnets | ||
13 | } | ||
14 | } | ||
15 | |||
16 | resource "aws_instance" "jinwei_me" { | ||
17 | ami = data.aws_ami.debian.id | ||
18 | instance_type = var.ec2_instance_type | ||
19 | |||
20 | subnet_id = data.aws_subnet.ec2.id | ||
21 | key_name = "framework" | ||
22 | |||
23 | vpc_security_group_ids = [aws_security_group.backend.id] | ||
24 | |||
25 | root_block_device { | ||
26 | volume_type = "gp3" | ||
27 | tags = { | ||
28 | Name = "${local.name}-root" | ||
29 | } | ||
30 | } | ||
31 | |||
32 | tags = { | ||
33 | Name = local.name | ||
34 | } | ||
35 | |||
36 | lifecycle { | ||
37 | ignore_changes = [ami] | ||
38 | } | ||
39 | } | ||
40 | |||
41 | resource "aws_eip" "main" { | ||
42 | instance = aws_instance.jinwei_me.id | ||
43 | } | ||
44 | |||