TFC(Terraform Cloud) drift μλ¦Ό μ€μ
- kkumtree
2023-10-15T00:10:33+09:00
CloudNet@μμμ Terraform μ€ν°λκ° λλκ³ λμ,
ν
λΌνΌμ μ€μ μ΄μ μν©μ λμ
νλ©΄μ λ§μ£Όν μ λ°μ μλ λ리ννΈ(drift) μν©μ λν΄
μ΄ν΄ν΄λ³΄λ μκ°μ κ°μ‘μ΅λλ€.
μ°Έκ³ ) TFCμμμ Drift Detection κΈ°λ₯μ νμ¬ TFC Plus μλμ
μμ μ§μλ©λλ€.
1. μ©μ΄ μ΄ν΄ν΄λ³΄κΈ°
μ¬μ€μ μλ
λΆν° ν
λΌνΌμ μ νκ³ λμ, IaCλΌλ κ°λ
μ κ½νκΈ°λ§ νμ§
μ΄μ μ
μ₯μμ λ§μ£Όνμλ μλ§μ μνμ°©μ€λ€μ νν μ μ μλ¬λ‘λ§ μκ°ν΄μμμ΅λλ€.
μ€ν°λμ μ°Έμ¬νλ©΄μ μ’
μ’
‘λ리ννΈ’λΌλ λ¨μ΄λ₯Ό λ£κ³ , μ°Ύμ보λ
μλΉλΆλΆμ΄ μ΄μ μνλ μν©μ΄λΌλ κ²μ μ μ μμμ΅λλ€.
(1) Drift?
κΈ μμ±μ μν΄ μ°Ύμλ³Έ κΈ°μ μ Driftλ λ³Έλ μ£Όνμ μμ΄μμ κ·Έκ²κ³Ό
ν¬κ² μ°¨μ΄κ° μμμ μ μ μμμ΅λλ€.
Understanding terraform module
- kkumtree
2023-10-04T11:24:13+09:00
This week is last week of CloudNet@ group study about terraform.
In this study, my personal goal is making AWS architecture only with terraform and one tfstate file.
- Basic knowledge about AWS resources is required.
1. Terraform without Module
Before, I already met terraform for maintaining AWS in production level.
But at that time, our team maintain them as folder structure which is used by terraformer
# example structure
$ tree
.
βββ alb
β βββ lb.tf
β βββ lb_listener.tf
β βββ lb_target_group.tf
β βββ lb_target_group_attachment.tf
β βββ outputs.tf
β βββ provider.tf
β βββ variables.tf
βββ auto_scaling
β βββ autoscaling_group.tf
β βββ launch_template.tf
β βββ outputs.tf
β βββ provider.tf
β βββ variables.tf
βββ ec2_instance
β βββ instance.tf
β βββ outputs.tf
β βββ provider.tf
β βββ variables.tf
βββ eni
β βββ network_interface.tf
β βββ outputs.tf
β βββ provider.tf
βββ igw
β βββ internet_gateway.tf
β βββ outputs.tf
β βββ provider.tf
β βββ variables.tf
βββ nacl
β βββ default_network_acl.tf
β βββ outputs.tf
β βββ provider.tf
β βββ variables.tf
βββ route_table
β βββ main_route_table_association.tf
β βββ outputs.tf
β βββ provider.tf
β βββ route_table.tf
β βββ route_table_association.tf
β βββ variables.tf
βββ s3
β βββ outputs.tf
β βββ provider.tf
β βββ s3_bucket.tf
βββ sg
β βββ outputs.tf
β βββ provider.tf
β βββ security_group.tf
β βββ variables.tf
βββ subnet
β βββ outputs.tf
β βββ provider.tf
β βββ subnet.tf
β βββ variables.tf
βββ vpc
βββ outputs.tf
βββ provider.tf
βββ vpc.tf
At glance, this solution looks like cool.
But, problems were enough critical to think ‘why we have to use terraform?’.
Troubleshoot when using terraformer with tfenv
- kkumtree
2023-09-24T11:47:51+09:00
Removing & installing packages are some annoying, isn’t it? So, I like using version managers like SDKMAN, nvm, etc..
I also use tfenv for terraform version management.
(prev post: KR/‘Terraform μμνκΈ° w/Minimal Ubuntu’)
And I recommend neighbors to use terraformer for first learning about terraform.
terraformer is a great terraform generator tool for converting existing cloud infrastructure to terraform code.
In this post, I write how I use terraformer with tfenv.
1. How to install terraformer in Linux
- After follow below, you can use terraformer with
terraformercommand!
export PROVIDER=aws
# you can use other providers like 'google, kubernetes',
# Or if you want to use all providers, adjust 'all' instead of 'aws'
curl -LO "https://github.com/GoogleCloudPlatform/terraformer/releases/download/$(curl -s https://api.github.com/repos/GoogleCloudPlatform/terraformer/releases/latest | grep tag_name | cut -d '"' -f 4)/terraformer-${PROVIDER}-linux-amd64"
chmod +x terraformer-${PROVIDER}-linux-amd64
sudo mv terraformer-${PROVIDER}-linux-amd64 /usr/local/bin/terraformer
2. Importing AWS VPC with terraformer
- After install terraformer, you can import AWS VPC with terraformer like below
(Also you can import other AWS resources like EC2, S3, etc..)
terraformer import aws --resources=vpc --regions=ap-northeast-2
- But, error will happen… if you use tfenv like me.
$ terraformer import aws --resources=vpc --regions=ap-northeast-2
2023/09/24 12:03:53 aws importing region ap-northeast-2
2023/09/24 12:03:53 open /home/kkumtree/.terraform.d/plugins/linux_amd64: no such file or directory
$ whereis terraform
terraform: /home/kkumtree/.tfenv/bin/terraform
-
As you can see, terraformer can’t find terraform binary.
IAM STSλ₯Ό μ΄μ©ν Terraform Cloud κΆν λΆμ¬
- kkumtree
2023-09-13T20:54:28+09:00
μ΄λ²μλ Terraform Cloudκ° μΌλ§λ μ’μμ§ λ μμ보기 μν΄,
μ€ν°λμμ μ§μμ μΌλ‘ μ₯μ μ΄ κ°μ‘°λμ΄ μλ Terraform Cloudμ
IAM STSλ₯Ό μ΄μ©ν κΆν λΆμ¬ λμ λ° μ μ© μ±κ³΅μ λν΄ μ¨λ³΄λ €κ³ ν©λλ€.
Terraformμ μν μ μ₯μ μν΄ λ³΄ν΅ AWS S3λ₯Ό μ¬μ©νλλ°,
μλ€μνΌ S3 κΈ°λ‘μ 무λ£μ§λ§, λΆλ¬μ€λ κ²μ μ λ£μ
λλ€.
(μ κΈ°λ κ΅μ°μ΄μ§λ§, μλ£λ μμ
μ
λλ€)
κ·Έλμ μ€ν°λμ©μΌλ‘λ Terraformμ λΆλ¬μ¬ λλ§λ€,
μν κ°μ S3λ§κ³ , λ‘컬μ μ μ₯νμλλ°μ.
λ°μμλ λ
ΈνΈλΆ, μ§μμλ λ°μ€ν¬νμΌλ‘ νλ €λ
μ΄κ±Έ GitHubμ Private Repoμ μ μ₯ν κΉ? νλ€κ°
Terraform Cloudλ₯Ό μ¨λ³΄κΈ°λ‘ νμ΅λλ€. (κ³ ν΅μ μμ)
Terraform resource μ΄ν΄νκΈ° w/AWS VPC
- kkumtree
2023-09-08T22:41:14+09:00
μ΄λ²μλ CloudNet@λ₯Ό ν΅ν΄ νμ΅ν λ΄μ©μ κΈ°λ°μΌλ‘,
- AZλ₯Ό λμμΌλ‘ ν data μ‘°ν
- AWS VPC μμ± μμ λ‘ μ΄ν΄λ³΄λ output
- resource μ΄λ¦ λ³κ²½
μμΌλ‘ μμ보λλ‘ νκ² μ΅λλ€.
κ΅μ¬λ‘ μ¬μ©ν [ν λΌνΌμΌλ‘ μμνλ IaC] λ μ°Έκ³ νμμ΅λλ€.
κΈ°λ³Έ μ€μ
- aws-cliμ 리μ μ
ap-northeast-2μ μ€μ νμμ΅λλ€.
$ aws configure list
Name Value Type Location
---- ----- ---- --------
profile <not set> None None
access_key ****************2U5J shared-credentials-file
secret_key ****************Z0co shared-credentials-file
region ap-northeast-2 config-file ~/.aws/config
1. data μ‘°ν
dataλ μ¬μ©μκ° μ μνλ resource λ° λ¦¬μμ€μ λν μ€νκ³Ό λ°λλ‘,
provider(μ΄λ² ν¬μ€νΈμμλ aws)μμ μ 곡νλ 리μμ€λ₯Ό μ‘°ννλ κΈ°λ₯μ
λλ€.
Terraform μμνκΈ° w/Minimal Ubuntu
- kkumtree
2023-08-31T22:21:08+09:00
μ΄λ²μλ CloudNet@μμ μ§ννλ Terraform μ€ν°λ(μ΄ν, T101)μ μ°Έμ¬νμ΅λλ€.
Terraformμ μ°λ©΄ μ μ’μμ§λ μμΈνκ³ μ λ¬Έμ μΈ κΈμ΄ μμΌλ―λ‘, μ°Έκ³ νμλ©΄ μ’μ κ² κ°μ΅λλ€. (λ§ν¬: 44bits)
μμ μ ν
λΌνΌμ μΌλ μ μ΄ μμ§λ§, Moduleνκ° μ΄λ ΅κΈ°λ νκ³
μ΄λ² κΈ°νμ ν
λΌνΌ μ κ°μ λ€μ 볡기νλ λ§μμΌλ‘ μ°Έμ¬νμ΅λλ€.
μ¬μ©ν κ΅μ¬λ [ν λΌνΌμΌλ‘ μμνλ IaC] μ λλ€.
μ΄λ²μλ Terraform μ΄κΈ° μ
μ
μ λν΄, μ΄ν΄λ³΄κ³
μνμΌμ Canonical 곡μ Minimal Ubuntu(ARM64) AMIλ₯Ό μ€μΉν΄λ³΄κ² μ΅λλ€.
- Terraform μ€μΉ
- tfenv μ¬μ©κ³Ό .tf μμ± λ°λΌνκΈ°
- Hello World in terraform
- Terraform μ¨λ³΄κΈ°
μμΌλ‘ μ§νν©λλ€.
Terraform μ€μΉ
Terraformμ Linux νκ²½(Ubuntu κΈ°μ€)μμ μ€μΉν μ μλ λ°©λ²μ΄ 3κ°μ§ μ λ μμ΅λλ€.
μ΅μ λ΄μ©μ Terraform CLIμμ νμΈν μ μμ΅λλ€.