Skip to content

Commit 9c773a8

Browse files
committed
chore(terraform): initial project
1 parent 9e6161d commit 9c773a8

File tree

6 files changed

+152
-0
lines changed

6 files changed

+152
-0
lines changed

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,39 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
18+
# Local .terraform directories
19+
**/.terraform/*
20+
21+
# .tfstate files
22+
*.tfstate
23+
*.tfstate.*
24+
25+
# Crash log files
26+
crash.log
27+
28+
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
29+
# password, private keys, and other secrets. These should not be part of version
30+
# control as they are data points which are potentially sensitive and subject
31+
# to change depending on the environment.
32+
#
33+
*.tfvars
34+
35+
# Ignore override files as they are usually used to override resources locally and so
36+
# are not checked in
37+
override.tf
38+
override.tf.json
39+
*_override.tf
40+
*_override.tf.json
41+
42+
# Include override files you do wish to add to version control using negated pattern
43+
#
44+
# !example_override.tf
45+
46+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
47+
# example: *tfplan*
48+
49+
# Ignore CLI configuration files
50+
.terraformrc
51+
terraform.rc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# 建立新專案
2+
3+
## 步驟一: 安裝 Terraform 工具
4+
5+
首先你要在自己電腦安裝上 Pulumi CLI 工具,請參考[官方網站][1],根據您的作業環境有不同的安裝方式,底下以 Mac 環境為主
6+
7+
[1]:https://learn.hashicorp.com/tutorials/terraform/install-cli
8+
9+
```sh
10+
brew tap hashicorp/tap
11+
brew install hashicorp/tap/terraform
12+
```
13+
14+
透過 brew 即可安裝成功,那升級工具透過底下即可
15+
16+
```sh
17+
brew upgrade hashicorp/tap/terraform
18+
```
19+
20+
完成後,可以直接安裝自動完成 (tab completion)
21+
22+
```sh
23+
terraform -install-autocomplete
24+
```
25+
26+
測試 CLI 指令
27+
28+
```sh
29+
$ terraform -version
30+
Terraform v0.14.6
31+
```
32+
33+
有看到版本資訊就是安裝成功了
34+
35+
## 步驟二: 初始化專案
36+
37+
建立 `demo` 專案目錄,並且新增 `terraform.tf` 檔案,內容如下:
38+
39+
```sh
40+
terraform {
41+
required_providers {
42+
aws = {
43+
source = "hashicorp/aws"
44+
version = "~> 2.70"
45+
}
46+
}
47+
}
48+
```
49+
50+
切換到 demo 目錄,並執行 terraform init 初始化即可
51+
52+
```sh
53+
cd demo && terraform init
54+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 設定 AWS 環境
2+
3+
在使用 Terraform 之前要先把 AWS 環境建立好
4+
5+
## 步驟一: 設定 AWS Region
6+
7+
請先將 AWS 環境設定完畢,請用 `aws configure` 完成 profile 設定
8+
9+
```sh
10+
aws configure --profile demo
11+
```
12+
13+
## 步驟二: 在 Terraform 設定 AWS Profile
14+
15+
打開 demo 目錄內的 `terraform.tf` 檔案,在內容後面補上
16+
17+
```sh
18+
provider "aws" {
19+
profile = "demo"
20+
region = "ap-northeast-1"
21+
}
22+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Lab 1 — 基礎 Infrastructure as Code 設定
2+
3+
第一個 Lab 帶你了解 Terraform 的環境設定跟 Code 目錄結構
4+
5+
1. [建立 Terraform 新專案](./01-create-new-project.md)

terraform/labs/lab01-modern-infrastructure-as-code/demo/.terraform.lock.hcl

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 2.70"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
profile = "demo"
12+
region = "ap-northeast-1"
13+
}

0 commit comments

Comments
 (0)