Skip to content

Commit ef668fb

Browse files
committed
chore : ec2, s3 terraform (#6)
1 parent 1656037 commit ef668fb

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

โ€Žs3/main.tf

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
terraform {
2+
// aws ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ถˆ๋Ÿฌ์˜ด
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
version = "~> 4.0"
7+
}
8+
}
9+
}
10+
11+
# AWS ์„ค์ • ์‹œ์ž‘
12+
provider "aws" {
13+
region = var.region
14+
}
15+
# AWS ์„ค์ • ๋
16+
17+
# S3 ์„ค์ • ์‹œ์ž‘
18+
# bucket_1 : ๊ณต๊ฐœ ๋ฒ„ํ‚ท
19+
resource "aws_s3_bucket" "bucket_1" {
20+
bucket = "${var.prefix}-bucket-${var.nickname}-1"
21+
22+
tags = {
23+
Name = "${var.prefix}-bucket-${var.nickname}-1"
24+
}
25+
}
26+
27+
data "aws_iam_policy_document" "bucket_1_policy_1_statement" {
28+
statement {
29+
sid = "PublicReadGetObject"
30+
effect = "Allow"
31+
32+
principals {
33+
type = "AWS"
34+
identifiers = ["*"]
35+
}
36+
37+
actions = ["s3:GetObject"]
38+
resources = ["${aws_s3_bucket.bucket_1.arn}/*"]
39+
}
40+
}
41+
42+
resource "aws_s3_bucket_policy" "bucket_1_policy_1" {
43+
bucket = aws_s3_bucket.bucket_1.id
44+
45+
policy = data.aws_iam_policy_document.bucket_1_policy_1_statement.json
46+
47+
depends_on = [aws_s3_bucket_public_access_block.bucket_1_public_access_block_1]
48+
}
49+
50+
resource "aws_s3_bucket_public_access_block" "bucket_1_public_access_block_1" {
51+
bucket = aws_s3_bucket.bucket_1.id
52+
53+
block_public_acls = false
54+
block_public_policy = false
55+
ignore_public_acls = false
56+
restrict_public_buckets = false
57+
}
58+
59+
# bucket_2 : ๋น„๊ณต๊ฐœ ๋ฒ„ํ‚ท
60+
resource "aws_s3_bucket" "bucket_2" {
61+
bucket = "${var.prefix}-bucket-${var.nickname}-2"
62+
63+
tags = {
64+
Name = "${var.prefix}-bucket-${var.nickname}-2"
65+
}
66+
}
67+
68+
resource "aws_s3_object" "object_1" {
69+
bucket = aws_s3_bucket.bucket_1.id
70+
key = "/index.html"
71+
content = "Hello" # ์ง์ ‘ ๋ฌธ์ž์—ด ์‚ฌ์šฉ
72+
content_type = "text/html"
73+
etag = md5("Hello")
74+
depends_on = [aws_s3_bucket.bucket_2]
75+
}
76+
77+
resource "aws_s3_object" "object_2" {
78+
bucket = aws_s3_bucket.bucket_2.id
79+
key = "/index.html"
80+
content = "Hello" # ์ง์ ‘ ๋ฌธ์ž์—ด ์‚ฌ์šฉ
81+
content_type = "text/html"
82+
etag = md5("Hello")
83+
depends_on = [aws_s3_bucket.bucket_2]
84+
}
85+
# S3 ์„ค์ • ๋

โ€Žs3/variables.tf

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
variable "prefix" {
2+
description = "Prefix for all resources"
3+
default = "cmf"
4+
}
5+
6+
variable "region" {
7+
description = "region"
8+
default = "ap-northeast-2"
9+
}
10+
11+
variable "nickname" {
12+
description = "nickname"
13+
default = "dev-seoyeon"
14+
}

0 commit comments

Comments
ย (0)