github.com/bengesoff/terraform@v0.3.1-0.20141018223233-b25a53629922/website/source/intro/getting-started/outputs.html.md (about) 1 --- 2 layout: "intro" 3 page_title: "Output Variables" 4 sidebar_current: "gettingstarted-outputs" 5 --- 6 7 # Output Variables 8 9 In the previous section, we introduced input variables as a way 10 to parameterize Terraform configurations. In this page, we 11 introduce output variables as a way to organize data to be 12 easily queried and shown back to the Terraform user. 13 14 When building potentially complex infrastructure, Terraform 15 stores hundreds or thousands of attribute values for all your 16 resources. But as a user of Terraform, you may only be interested 17 in a few values of importance, such as a load balancer IP, 18 VPN address, etc. 19 20 Outputs are a way to tell Terraform what data is important. 21 This data is outputted when `apply` is called, and can be 22 queried using the `terraform output` command. 23 24 ## Defining Outputs 25 26 Let's define an output to show us the public IP address of the 27 elastic IP address that we create. Add this to any of your 28 `*.tf` files: 29 30 ``` 31 output "ip" { 32 value = "${aws_eip.ip.public_ip}" 33 } 34 ``` 35 36 This defines an output variables named "ip". The `value` field 37 specifies what the value will be, and almost always contains 38 one or more interpolations, since the output data is typically 39 dynamic. In this case, we're outputting the 40 `public_ip` attribute of the elastic IP address. 41 42 Multiple `output` blocks can be defined to specify multiple 43 output variables. 44 45 ## Viewing Outputs 46 47 Run `terraform apply` to populate the output. This only needs 48 to be done once after the output is defined. The apply output 49 should change slightly. At the end you should see this: 50 51 ``` 52 $ terraform apply 53 ... 54 55 Apply complete! Resources: 0 added, 0 changed, 0 destroyed. 56 57 Outputs: 58 59 ip = 50.17.232.209 60 ``` 61 62 `apply` highlights the outputs. You can also query the outputs 63 after apply-time using `terraform output`: 64 65 ``` 66 $ terraform output ip 67 50.17.232.209 68 ``` 69 70 This command is useful for scripts to extract outputs. 71 72 ## Next 73 74 You now know how to parameterize configurations with input 75 variables, extract important data using output variables, 76 and bootstrap resources using provisioners. 77 78 Next, we're going to take a look at 79 [how to use modules](/intro/getting-started/modules.html), a useful 80 abstraction to organization and reuse Terraform configurations.