ããŒãããKamal Marhubiãžã®èšèã
ã€ã³ãã©ã¹ãã©ã¯ãã£ã¯AWSã«åºã¥ããŠãããTerraformã§ç®¡çããŠããŸãã ãã®åºçç©ã§ã¯ãäœæ¥äžã«åœ¹ç«ã€å®çšçãªãã³ããšã³ããåãäžããŸããã
Terraformããã³ã³ãŒãã¬ãã«ã®ã€ã³ãã©ã¹ãã©ã¯ãã£
Terraformã¯ãã€ã³ãã©ã¹ãã©ã¯ãã£ã®å®£èšçãªç®¡çãæ¯æŽããHashicorpã®ããŒã«ã§ãã ãã®å Žåãã€ã³ã¹ã¿ã³ã¹ããããã¯ãŒã¯ãªã©ãæåã§äœæããå¿ èŠã¯ãããŸããã ã¯ã©ãŠããããã€ããŒã®ã³ã³ãœãŒã«ã§; å°æ¥ã®ã€ã³ãã©ã¹ãã©ã¯ãã£ãã©ã®ããã«èŠãããæŠèª¬ããæ§æãèšè¿°ããã ãã§ãã ãã®æ§æã¯ã人éãèªã¿åããããã¹ã圢åŒã§äœæãããŸãã ã€ã³ãã©ã¹ãã©ã¯ãã£ãå€æŽããå Žåã¯ãæ§æãç·šéããŠ
terraform apply
ãå®è¡ã
terraform apply
ã Terraformã¯ãã¯ã©ãŠããããã€ããŒã«APIåŒã³åºããã«ãŒãã£ã³ã°ããã€ã³ãã©ã¹ãã©ã¯ãã£ããã®ãã¡ã€ã«ã§æå®ãããæ§æã«åãããŸãã
ã€ã³ãã©ã¹ãã©ã¯ãã£ç®¡çãããã¹ããã¡ã€ã«ã«ç§»è¡ãããšããœãŒã¹ã³ãŒããšããã»ã¹ã管çããããã®ãã¹ãŠã®ãæ°ã«å ¥ãã®ããŒã«ã䜿çšããŠãã€ã³ãã©ã¹ãã©ã¯ãã£ã§åäœããããã«æ¹åãå€ããããšãã§ããŸãã çŸåšãã€ã³ãã©ã¹ãã©ã¯ãã£ã¯ããœãŒã¹ã³ãŒããšåæ§ã«ããŒãžã§ã³ç®¡çã·ã¹ãã ã®å¯Ÿè±¡ãšãªããŸããäœãåé¡ãçºçããå Žåãåãæ¹æ³ã§ã¬ãã¥ãŒãããã以åã®ç¶æ ã«ããŒã«ããã¯ãããã§ããŸãã
ããšãã°ãTerraformãEBSããªã¥ãŒã ã§EC2ã€ã³ã¹ã¿ã³ã¹ãå®çŸ©ããæ¹æ³ã¯æ¬¡ã®ãšããã§ãã
resource "aws_instance" "example" { ami = "ami-2757f631" instance_type = "t2.micro" ebs_block_device { device_name = "/dev/xvdb" volume_type = "gp2" volume_size = 100 } }
TerraformããŸã è©ŠããŠããªãå Žåã¯ããã®åå¿è åãã¬ã€ããé©åã§ããããã®ããŒã«ã®ã¿ã¹ã¯ã®æµãã«ããã«æ £ããã®ã«åœ¹ç«ã¡ãŸãã
å°åœ¢ããŒã¿ã¢ãã«
äžè¬çãªèŠ³ç¹ã§ã¯ãTerraformããŒã¿ã¢ãã«ã¯åçŽã§ããTerraformã¯ãªãœãŒã¹ã管çãããªãœãŒã¹ã«ã¯å±æ§ããããŸãã AWSã®äžçããã®äŸïŒ
- ã€ã³ã¹ã¿ã³ã¹EC2ã¯ããã·ã³ã¿ã€ããããŒãã€ã¡ãŒãžãã¢ãã€ã©ããªãã£ãŒãŸãŒã³ãã»ãã¥ãªãã£ã°ã«ãŒããªã©ã®å±æ§ãæã€ãªãœãŒã¹ã§ã
- EBSããªã¥ãŒã ã¯ãããªã¥ãŒã ãµã€ãºãããªã¥ãŒã ã¿ã€ããIOPSãªã©ã®å±æ§ãæã€ãªãœãŒã¹ã§ã
- ãšã©ã¹ãã£ãã¯ããŒããã©ã³ãµãŒã¯ãããã¯ã¢ããã€ã³ã¹ã¿ã³ã¹ã®å±æ§ããã®ããã©ãŒãã³ã¹ç¹æ§ãããã³ãã®ä»ã®çŸè±¡ãåãããªãœãŒã¹ã§ãã
Terraformã¯ãæ§æãã¡ã€ã«ã«èšè¿°ãããŠãããªãœãŒã¹ãšãã¯ã©ãŠããããã€ããŒã®å¯Ÿå¿ãããªãœãŒã¹ã®ãããã³ã°ãæäŸããŸãã ãã®ãããã³ã°ã¯ç¶æ ãšåŒã°ãã巚倧ãªJSONãã¡ã€ã«ã§ãã
terraform apply
Terraformã¯å¯Ÿå¿ãããªã¯ãšã¹ããã¯ã©ãŠããããã€ããŒã«éä¿¡ããŠç¶æ ãæŽæ°ããŸãã 次ã«ãè¿ããããªãœãŒã¹ãTerraformæ§æã«èšé²ãããŠããæ å ±ãšæ¯èŒããŸãã éããèŠã€ãã£ãå Žåãå®éã®æ§æãæ§æã§æå®ãããæ§æãšäžèŽããããã«ãæ¬è³ªçã«ã¯ã©ãŠããããã€ããŒã®ãªãœãŒã¹ã«å¯ŸããŠè¡ãå¿ èŠãããå€æŽã®ãªã¹ããäœæããŸãã æåŸã«ãTerraformã¯ãããã®å€æŽãé©çšããã¯ã©ãŠããããã€ããŒãžã®é©åãªåŒã³åºããæ瀺ããŸãã
ãã¹ãŠã®TerraformãªãœãŒã¹ãAWSãªãœãŒã¹ã§ã¯ãªã
ãªãœãŒã¹ãšå±æ§ãåãããã®ãããªããŒã¿ã¢ãã«ãç解ããããšã¯ããã»ã©é£ãããããŸããããã¯ã©ãŠããããã€ããŒAPIãšå®å šã«ã¯äžèŽããªãå ŽåããããŸãã å®éãåäžã®TerraformãªãœãŒã¹ã¯ãã¯ã©ãŠããããã€ããŒã®1ã€ãŸãã¯è€æ°ã®åºæ¬ãªããžã§ã¯ãã«å¯Ÿå¿ã§ããŸãã AWSããã®äŸãããã€ã瀺ããŸãã
-
aws_ebs_volume
ã¯ã1ã€ã®AWS EBSããªã¥ãŒã ãšäžèŽããŸã - åã®äŸã®ããã«
ebs_block_device
ãããã¯ãæã€Terraformã®aws_instance
ã¯ã2ã€ã®EC2ãªãœãŒã¹ã«å¯Ÿå¿ããŠããŸãïŒã€ã³ã¹ã¿ã³ã¹ãš -
aws_volume_attachment
ã¯ãEC2ã®ã©ã®ãªããžã§ã¯ããšãäžèŽããŸããïŒ
åŸè ã¯é©ãã¹ãããšã«æãããããããŸããã
aws_volume_attachment
äœæãããšãTerraformã¯
AttachVolume
ãªã¯ãšã¹ããäœæããŸãã ãã®ããªã¥ãŒã ãç Žå£ããããšã
DetachVolume
ãªã¯ãšã¹ããéä¿¡ãã
DetachVolume
ã åäžã®EC2ãªããžã§ã¯ãã¯é¢ä¿ããŠããŸãã
aws_volume_attachment
ã¯å®å šã«åæãããŠããŸãïŒ Terraformã®ãã¹ãŠã®ãªãœãŒã¹ãšåæ§ã«ãIDããããŸãã ãã ããã»ãšãã©ã®å ŽåãIDã¯ã¯ã©ãŠããããã€ããŒããè³Œå ¥ãããŸããã
aws_volume_attachment
IDã¯ãããªã¥ãŒã IDãã€ã³ã¹ã¿ã³ã¹IDãããã³ããã€ã¹åããã®åãªãããã·ã¥ã§ãã Terraformã«åæãªãœãŒã¹ã衚瀺ãããä»ã®ã±ãŒã¹ããããŸã
aws_route53_zone_association
ã
aws_elb_attachment
ã
aws_security_group_rule
ã ããããèŠã€ããã«ã¯ã
association
ãŸãã¯
attachment
ãªãœãŒã¹ã®ååã§æ€çŽ¢ã§ããŸãããåžžã«åœ¹ç«ã€ãšã¯éããŸããã
ãã¹ãŠã®ã¿ã¹ã¯ã¯ããã€ãã®æ¹æ³ã§è§£æ±ºããããããéžæããéã¯æ³šæããŠãã ããïŒ
Terraformã䜿çšããå ŽåããŸã£ããåãã€ã³ãã©ã¹ãã©ã¯ãã£ãããã€ãã®ç°ãªãæ¹æ³ã§è¡šãããšãã§ããŸãã Terraformã®EBSããªã¥ãŒã ã䜿çšããã€ã³ã¹ã¿ã³ã¹äŸã®èª¬æã®å¥ã®ããŒãžã§ã³ã¯ããŸã£ããåãEC2ãªãœãŒã¹ãæäŸããŸãã
resource "aws_instance" "example" { ami = "ami-2757f631" instance_type = "t2.micro" } resource "aws_ebs_volume" "example-volume" { availability_zone = "${aws_instance.example.availability_zone}" type = "gp2" size = 100 } resource "aws_volume_attachment" "example-volume-attachment" { device_name = "/dev/xvdb" instance_id = "${aws_instance.example.id}" volume_id = "${aws_ebs_volume.example-volume.id}" }
EBSããªã¥ãŒã ã¯Terraformã®æ¬æ ŒçãªãªãœãŒã¹ã«ãªããŸãããEC2ã€ã³ã¹ã¿ã³ã¹ããåºåããŸããã æåã®2ã€ããªã³ã¯ãã3çªç®ã®åæãªãœãŒã¹ããããŸãã ã€ã³ã¹ã¿ã³ã¹ãšããªã¥ãŒã ãæ³åãããšã
aws_ebs_volume
ããã³
aws_volume_attachment
ãè¿œå ããã³åé€ããã ãã§ãããªã¥ãŒã ãè¿œå ããã³åé€ã§ããŸãã
å€ãã®å ŽåãéžæããEBSã®è¡šçŸã¯é¢ä¿ãããŸããã ããããéžæãééã£ãŠããå Žåããã®åŸã®ã€ã³ãã©ã¹ãã©ã¯ãã£ã®å€æŽã¯éåžžã«å°é£ã«ãªãããšããããŸãïŒ
ç§ãã¡ã¯éžæãééããŸãã
ããã¯ç§ãã¡ãããã©ããå Žæã§ãã 倧èŠæš¡ãªAWS PostgreSQLã¯ã©ã¹ã¿ãŒã䜿çšããŠããã18åã®EBSããªã¥ãŒã ãã¹ãã¬ãŒãžãšããŠåã€ã³ã¹ã¿ã³ã¹ã«æ¥ç¶ãããŠããŸãã ãããã®ã€ã³ã¹ã¿ã³ã¹ã¯ãã¹ãŠã
ebs_block_device
ãããã¯ã§å®çŸ©ãããEBSããªã¥ãŒã ãæã€å¯äžã®aws_instanceãªãœãŒã¹ãšããŠTerraformã§è¡šãããŸãã
ããŒã¿ããŒã¹ã®ã€ã³ã¹ã¿ã³ã¹ã§ã¯ãæ å ±ã¯ZFSãã¡ã€ã«ã·ã¹ãã ã«ä¿åãããŸãã ZFSã䜿çšãããšããããã¯ããã€ã¹ãåçã«è¿œå ããŠãé 延ãªããã¡ã€ã«ã·ã¹ãã ãæ¡åŒµã§ããŸãã ãããã£ãŠã顧客ããã®ããŒã¿éä¿¡éãå¢ããã«ã€ããŠãã¹ãã¬ãŒãžãåŸã ã«å¢ãããŠãããŸãã ç§ãã¡ã¯åæäŒç€Ÿã§ãããããããçš®é¡ã®æ å ±ãåéããããããã®ãããªæ©äŒã¯ç§ãã¡ã«ãšã£ãŠå€§ããªå©ãã«ãªããŸãã ã¯ãšãªãåžžã«æé©åããã¯ã©ã¹ã¿ã«æäœãæ¿å ¥ããŸã ã ãããã£ãŠãã¯ã©ã¹ã¿ãŒãæºåãããšãã«éžæããå³æ ŒãªCPUã¹ãã¬ãŒãžæ¯çã«ãšããããã«ãææ°ã®ã€ãããŒã·ã§ã³ãå¹æçã«äœ¿çšããããã«ããã®å Žã§ãã©ã³ã¹ã調æŽããããšãã§ããŸãã
ebs_block_device
ãããã¯ã䜿çšããªãå Žåããã®ããã»ã¹ã¯ããã«ã¹ã ãŒãºã«
ebs_block_device
ãŸãã ã¯ããTerraformã
ebs_block_device
ã®19çªç®ã®ãããã¯ãaws_instance
aws_instance
è¿œå ããããšãæåŸ ã§ã
aws_instance
ããã¹ãŠãæ£åžžã«æ©èœã
aws_instance
ã ãã ããTerraformã¯ããã§å§åçãªå€æŽã確èªããŸãã圌ã¯18ããªã¥ãŒã ã®ã€ã³ã¹ã¿ã³ã¹ã19ã«å€æŽããæ¹æ³ããç¥ããŸãããããããTerraformã¯ã€ã³ã¹ã¿ã³ã¹å šäœãç Žæ£ãã代ããã«æ°ããã€ã³ã¹ã¿ã³ã¹ãäœæããŸãã å°ãªããšãããã©ãã€ãã®æ å ±ãä¿åãããŠããããŒã¿ããŒã¹ã«äŒŒããã®ã欲ããã£ãã®ã§ãïŒ
æè¿ãŸã§ãåé¿çã䜿çšããããã€ãã®æ®µéã§TerraformãåæãããŸããã
- AWS CLIã䜿çšããŠããªã¥ãŒã ãäœæããã³è¿œå ããã¹ã¯ãªãããå®è¡ããŸãã
-
terraform refresh
å®è¡ããŠãTerraformãç¶æ ãæŽæ°ãã - æçµçã«æ°ããçŸå®ã«åãããŠåæ§æãããŸãã
ã¹ããã2ãš3ã®éã§ã
terraform plan
ããŒã ã¯ãTerraformãããŒã¿ããŒã¹ã®ãã¹ãŠã®ã€ã³ã¹ã¿ã³ã¹ãç Žå£ããŠåäœæããããšããŠããããšã瀺ããŸãã ãããã£ãŠã誰ããæ§æãæŽæ°ãããŸã§ãTerraformã§ãããã®ã€ã³ã¹ã¿ã³ã¹ãæäœããããšã¯ã§ããŸããã§ããã èšããŸã§ããªãããã®ç¶æ ãæ°žç¶çã«ç¶æããããšã¯ã©ãã»ã©æãããããšã§ãããã
Terraform StateïŒæè¡ãžã®ç§»è¡
aws_volume_attachment
ã䜿çšããã¢ãããŒããçºèŠããããããã¥ãŒãåæ§ç¯ããããšã«ããŸããã åããªã¥ãŒã ã¯ã
aws_ebs_volume
ãšaws_volume_attachmentã®2ã€ã®æ°ããTerraformãªãœãŒã¹ã«å€ãããŸããã ã¯ã©ã¹ã¿ãŒå ã®ã€ã³ã¹ã¿ã³ã¹ããšã«18ã®ããªã¥ãŒã ãããã1000ãè¶ ããæ°ãããªãœãŒã¹ãç®ã®åã«äžŠãã§ããŸãã ãã¥ãŒã®åæ§ç¯ã¯ãTerraformæ§æã®å€æŽã ãã§ã¯ãããŸããã Terraformã®æäžéšã«å°éãããªãœãŒã¹ã®ããžã§ã³ãå€æŽããå¿ èŠããããŸããã
1,000ãè¶ ãããªãœãŒã¹ãè¿œå ãããããæåã§è¿œå ããããšã¯çµ¶å¯Ÿã«ãããŸããã§ããã Terraformã¹ããŒã¿ã¹ã¯JSON圢åŒã§ä¿åãããŸãã ãã®åœ¢åŒã¯å®å®ããŠããŸãããããã¥ã¡ã³ãã«ã¯ã ã¹ããŒã¿ã¹ã®ãããã¡ã€ã«ãçŽæ¥ç·šéããããšã¯ãå§ãã§ããŸãã ããšèšèŒãããŠããŸã ã ç§ãã¡ã¯ãŸã ãããããªããã°ãªããŸããããç§ãã¡ã¯ãããæ£ããããŠããããšã確èªãããã£ãã®ã§ãã JSON圢åŒã®ãªããŒã¹éçºã«åŸäºããªãããšã«ããŸããããèªã¿åããå€æŽãæžã蟌ã¿çšã®ã©ã€ãã©ãªãšããŠTerraformå éšèŠçŽ ã䜿çšããããã°ã©ã ãäœæããŸããã ç°¡åãªããšã§ã¯ãããŸããã§ããããªããªããç§ãã¡å šå¡ã«ãšã£ãŠãGoã§äœæ¥ããæåã®ããã°ã©ã ã ã£ãããã§ãïŒ ãã ãã確èªããå¿ èŠããããšèããŸãããã¯ããããŒã¿ããŒã¹ã®ãã¹ãŠã®ã€ã³ã¹ã¿ã³ã¹ã®ãã¹ãŠã®Terraformç¶æ ã1ã€ã®ããŒãã«æ··åããªãã§ãã ããã
ãã®ããŒã«ãGitHubã«æçš¿ããŸããããã®ããŒã«ã§éãã§ã¿ãŠãèªåã®éŽã§èªåãæãããå Žåã«åããŠã
æ£ç¢ºãªå°åœ¢
terraform apply
ã®éå§ã¯ãäŒæ¥ã€ã³ãã©å šäœã«æ·±å»ãªæ害ãäžããå¯èœæ§ã®ããæ°å°ãªãè¡çºã®1ã€ã§ãã ããã€ãã®ãã³ãããããŸããããã®åŸããªã¹ã¯ãæžããããšãã§ããŸã-äžè¬çã«ã¯ããã»ã©æããªãã§ãããã
åžžã«âout
èšç»ãæºåãããã®èšç»ã«åŸã£ãŠãã ãã
terraform plan -out planfile
ãå®è¡ãããšãTerraformã¯
terraform plan -out planfile
ã«èšç»ã
planfile
ãŸãã ãã®åŸã
terraform apply planfile
å®è¡
terraform apply planfile
ã«ããããã®èšç»ãæ£ç¢ºã«ååŸã§ã
terraform apply planfile
ã ãããã£ãŠããã®æç¹ã§é©çšãããå€æŽã¯ãèšç»æã«Terraformã衚瀺ããå 容ã«æ£ç¢ºã«å¯Ÿå¿ããŠããŸãã äŸå€ã¯ãååã®1人ããèšç»ãæäœãšãé©çšãæäœã®éã§ã€ã³ãã©ã¹ãã©ã¯ãã£ã調æŽããããã«ãã€ã³ãã©ã¹ãã©ã¯ãã£ãçªç¶å€æŽãããå¯èœæ§ãããç¶æ³ã§ãã
ãã ãããã®ãã¡ã€ã«ãæäœãããšãã¯æ³šæããŠãã ãããTerraformå€æ°ã¯ããã«å«ãŸããŠãããããããã«äœãç§å¯ãæžããšã ãã®æ å ±ã¯æå·åãããŠããªã圢åŒã§ãã¡ã€ã«ã·ã¹ãã ã«èšé²ãããŸã ã ããšãã°ãè³æ Œæ å ±ãå€æ°ãšããŠã¯ã©ãŠããããã€ããŒã«è»¢éããå Žåãè³æ Œæ å ±ã¯ãã¬ãŒã³ããã¹ããšããŠãã£ã¹ã¯ã«ä¿åãããŸãã
èªã¿åãå°çšã®IAMããŒã«ãäœæããŠå€æŽãåæãã
Terraform
terraform plan
éå§ãããš
terraform plan
Terraformã¯ã¢ãŒããã¯ãã£ã®åºæ¬ãã¥ãŒãæŽæ°ããŸãã ãããè¡ãã«ã¯ãèªã¿åãå°çšæš©éãæã€ã¯ã©ãŠããããã€ããŒãžã®ã¢ã¯ã»ã¹ã®ã¿ãå¿ èŠã§ãã 圌ã«ãã®ãããªåœ¹å²ãäžããã®ã§ãæ§æã«å ããããå€æŽã
terraform plan
ã䜿çšããŠç¢ºèªããäžæ³šæãª
apply
ããŒã ã1æ¥ãŸãã¯1é±éã§ããªãã®ããã«è¡ã£ããã¹ãŠã®äœæ¥ãåãæ¶ãå±éºãåãããšããã§ããŸããïŒ
AWSã䜿çšãããšãTerraformã§IAMããŒã«ãšé¢é£ããæš©éã管çã§ããŸãã Terraformã®åœ¹å²ã¯æ¬¡ã®ããã«ãªããŸãã
resource "aws_iam_role" "terraform-readonly" { name = "terraform-readonly" path = "/", assume_role_policy = "${data.aws_iam_policy_document.assume-terraform-readonly-role-policy.json}" }
assume_role_policy
ã¯ããã®ããŒã«ã®åãå ¥ãã
assume_role_policy
ããããŠãŒã¶ãŒãåã«ãªã¹ãããŸãã
æåŸã«ããã¹ãŠã®AWSãªãœãŒã¹ãžã®èªã¿åãå°çšã¢ã¯ã»ã¹ãæäŸããããªã·ãŒãå¿ èŠã§ãã Amazonã¯ãããªã·ãŒã®èª¬æãèšèŒãããããã¥ã¡ã³ãã芪åã«æäŸããŸããããã¯ãã³ããŒããŠè²Œãä»ããããšãã§ããŸããããã¯ã䜿çšããããã¥ã¡ã³ãã§ãã ãã®ããã¥ã¡ã³ããåç §ãã
aws_iam_policy
ããªã·ãŒãå®çŸ©ããŸãã
resource "aws_iam_policy" "terraform-readonly" { name = "terraform-readonly" path = "/" description = "Readonly policy for terraform planning" policy = "${file("policies/terraform-readonly.json")}" }
次ã«ã
aws_iam_policy_attachment
ãè¿œå ããªãããããªã·ãŒã
aws_iam_policy_attachment
terraform-readonly
ããŒã«ã«é©çšããŸãã
resource "aws_iam_policy_attachment" "terraform-readonly-attachment" { name = "Terraform read-only attachment" roles = ["${aws_iam_role.terraform-readonly.name}"] policy_arn = "${aws_iam_policy.terraform-readonly.arn}" }
ããã§ãSecure Token Service APIã®äžéšã§ãã
AssumeRole
ã¡ãœããã䜿çšããŠãAWSã®ã¿ããªã¯ãšã¹ãã§ããäžæçãªèªèšŒæ å ±ãååŸã§ããŸãããå€æŽã¯ã§ããŸããã
terraform plan
èµ·åããããšã«ãããTerraformã®ç¶æ ãæŽæ°ããã€ã³ãã©ã¹ãã©ã¯ãã£ã®çŸåšã®ç¶æ ãåæ ããããã«ããŸãã ããŒã«ã«ç¶æ ã§äœæ¥ããŠããå Žåããã®æ å ±ã¯
terraform.tfstate
ãã¡ã€ã«ã«æžã蟌ãŸããŸãã ããšãã°ãS3ã§ãªã¢ãŒãç¶æ ã䜿çšããå Žåãèªã¿åãå°çšããŒã«ã«ã¯æžã蟌ã¿æš©éãå¿ èŠã«ãªããŸããããããªããšãS3ã«å°éã§ããŸããã
ããŒã¿ããŒã¹
aws_volume_attachment
ã§
aws_volume_attachment
ã䜿çšããããã«Terraformã®ç¶æ å šäœãæžãçŽããããããã®ããŒã«ãæŽçããæ¹ãã¯ããã«ç°¡åã§ããã AWSã€ã³ãã©ã¹ãã©ã¯ãã£ã§å€æŽãèšç»ãããŠããªãããšã¯ããã£ãŠããŸãããTerraformã§ã®ãã¬ãŒã³ããŒã·ã§ã³ã®ã¿ãå€æŽãããŸãã æçµçã«ãã€ã³ãã©ã¹ãã©ã¯ãã£ãå®å šã«å€æŽããã€ããã¯ãããŸããã§ããããªããã®ãããªæ©äŒãå¿ èŠãªã®ã§ããããã
æªæ¥ãžã®ã¢ã€ãã¢
ç§ãã¡ã®ããŒã ã¯æé·ããŠãããæ°ããåŸæ¥å¡ã¯Terraformã§ã€ã³ãã©ã¹ãã©ã¯ãã£ã«å€æŽãå ããããšãåŠãã§ããŸãã ãã®ããã»ã¹ã¯ã·ã³ãã«ã§å®å šãªãã®ã«ãããã§ãã ã»ãšãã©ã®é害ã¯äººçºçãšã©ãŒãšæ§æã®å€æŽã«é¢é£ããŠãã ãTerraformã䜿çšããå€æŽã¯äž¡æ¹ã«äŒŽãå¯èœæ§ããããŸããæãããããšã§ãã
ããšãã°ãå°ããªããŒã ã§ã¯ãåžžã«1人ã ããTerraformã§äœæ¥ããããšãä¿èšŒããã®ã¯ç°¡åã§ãã 倧èŠæš¡ãªããŒã ã§ã¯ããããä¿èšŒããããšã¯ã§ããŸãã-æåŸ ããã ãã§ãã
terraform apply
ã2ã€ã®ããŒãããåæã«å®è¡ãããå Žåãçµæã¯ã²ã©ãé決å®çããã·ã¥ã«ãªãå¯èœæ§ããããŸãã Terraform 0.9ã§ã¯ã ç¶æ ãããã¯ããæ©èœãå°å ¥ãããŸãããããã«ããã
terraform apply
1ã€ã®
terraform apply
ã³ãã³ãã®ã¿ã
terraform apply
ã§ããŸãã
ç°¡åããšã»ãã¥ãªãã£ãå®çŸãããå¥ã®äœæ¥é åã¯ãã€ã³ãã©ã¹ãã©ã¯ãã£ã«å ããããå€æŽã®ã¬ãã¥ãŒã§ãã ãã®æ®µéã§ã¯ãã¬ãã¥ãŒããéã«ã
terraform plan
åºåãã³ããŒããŠã¬ãã¥ãŒãžã®ã³ã¡ã³ããšããŠè²Œãä»ããŸãããªãã·ã§ã³ãæ¿èªããããããã¹ãŠã®å€æŽãæåã§è¡ããŸãã
Terraformã®æ§æãæ€èšŒãããšãã«ãç¶ç¶ççµ±åããŒã«ã䜿çšããããã«æ¢ã«é©åããŠããŸãã
terraform validate
ã
terraform validate
ã³ãã³ããå®è¡ããã ãã§ãããŒã«ã¯ã³ãŒãã®æ§æãšã©ãŒããã§ãã¯ããŸãã 次ã®ã¿ã¹ã¯ã¯ã
terraform plan
ãèµ·åããã€ã³ãã©ã¹ãã©ã¯ãã£ã«å ããããå€æŽãã³ãŒãã¬ãã¥ãŒã®ã³ã¡ã³ããšããŠè¡šç€ºããããã«ãç¶ç¶ççµ±åããŒã«ãé©åãããããšã§ãã ç¶ç¶çã€ã³ãã°ã¬ãŒã·ã§ã³ã·ã¹ãã ã¯ãå€æŽãæ¿èªããããšããã«ã
terraform apply
ãèªåçã«èµ·åã
terraform apply
ã ãã®ãããæåã§å®è¡ããå¿ èŠãããæé ã®1ã€ãé€å€ããã³ã¡ã³ãã§è¿œè·¡å¯èœãªãããäžè²«ããå¶åŸ¡ãã©ãã¯ïŒå€æŽå±¥æŽïŒãæäŸããŸãã Terraform EnterpriseããŒãžã§ã³ã«ã¯ãã®æ©èœããããŸãããã®ããã詳现ã確èªããããšããå§ãããŸãã