AWS\[XTerraform̊Ǘɒu@FuAWSv~uTerraformvŊwԃNEh̃CtǗi7j - IT

AWS\[XTerraform̊Ǘɒu@FuAWSv~uTerraformvŊwԃNEh̃CtǗi7j

Ctc[̈‚łuTerraformvɂ‚āAꂩwڂƂAgĂΏۂɁATerraform̓@{IȎgЉĂ{AځB́AȑO痘pĂNEh\[XTerraformŊǗ@ɂ‚āB

» 2024N0606 0500 J
[c[CCTCIXeNmW[]

̋L͉łBo^ijƑSĂ܂B

@Ctc[̈‚łuTerraformvɂ‚āATerraform̓@{IȎgЉĂ{ABO܂ŁATerraform𗘗pĐVɃNEh\[X쐬ъǗ@ЉĂ܂B

@̉b𓾂邽߂Terraform̗pi߂ĂƁÃNEh\[XTerraformŊǗȂł傤BṓÃNEh\[XTerraform̊Ǘɒu@\̎gЉ܂B

̃NEh\[XTerraformŊǗ@

@̃NEh\[XTerraformǗɒuC[W‚ނ߂ɁAƂō쐬uAmazon Elastic Compute CloudiAmazon EC2jṽCX^XiȉAEC2CX^XjTerraformŊǗł悤ɂ܂傤B

@܂Aȉ̗v̂EC2CX^XƂō쐬܂B

ݒ荀 ݒl
CX^X test
Amazon}VC[WiAMIj Amazon Linux 2023 AMI
A[LeN` 64bitix86j
CX^X^Cv t2.micro
L[yA L[yAȂős
ZLeBO[v ̃ZLeBO[vIidefaultj
[g{[TCY 8 GiB
[g{[^Cv gp2

@쐬EC2CX^XTerraformŊǗ鏀܂B܂͑Ώۂ̃CX^X IDAMI IDKvł̂ŁAꂼTĂ܂B

T̉ӏ T̉ӏ

@āAEC2CX^XTerraformǗɒu߁A܂͈ȉ̂悤TerraformR[h쐬܂Bami̕ɂ͐قǍTAMI ID͂ĂB

resource "aws_instance" "test" {
  ami           = "ami-0dfa284c9d7b2adad"
  instance_type = "t2.micro"
}

@ɁAȉ̃R}hsāAEC2CX^XTerraform̊Ǘɒu܂B

$ terraform import aws_instance.test i-xxxxxxxxxxxxxxxxx
aws_instance.test: Importing from ID "i-xxxxxxxxxxxxxxxxx"...
aws_instance.test: Import prepared!
  Prepared aws_instance for import
aws_instance.test: Refreshing state... [id=i-xxxxxxxxxxxxxxxxx]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

@R}h̎sʂċCtlƎv܂A\[XTerraform̊ǗɒuƂuC|[gvƌĂт܂B̂߁AsR}himportɂȂĂ܂BR}h̃p[^[ƂāAC|[gƂȂTerraform̃\[Xw肵ǍɃC|[g̃\[X IDw肵Ă܂B

@C|[g͊܂Â܂܂łTerraformR[hƃ\[X̏ԂvĂ܂B̂߁Aȉ̃R}hsčقmF܂B

$ terraform plan
aws_instance.test: Refreshing state... [id=i-xxxxxxxxxxxxxxxxx]
Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
  ~ update in-place
Terraform will perform the following actions:
  # aws_instance.test will be updated in-place
  ~ resource "aws_instance" "test" {
        id                                   = "i-xxxxxxxxxxxxxxxxx"
      ~ tags                                 = {
          - "Name" = "test" -> null
        }
      ~ tags_all                             = {
          - "Name" = "test"
        } -> (known after apply)
      + user_data_replace_on_change          = false
        # (29 unchanged attributes hidden)
        # (8 unchanged blocks hidden)
    }
Plan: 0 to add, 1 to change, 0 to destroy.

Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.

@R}h̏o͌ʂAقĂ̂tagsuser_data_replace_on_change2‚ƕ܂BtagśAEC2CX^Xݒ肷ełAuser_data_replace_on_changê܂B

@Terraform̃hLgmFƁÃp[^[̓ftHglfalseŁATerraformǗۂ̃ftHglݒ肷邾̂悤Ɍ܂B

@]āA\[X̏󋵂TerraformR[hvɂ́Atagsݒ肷΂悳łBATerraformR[hȉ̂悤ɏC܂傤B

resource "aws_instance" "test" {
  ami           = "ami-0dfa284c9d7b2adad"
  instance_type = "t2.micro"
  tags = {
    Name = "test"
  }
}

@ɁAقꂽǂmF邽߁AقǂƓ悤terraform planR}hsĊmF܂B

$ terraform plan
aws_instance.test: Refreshing state... [id=i-xxxxxxxxxxxxxxxxx]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and
found no differences, so no changes are needed.

@Ȃuser_data_replace_on_change̍ق܂AɃ\[X̏󋵂TerraformR[hv܂B̂悤ɁÃ\[XTerraform̊Ǘɒuɂ́AΉTerraformR[h쐬ŃC|[gƂ{Aق𖄂߂ĂKv܂B

@ł́Ã\[XTerraform̊Ǘɂ邱ƂmF邽߂ɁATerraformR[hҏWterraform applyR}hsAύXKpꂽǂmF܂傤B͈ȉ̂悤ɃCX^X^Cvt2.microt3a.microɕύX܂B

resource "aws_instance" "test" {
  ami           = "ami-0dfa284c9d7b2adad"
  instance_type = "t3a.micro"
  tags = {
    Name = "test"
  }
}

@ɁAύXKp邽߂terraform applyR}hs܂B

$ terraform apply
aws_instance.test: Refreshing state... [id=i-xxxxxxxxxxxxxxxxx]
Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
  ~ update in-place
Terraform will perform the following actions:
  # aws_instance.test will be updated in-place
  ~ resource "aws_instance" "test" {
        id                                   = "i-xxxxxxxxxxxxxxxxx"
      ~ instance_type                        = "t2.micro" -> "t3a.micro"
        tags                                 = {
            "Name" = "test"
        }
      + user_data_replace_on_change          = false
        # (29 unchanged attributes hidden)
        # (8 unchanged blocks hidden)
    }
Plan: 0 to add, 1 to change, 0 to destroy.
Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.
  Enter a value: yes
aws_instance.test: Modifying... [id=i-xxxxxxxxxxxxxxxxx]
aws_instance.test: Still modifying... [id=i-xxxxxxxxxxxxxxxxx, 10s elapsed]
aws_instance.test: Still modifying... [id=i-xxxxxxxxxxxxxxxxx, 20s elapsed]
aws_instance.test: Still modifying... [id=i-xxxxxxxxxxxxxxxxx, 30s elapsed]
aws_instance.test: Still modifying... [id=i-xxxxxxxxxxxxxxxxx, 40s elapsed]
aws_instance.test: Modifications complete after 42s [id=i-xxxxxxxxxxxxxxxxx]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

@TerraformR}h͕ύX悤ł̂ŁA}lWgR\[ʂŌĂ݂ƁAύXfĂ邱ƂmFł܂B

CX^X^CvύXĂ CX^X^CvύXĂ

EC2CX^XȊÕ\[XC|[gɂ́H

@ʓIɁAAmazon Web ServicesiAWSjgč\zꂽ‹EC2CX^XȊOɂ܂܂ȃNEh\[X݂Ǝv܂B̃NEh\[XTerraform̊Ǘɒuꍇ́AOqʂC|[gƂKvɂȂ܂BimportR}hɎw肷̂́ANEh\[XƂɍׂقȂ܂B

@ł́uAmazon Elastic Block StoreiAmazon EBSjvuAWS Identity and Access ManagementiIAMjvuAmazon Simple Storage ServiceiAmazon S3jv\[XC|[gۂɕKvȏ‚Љ܂B

NEh\[X R}hɎw肷鎯ʎq R}h
EC2CX^X i-n܂CX^X ID terraform import aws_instance.example i-xxxxxxxxxxxxxxxxx
EBS{[ vol-n܂{[ ID terraform import aws_ebs_volume.example vol-xxxxxxxxxxxxxxxxx
IAM [U[ IAM [U[ terraform import aws_iam_user.example user-name
S3 oPbg S3 oPbg terraform import aws_s3_bucket.example bucket-name

@C|[głǂ̂悤ȏw肷΂悢̂ƒm肽ĺATerraform̃hLgQƂĂ݂ĂB

@TerraformgOɎƂō쐬ĂNEh\[XATerrafromŊǗł܂Bu^pɓĂ̂Ŏ̉b󂯂Ȃccvƒ߂Kv͂܂BЁA{LQlɊ̃NEh\[XTerraformŊǗĂ݂ĂB

MҏЉ

c[C

TCIXeNmW[BOSS 낸kŃT|[gΉĂeNjJT|[gGWjABAnsible ɏoĂ玩Ɏ߂Ag̋ƖvCx[gł̂̎ɎgށBvCx[gł Java łƂc[̊JɂĂB

TCIX OSS 낸k

TCIXeNmW[GWjAuO

TCIXeNmW[GWjA YouTube `l


Copyright © ITmedia, Inc. All Rights Reserved.

X|T[̂m点PR

ڂ̃e[}

4AI by IT - AIAAA
Microsoft  WindowsőO2025
AI for GWjAO
[R[h^m[R[h Zg by IT - ITGWjArWlX̒SŊ􂷂gD
Cloud Native Central by IT - XP[uȔ\͂gD
VXeJmEnE yirzPR
Ȃɂ߂̋LPR

RSSɂ‚

ACeBfBAIDɂ‚

[}KWo^

IT̃[}KẂA AׂĖłBЃ[}KWwǂB