github.com/bengesoff/terraform@v0.3.1-0.20141018223233-b25a53629922/website/source/intro/getting-started/change.html.md (about) 1 --- 2 layout: "intro" 3 page_title: "Change Infrastructure" 4 sidebar_current: "gettingstarted-change" 5 --- 6 7 # Change Infrastructure 8 9 In the previous page, you created your first infrastructure with 10 Terraform: a single EC2 instance. In this page, we're going to 11 modify that resource, and see how Terraform handles change. 12 13 Infrastructure is continuously evolving, and Terraform was built 14 to help manage and enact that change. As you change Terraform 15 configurations, Terraform builds an execution plan that only 16 modifies what is necessary to reach your desired state. 17 18 By using Terraform to change infrastructure, you can version 19 control not only your configurations but also your state so you 20 can see how the infrastructure evolved over time. 21 22 ## Configuration 23 24 Let's modify the `ami` of our instance. Edit the "aws\_instance.example" 25 resource in your configuration and change it to the following: 26 27 ``` 28 resource "aws_instance" "example" { 29 ami = "ami-aa7ab6c2" 30 instance_type = "t1.micro" 31 } 32 ``` 33 34 We've changed the AMI from being an Ubuntu 14.04 AMI to being 35 an Ubuntu 12.04 AMI. Terraform configurations are meant to be 36 changed like this. You can also completely remove resources 37 and Terraform will know to destroy the old one. 38 39 ## Execution Plan 40 41 Let's see what Terraform will do with the change we made. 42 43 ``` 44 $ terraform plan 45 ... 46 47 -/+ aws_instance.example 48 ami: "ami-408c7f28" => "ami-aa7ab6c2" (forces new resource) 49 availability_zone: "us-east-1c" => "<computed>" 50 key_name: "" => "<computed>" 51 private_dns: "domU-12-31-39-12-38-AB.compute-1.internal" => "<computed>" 52 private_ip: "10.200.59.89" => "<computed>" 53 public_dns: "ec2-54-81-21-192.compute-1.amazonaws.com" => "<computed>" 54 public_ip: "54.81.21.192" => "<computed>" 55 security_groups: "" => "<computed>" 56 subnet_id: "" => "<computed>" 57 ``` 58 59 The prefix "-/+" means that Terraform will destroy and recreate 60 the resource, versus purely updating it in-place. While some attributes 61 can do in-place updates (which are shown with a "~" prefix), AMI 62 changing on EC2 instance requires a new resource. Terraform handles 63 these details for you, and the execution plan makes it clear what 64 Terraform will do. 65 66 Additionally, the plan output shows that the AMI change is what 67 necessitated the creation of a new resource. Using this information, 68 you can tweak your changes to possibly avoid destroy/create updates 69 if you didn't want to do them at this time. 70 71 ## Apply 72 73 From the plan, we know what will happen. Let's apply and enact 74 the change. 75 76 ``` 77 $ terraform apply 78 aws_instance.example: Destroying... 79 aws_instance.example: Modifying... 80 ami: "ami-408c7f28" => "ami-aa7ab6c2" 81 82 Apply complete! Resources: 0 added, 1 changed, 1 destroyed. 83 84 ... 85 ``` 86 87 As the plan predicted, Terraform started by destroying our old 88 instance, then creating the new one. You can use `terraform show` 89 again to see the new properties associated with this instance. 90 91 ## Next 92 93 You've now seen how easy it is to modify infrastructure with 94 Terraform. Feel free to play around with this more before continuing. 95 In the next section we're going to [destroy our infrastructure](/intro/getting-started/destroy.html).