Platform Group, Platform Infra Team ã® @dtan4 ã§ãã
ç¾å¨ã¡ã«ã«ãª/ã¡ã«ãã¤ã®ãã¤ã¯ããµã¼ãã¹åºç¤ (Microservices Platform) ã§ã¯ãæ§ã
ãªã¯ã©ã¦ããªã½ã¼ã¹ã»SaaS ãéçºè
ã«æä¾ãã¦ãã¾ãããããã®ãªã½ã¼ã¹ã宣è¨çã«ç®¡çããããã®æ段ã¨ã㦠HashiCorp Terraform ãå©ç¨ãã¦ãããæ°ç¾ã®ãã¤ã¯ããµã¼ãã¹ã®ã¤ã³ãã©ã Terraform ã«ãã£ã¦ç®¡çããã¦ãã¾ãã
1年以ä¸åã®è©±ã§ãããTerraform 0.12 ããªãªã¼ã¹ããã¾ãããæ¨å¹´å¾åã«ãæã ã管çãã¦ãã Terraform ãªãã¸ããªã«ãã㦠Terraform 0.12 対å¿ä½æ¥ãè¡ãã¾ãããæ¬è¨äºã§ã¯ãæã ã®ç°å¢ã«ããã¦ã©ã®ããã« Terraform 0.12 対å¿ä½æ¥ãè¡ã£ããã«ã¤ãã¦èª¬æãã¾ãã
Terraform 0.12 対å¿ã®åæ©
Terraform 0.12 ã使ããã¨ã§å¾ãããã¡ãªããã¯ãconfiguration language ã® HCL2 対å¿ã¨ãfor_each
ã dynamic
ã¨ãã£ã便å©ãªé¢æ°ã使ããããã«ãªããã¨ã§ããä¾ãã° for_each
ã使ããã¨ã§ãé
åãããªã½ã¼ã¹ãè¤æ°ä½ãéã«ãresource ID ãé
åã®ã¤ã³ããã¯ã¹ã§ã¯ãªãè¦ç´ ãã¼ã¹ã§å²ãå½ã¦ãããããã«ãªãã¾ãããã®ãããã§ãé
åã®éä¸ã§è¦ç´ ã追å /åé¤ããã¦ãä¸å¿
è¦ãªå·®åãçããªããªãã¾ããã¡ã«ã«ãªã§ã¯ãã®ãããªåçãªãªã½ã¼ã¹çæãå¤ç¨ãã¦ãããããæ°ããé¢æ°ãç¨ãããã¨ã§å®è£
ããã容æã«ãªãã¾ãã
variables "members" {
default = [
"[email protected]",
"[email protected]",
]
}
# Terraform 0.11
resource "google_project_iam_member" "project_viewer" {
count = "${length(var.members)}"
project = "xxx"
member = "user:${element(var.members, count.index)}"
role = "roles/viewer"
}
# ==> google_project_iam_member.project_viewer[0]
# ==> google_project_iam_member.project_viewer[1]
# Terraform 0.12
resource "google_project_iam_member" "project_viewer" {
for_each = toset(var.members)
project = "xxx"
member = each.key
role = "roles/viewer"
}
# ==> google_project_iam_member.project_viewer["[email protected]"]
# ==> google_project_iam_member.project_viewer["[email protected]"]
ã¾ããæ¨å¹´11æã« Terraform 0.11 ã®ãµãã¼ãçµäºã宣è¨ãããããæ´ã« Terraform Provider ã®ææ°ãªãªã¼ã¹ (e.g. Google Provider v3) ã Terraform 0.12 以éã®ã¿ããµãã¼ãããããã«ãªã£ãã®ããTerraform 0.12 ä½æ¥ãå§ããçç±ã¨ãã¦æãããã¾ãã
ãã®ããã« Terraform 0.12 ã§ã¯è¨èªæ©è½ã®å¤§å¹ ãªå¼·åãè¡ããã¾ããããåæã«ï¼ããç¨åº¦å¾æ¹äºæãä¿ããã¦ããã¨ã¯ããï¼æ¢å Terraform configuration ã® Terraform 0.12 対å¿ã¯ããç¨åº¦ã®å´åãå²ãå¿ è¦ãããã¾ãããTerraform 0.12 ã¯éçºè ã¨ãã©ãããã©ã¼ã ãã¼ã åæ¹ãå°å ¥ãæãã§ãã¾ããããæã ã®ç°å¢ã§ãå®å ¨ã«ãå°å ¥ãã¦ããã¨ãªãã¨ãããããªå·¥å¤«ãå¿ è¦ã¨ãªãã¾ããã
Terraform at Mercari Microservices Platform
å®éã®ç§»è¡æé ã説æããåã«ãã¾ãæã ãã©ã®ããã« Terraform configuration ã管çãã¦ãããã«ã¤ãã¦èª¬æãã¾ãã
microservices-terraform: Terraform configuration ã®ä¸å 管çãªãã¸ããª
åé ã§è¿°ã¹ãããã«ãã¡ã«ã«ãª/ã¡ã«ãã¤ã§åããã¦æ°ç¾ã®ãã¤ã¯ããµã¼ãã¹ãåå¨ãã¾ãããããã® Terraform configuration ã¯ã¾ã¨ãã¦ä¸ã¤ã®ãªãã¸ã㪠(microservices-terraform) ã§ç®¡çããã¦ãã¾ãããªãã¸ããªã¯ä¸ã¤ã§ãã Terraform ã®å®è¡åä½ã¨ãªã tfstate ã¯ãµã¼ãã¹ã¨ç°å¢åä½ (prod/dev/lab) ã§åããã¦ãããä»ã®ãµã¼ãã¹ã®å¤æ´ã plan/apply ã®çµæã«å½±é¿ãåã¼ããã¨ã®ãªãããä½ããã¦ãã¾ããã¾ããTerraform ãã®ãã®ã¯ CI ä¸ã§ã®ã¿å®è¡ããã¾ããããã®ã¨ãã Push ããã Git branch ã®å·®åã確èªããå¤æ´ã®ãããµã¼ãã¹ã§ã®ã¿ Terraform ãå®è¡ããããã«ãã¦ãã¾ãã
ãããã®ä»çµã¿ã«ããã管çãããµã¼ãã¹ãã©ãã ãå¢ãããã¨ããããããã®ãµã¼ãã¹ãäºãã«å½±é¿ãåã¼ããã¨ãªããéçºè ãç¬èªã®ã©ã¤ããµã¤ã¯ã«ã§ Terraform ãæ±ããã¨ãã§ãã¦ãã¾ããä¸æ¹ã§ç®¡çè ã®è¦ç¹ããè¦ãã¨ãmonorepo çãªæ§æãã¨ã£ã¦ãããã¨ã§ãå ¨ä½ã«å½±é¿ããå¤æ´ (e.g. CI ã¹ã¯ãªããæ´æ°ãããªã·ã¼ãã«ã¼ã«ã®è¿½å ) ã権é管çãè¡ãããããªã£ã¦ãã¾ãããµã¼ãã¹ã追å ãããã³ã« Terraform ã® CI/CD ãä¸ããã»ããã¢ããããå¿ è¦ãããã¾ãããéçºè ã¯ãmicroservices-terraform ã«æ°ãããµã¼ãã¹ã®ãã£ã¬ã¯ããªãä½ã£ã¦å¿ è¦ãª Terraform configuration ãç½®ãã ãã§ããã®ãµã¼ãã¹ã®ã¤ã³ãã©ã Terraform ã§ç®¡çã§ããããã«ãªãã¾ãã
Microservice Starter-kit Terraform Module
microservices-terraform ã®ä¸ã§ã¯ããã¤ãã® Terraform Module ãå©ç¨ãã¦ãã¾ããããã¹ã¦ã®ãµã¼ãã¹ãå¿ ãå©ç¨ãã¦ãã Module ã Microservice Starter-kit ã§ãããã® Module ã¯ãã¹ã¦ã®ãµã¼ãã¹ãå ±éãã¦å¿ è¦ã¨ãããªã½ã¼ã¹ (GCP Project, GCP IAMs, Kubernetes Namespace, GitHub Team, …) ãå«ãã§ããããµã¼ãã¹åãæå± (ã¡ã«ã«ãª JP/US, ã¡ã«ãã¤) ã¨ãã®ãµã¼ãã¹ã® Owner ä¸è¦§ãè¨è¼ãããã¨ã§ãå¿ è¦ãªãªã½ã¼ã¹ä½æã¨æ¨©éè¨å®ãè¡ããããã®ã§ããå¤æ´ãå ãããããã³ã«æ°ãããã¼ã¸ã§ã³ãçºè¡ãããAmazon S3 ã«ãã¼ã¸ã§ã³ãã¨ã® tarball ãã¢ãããã¼ãããã¾ããåãµã¼ãã¹ã§ã¯ãã® tarball ã pull ãã¾ããããã«ãããããããã®ãã¤ã¯ããµã¼ãã¹ãèªåãã¡ã®ãã¼ã¹ã«ã¦ Starter-kit ã®ãã¼ã¸ã§ã³ç®¡çãè¡ããã¨ãã§ãã¾ããTerraform 0.12 å¯¾å¿ ã§ã¯ããã®ãã¼ã¸ã§ãã³ã°ããã Starter-kit ã大ããªå½¹å²ãæããã¾ããã
microservices-terraform ã Starter-kit ã«ã¤ãã¦è©³ããç¥ãããã¨ããæ¹ã¯ã@babarot ã®çºè¡¨è³æ Terraform Ops for Microservices ã御覧ãã ãããè³æèªä½ã¯2å¹´åã®ãã®ã§ããã大ã¾ããªä»çµã¿ã«ã¤ãã¦ã¯ç¾å¨ã§ãã»ã¼åãã§ãã
microservices-terraform ã«ããã Terraform 0.12 対å¿ã«åãã課é¡
ãã¦ãæ°ç¾ã®ãµã¼ãã¹ãåå¨ãããã¤ãããããç¬ç«ããã©ã¤ããµã¤ã¯ã«ã§ç®¡çããã¦ããã¨ãªãã¨ãä¸åº¦ã«ãã¹ã¦ã®ãµã¼ãã¹ã Terraform 0.12 対å¿ãããã®ã¯éç¾å®çã§ãã
åè¿°ããããã«åãµã¼ãã¹ã¯æ ¸ã¨ãªã Terraform Module "Starter-kit" ãæã£ã¦ããã®ã§ããããµã¼ãã¹ã«ãã£ã¦ä½¿ã£ã¦ãã Starter-kit ã®ãã¼ã¸ã§ã³ãç°ãªãã¾ããä»åã¯åãµã¼ãã¹ã«ããã Terraform 0.12 対å¿ã®ããªã¬ã¼ããã® Starter-kit ã®ãã¼ã¸ã§ã³ã«é£åããã¾ããããå¤ã Starter-kit ã使ã£ã¦ãããµã¼ãã¹ã¯ã¾ã Terraform 0.12 対å¿ãå¯è½ãªãã¼ã¸ã§ã³ã¾ã§ Starter-kit ãã®ãã®ãæ´æ°ããå¿ è¦ãããã¾ããã¾ãããµã¼ãã¹ã«ãã£ã¦ã¯é·ãé Terraform ãå®è¡ããã¦ãªããã¨ã§ãconfiguration drift ï¼æä½æ¥çã«ãããTerraform configuration ã¨å®éã®ã¤ã³ãã©ã®ç¶æ ãä¹é¢ãã¦ããç¶æ ï¼ãåå¨ãããã¨ããããã¾ããå®å ¨ã« Terraform 0.12 対å¿ãè¡ãããã«ã¯ãäºåã«ãããã® drift ã解æ¶ããªããã°ãªãã¾ããã
以ä¸ãããéçºè ãèªåãã¡ã®ãã¼ã¹ã§èªåãã¡ã®ãµã¼ãã¹ã Terraform 0.12 対å¿ã§ãããããªãä½ããã®å·¥å¤«ãå¿ è¦ã¨ãªãã¾ããã
移è¡æ¹æ³: å ¬å¼ã®å¯¾å¿æé
å ¬å¼ããã¥ã¡ã³ã ã§ã説æããã¦ãã¾ãããTerraform 0.12 対å¿ã¯ä»¥ä¸ã®æé ã«ã¦è¡ããã¨ãã§ãã¾ãã
æåã®ä½æ¥ã¯ Terraform 0.11 ã§è¡ãã¾ãã
terraform init
terraform plan
terraform apply
- ã¾ããç¾æç¹ã§ Terraform configuration ã¨å®éã®ã¤ã³ãã©ã®ç¶æ
ãä¸è´ãã¦ãã (
terraform plan
ã§å·®åã表示ãããªã) ç¶æ ã«ãã¾ãã
- ã¾ããç¾æç¹ã§ Terraform configuration ã¨å®éã®ã¤ã³ãã©ã®ç¶æ
ãä¸è´ãã¦ãã (
-
terraform 0.12checklist
- èªåã³ã¼ãå¤æã§å¯¾å¿ã§ããªãç®æããæ´æ°ãå¿ è¦ãª Terraform Provider ã以ä¸ã®ããã«æ示ããã¾ãã
After analyzing this configuration and working directory, we have identified some necessary steps that we recommend you take before upgrading to Terraform v0.12: - [ ] Provider "openpgp" may need to be upgraded to a newer version that supports Terraform 0.12. (Supported version information is not available for this provider.) - [ ] Upgrade provider "kubernetes" to version 1.10.0 or newer. No currently-installed version is compatible with Terraform 0.12. To upgrade, set the version constraint for this provider as follows and then run
terraform init
: version = "~> 1.10.0" Taking these steps before upgrading to Terraform v0.12 will simplify the upgrade process by avoiding syntax errors and other compatibility problems.
ãããã㯠Terraform 0.12 ã®ãã¤ããªã使ãã¾ãã
-
terraform 0.12upgrade
- åããã£ã¬ã¯ããªã«ããå ¨ã¦ã® Terraform configuration ã Terraform 0.12 ã§å°å ¥ãããæ¸å¼ã«å¤æãã¦ããã¾ãã
- ä¸é¨ããã¼ã«ã«ã¦ä¸æã«å¤æã§ããªããã®ã«ã¤ãã¦ã¯
TF-UPGRADE-TODO
ã³ã¡ã³ããæ®ãã ãã«ãã¾ãã - ã¾ãããã®ãã£ã¬ã¯ããªã Terraform 0.12 以ä¸ãè¦æ±ãããã¨ãæ示ãã Terraform ãã®ãã®ã§ãã¼ã¸ã§ã³ãã§ãã¯ã§ããããã«ããããã以ä¸ã®ãããª
versions.tf
ã追å ãã¾ãã
terraform { required_version = ">= 0.12" }
-
terraform plan
- 大æµã®å ´åå·®åã¯åºãªãã¯ãã§ãããå¤ææ¼ãçã§çºçããå ´åã¯ãã®é½åº¦ä¿®æ£ãã¾ãã
- ãã®æç¹ã§ã¯ã¾ã Terraform 0.11 以ä¸ã®ãã¼ã¸ã§ã³ã§ tfstate ãèªããã¨ã¯ã§ãã¾ããä¾ãã° Terraform 0.12 対å¿ç¨ Git ãã©ã³ãã¨ã¯å¥ã®ãã©ã³ãã§ãé常ã®ã¤ã³ãã©æ´æ°ä½æ¥ã並è¡ãã¦è¡ãã¾ã
-
terraform apply
- ãã®æç¹ã§ tfstate ã Terraform 0.12 ãã¼ã¹ã®ãã®ã«ç½®ãæããããã以éãã®ãµã¼ãã¹ã§ã¯ Terraform 0.11 以ä¸ã使ã£ã¦ã®ä½æ¥ã¯ã§ããªããªãã¾ãã
- 並è¡ä½æ¥ä¸ã®ãã©ã³ããããã°ããã®ãã©ã³ããææ°ã® master ãã©ã³ãã«è¿½å¾ããããã¨ã§ Terraform 0.12 対å¿ããå¿ è¦ãããã¾ãã
移è¡æ¹æ³: ã¡ã«ã«ãªã®å ´å
Terraform Provider ã® Terraform 0.12 対å¿
Terraform 0.12 ã使ãããã«ã¯ããã®ã¬ã¤ãã«æ¸ããã¦ããéããã¾ã使ã£ã¦ãã Terraform Provider ã Terraform 0.12 対å¿ãã¦ããå¿ è¦ãããã¾ãã移è¡ããã¸ã§ã¯ããå§ãã段éã§ã¯ãTerraform Registry ã§æä¾ããã¦ãã Official/Verified Provider ã®ææ°ãã¼ã¸ã§ã³ã¯ãã¹ã¦ Terraform 0.12 ã«å¯¾å¿ãã¦ããã®ã§ããããã¯é©åãªãã¼ã¸ã§ã³ä»¥ä¸ã«æ´æ°ãããã¨ã§å¯¾å¿ã§ãã¾ãããä¸æ¹ã§ãmicroservices-terraform ã§ã¯æ´å²ççµç·¯ã«ããèªä½ã¾ãã¯ãã©ã¼ã¯ãã Provider ãããã¤ãå©ç¨ãã¦ããã®ã§ããããã¯ä»¥ä¸ã®ãããªå 容㧠Terraform 0.12 対å¿ãããå¿ è¦ãããã¾ããã
- èªä½ Provider
- å ¬å¼ã® migrator (hashicorp/tf-sdk-migrator) ãç¨ã㦠Terraform 0.12 対å¿ããã¾ããã
- e.g. Switch to using Terraform provider plugin SDK by dragon3 · Pull Request #5 · mercari/terraform-provider-openpgp
- ãã©ã¼ã¯ãã Provider
- ãã©ã¼ã¯ããåå ã¨ãªã£ããã°ãæ©è½ä¸è¶³ããã©ã¼ã¯å ã®ææ°ãã¼ã¸ã§ã³ã§ã¯ä¿®æ£ããã¦ãããã®ã¯ãTerraform 0.12 対å¿ã®ã¿ã¤ãã³ã°ã§ãã©ã¼ã¯ãããã¦ãå ã® Provider ã使ãããã«ãã¾ããã
- e.g. Kubernetes RBAC å°å ¥æã¯å¤ã Kubernetes Provider ã RBAC ã«å¯¾å¿ãã¦ããªãã£ãã®ã§ãã©ã¼ã¯ãã Provider ã使ã£ã¦ããããææ°ã®å ¬å¼æä¾ Provider ã§ã¯å¯¾å¿ããã¦ããã㤠Terraform 0.12 対å¿ãæ¸ãã§ããã®ã§ããã®æ©ä¼ã«ãã©ã¼ã¯ãããã¦ãã¡ãã¸ç§»è¡ãã¾ããã
- ãã以å¤ã¯èªä½ Provider ã¨åãæé ã§ãèªå㧠Terraform 0.12 対å¿ããã¾ããã
Terraform modules ã® Terraform 0.12 対å¿
ç¶ãã¦ãåãã¤ã¯ããµã¼ãã¹ãå©ç¨ãã¦ãã Terraform Module ã Terraform 0.12 対å¿ããã¾ãããç¾å¨ microservices-terraform ã§ã¯ Terraform Registry ã«ç»é²ããã¦ãã Module ã¯å©ç¨ãã¦ããããèªä½ Module ã®ã¿ãå©ç¨ãã¦ãã¾ããããããå ¨ã¦æã ã®æ㧠Terraform 0.12 対å¿ãããå¿ è¦ãããã¾ããããã®ä½æ¥ã¯ãå ¬å¼ã®å¯¾å¿æé ãéãã«è¡ãã対å¿å®äºããæç¹ã§æ°ãããã¼ã¸ã§ã³ããªãªã¼ã¹ãã¾ãããããã«ãããããã®ãã¼ã¸ã§ã³ä»¥éã® Starter-kit ã使ãå ´åã¯ãTerraform 0.12 対å¿ä½æ¥ãæ¸ã¾ãã¦ãã ãããã¨ããç¶æ ã«ãã¾ããã
å¨è¾ºãã¼ã«ã® Terraform 0.12 対å¿
microservices-terraform ãªãã¸ããªã§ã¯ãTerraform ãã®ãã®ã«å ãã¦ãplan/apply ã®çµæéç¥ã Terraform configuration ã®éç解æãè¡ãããæ§ã ãªãã¼ã«ãå©ç¨ããã¦ãã¾ããTerraform 0.12 対å¿ã¨ããã«ä¼´ã configuration language ã® HCL2 移è¡ã«ããããããã®ãã¼ã«ãæ£ããåä½ããªããã¨ãæ¤è¨¼æ®µéã§å¤æãã¾ããããã®ããã以ä¸ã®ãããªä¿®æ£ãè¡ãã¾ããã
- mercari/tfnotify: plan/apply ã®çµæã CI ãã GitHub ã«ã³ã¡ã³ãã¨ãã¦éç¥ãããã¼ã«
- Terraform 0.12 ã§çµæã®ãã©ã¼ããããå¤ãã£ã¦è¡¨ç¤ºãå´©ãã (ä½è¨ã« HTML ã¨ã¹ã±ã¼ãããã) ããã«ãªã£ãã®ã§ã対å¿ãè¡ãã¾ããã
- Add a option to disable HTML escape for Terraform command output in GitHub by dtan4 · Pull Request #58 · mercari/tfnotify
- b4b4r07/stein: ç¬èªå®ç¾©ã®ã«ã¼ã«ããã¨ã«ãTerraform configuration ã®éç解æãè¡ããã¼ã«
- HCL2 ã®ãã¡ã¤ã«ãèªããããã«ãã¾ããã
- Support HCL2 format .tf and .hcl files by dragon3 · Pull Request #18 · b4b4r07/stein
åãµã¼ãã¹ã® Terraform 0.12 対å¿
ããã¾ã§ã®ä¸æºåãçµããã°ããããããµã¼ãã¹ãã®ãã®ã® Terraform configuration ã Terraform 0.12 対å¿ããããã¨ãã§ãã¾ããã§ããã以ä¸ã®å¶ç´ã«ãããããã§ã工夫ãå¿ è¦ã¨ãªãã¾ããã
ã¾ã microservices-terraform ãªãã¸ããªã«ããã¦ã¯ããã¼ã«ã«ã§ Terraform ãå®è¡ã§ãã (tfstate ã remote backend ãã pull ã§ãã) 権éãéçºè
ã«ä¸ãã¦ãã¾ãããGit ã§ãã¼ã¸ã§ã³ç®¡çããã¦ããªãå¤æ´ãå®ç°å¢ã«é©ç¨ãããã®ãé²ããããã¾ãéçºè
ãæã¤ã¯ã©ã¦ããããã¤ãã®æ¨©éãæå°éã«ããããCI ã«éç´ããããã¨ããçç±ã§ãããã®å¶ç´ã«ããããã¼ã«ã«ã§ã¯ terraform init
ã¨ãã®å¾ã® terraform 0.12upgrade
ã³ãã³ããå®è¡ã§ããªãã®ã§ãå
¬å¼ã®å¯¾å¿æé ãã«æ¸ããæ¹æ³ã¯ãã¼ã«ã«ç°å¢ã§ã¯è¡ãªãã¾ããã
ãã®ãããåãµã¼ãã¹ã® Terraform 0.12 対å¿ã¯ä»¥ä¸ã®æé ã§è¡ããããã«ãã¾ããã
- Starter-kit ã Terraform 0.12 対å¿ãããã¼ã¸ã§ã³ã®ãã²ã¨ã¤åãã¾ã§æ´æ°ããã¨ãCI ãèªåã§
terraform 0.12upgrade
ã®å®è¡ã¨ Starter-kit æ´æ°ãè¡ããTerraform 0.12 対å¿ç¨ã® Pull Request ãä½ãããã«ãã¾ããã- ä¾ãã° Starter-kit v0.20 ã Terraform 0.12 対å¿ãã¼ã¸ã§ã³ã¨ããå ´åããã²ã¨ã¤åãã® Starter-kit v0.19 ã使ã£ã¦ããã°ãCI ã terraform 0.12 å¯¾å¿ Pull Request ãèªåã§ä½æãã¾ãã
- ç¹ã«å·®åãç¡ããã°ãéçºè ãèªå㧠Approve -> Merge ãããã¨ã§ Terraform 0.12 対å¿ãå®äºãã¾ããå·®åãããã°ãã® Pull Request ä¸ã¾ãã¯å¥ã®ãã©ã³ãã§ä¿®æ£ããåé¡ãªããã¼ã¸ã§ããç¶æ ã«ããå¿ è¦ãããã¾ãã
常ã«ææ°ã® Starter-kit ã«è¿½å¾ã§ãã¦ãããµã¼ãã¹ã§ããã°ã»ã¨ãã©è¦å´ãªã Terraform 0.12 対å¿ã§ãã¾ããããå¤ã Starter-kit ã使ãç¶ãã¦ãããµã¼ãã¹ã¯ã¾ããã²ã¨ã¤åãã®ãã¼ã¸ã§ã³ã¾ã§è¿½å¾ããªããã°ãªãã¾ãããStarter-kit ã®æ´æ°ã«ã¯ç¹å®ã®è¨å®è¿½å ãè¦ãããã®ããããéçºè ã®è² æ ã«ãªããã¨ã¯äºæ³ã§ãã¾ããã
ããã§ãStarter-kit ããã²ã¨ã¤åã®ãã¼ã¸ã§ã³ã¾ã§æ´æ°ããæ軽ã«ã§ãããããã«ãã¼ã¹ã¯ãªãããæä¾ãã¾ããã以ä¸ã®ã³ãã³ããå®è¡ããã ãã§ã対象ãµã¼ãã¹ã«ãã㦠Starter-kit ã®æ´æ°ã¨å¿ è¦ãªãããé©ç¨ãè¡ããã¾ãã
# e.g. upgrade Starter-kit in mercari-echo-jp-prod to the latest version
script/upgrade-microservice-starter-kit /path/to/mercari-echo-jp/production
ãã®ã¹ã¯ãªããã¯å°å ¥å¾å年以ä¸çµã£ãç¾å¨ã§ãç¶ç¶ãã¦ã¡ã³ããã³ã¹ããã¦ãããStarter-kit ã®æ´æ°ã«å¯¾ããéå£ãä½ãããã®ã«ä¸å½¹è²·ã£ã¦ãã¾ãã
å©ç¨ãã Terraform ãã¤ããªã®ä½¿ãåã
移è¡ä½æ¥ãéå§ãã㨠Terraform 0.12 対å¿æ¸ã¿ã®ãµã¼ãã¹ã¨ããã§ãªããµã¼ãã¹ãæ··å¨ãããã¨ã«ãªãã¾ãããã®ãããTerraform ãå®è¡ãããµã¼ãã¹ã«å¿ãã¦ã使ã Terraform ãã¤ããªã使ãåããå¿
è¦ãããã¾ããåæã«ãææ°ã® Provider 㯠Terraform 0.11 以åã«å¯¾å¿ãã¦ããªãå ´åãããã®ã§ãProvider ã®ä½¿ãåããå¿
è¦ã§ãã
ä»å㯠terraform 0.12upgrade
ã³ãã³ãã«ã¦çæããã versions.tf
ã®æç¡ã Terraform å®è¡åã«ç¢ºèªããåå¨ããå ´å㯠Terraform 0.12 ãã¤ããªã¨ Terraform 0.12 対å¿æ¸ã¿ã® Providerãããã§ãªãå ´å㯠Terraform 0.11 ãã¤ããªã¨å¤ããã¼ã¸ã§ã³ã® Provider ã使ãããã«ããå¦çã CI ã«å°å
¥ãã¾ãããä¾ãã°ãTerraform ãã¤ããªã®ä½¿ãåãã¯ä»¥ä¸ã®ãããªã·ã§ã«ã¹ã¯ãªããã§å®è£
ããã¦ãã¾ãã
#!/bin/bash
declare workdir="$PWD"
get_terraform_cmd() {
if [[ -f "${workdir}/versions.tf" ]] && grep -q 'required_version = ">= 0.12"' "${workdir}/versions.tf" >/dev/null; then
echo "terraform-0.12"
else
echo "terraform-0.11"
fi
}
$(get_terraform_cmd) $@
Terraform 0.12 対å¿é²æçã®ç®¡ç
Microservices Platform ã§ã¯ãDevStats ã®ä»çµã¿ãç¨ãã¦ãç¾å¨éç¨ããã¦ãããµã¼ãã¹ã®æ°ã Starter-kit ã®ãã¼ã¸ã§ã³åä½ã§è¦ãããä»çµã¿ãã§ãã¦ãã¾ããããã® Datadog Dashboard ãç¨ãã¦ãTerraform 0.12 対å¿ã®é²æå ·åï¼ç¹å®ãã¼ã¸ã§ã³ä»¥ä¸ã® Starter-kit ãå©ç¨ãã¦ããæ°ï¼ã確èªãã¦ãã¾ããã
ã¡ãªã¿ã«ãä»å¹´é ã«ãµã¼ãã¹ã® Terraform 0.12 対å¿ãéå§ãã¾ããããç¾æç¹ã§æ°è¦ãµã¼ãã¹ãå«ã 86% ã®ãµã¼ãã¹ã Terraform 0.12 対å¿ããã¦ããããã§ããStarter-kit ãã®ãã®ã®ãµãã¼ãããªã·ã¼ãå«ãã対å¿ã®è¿½ãã¤ãã¦ãªããµã¼ãã¹ãã©ã®ããã«ã±ã¢ãã¦ãããã¯ä»å¾ã®èª²é¡ã§ãã
ã¾ã¨ã
æ¬è¨äºã§ã¯ãã¡ã«ã«ãª/ã¡ã«ãã¤åãã«éç¨ãã¦ãã Microservices Platform ã® Terraform ãªãã¸ããªã«ã¦ãã©ã®ããã« Terraform 0.12 対å¿ä½æ¥ãè¡ã£ããã«ã¤ãã¦è§£èª¬ãã¾ãããã¡ã«ã«ãªç¬èªã®ç®¡çææ³ãå¤åã«å«ã¾ãããããä»åå ¬éããæ¹æ³ããã¹ã¦ã®ç°å¢ã«ã¦é©ç¨ã§ããã¨ã¯è¨ãåããªãã§ãããå°ãã§ãåèã«ãªãã°å¹¸ãã§ãã