Terraform state and Outputs

Figure 1083. Output data details #1/2 Slide presentation

See terraform output documentation:

# outputs.tf
output "helloIpAddress" {
  value       = hcloud_server.mySrv.ipv4_address
  description = "The server's IPv4 address"
}

output "helloLocation" {
  value       = hcloud_server.mySrv.location
  description = "The server's datacenter location"
}
$ terraform output
helloLocation  = "nbg1"
helloIpAddress = "159.69.152.37"
$ terraform output helloIpAddress
"159.69.152.37"

Figure 1084. Output data details #2/2 Slide presentation
# outputs.tf

output "helloIpAddress" {
  value       = hcloud_server.mySrv.ipv4_address
  description = "The server's IPv4 address"
}

output "helloLocation" {
  value       = hcloud_server.mySrv.location
  description = "The server's datacenter location"
}

terraform output -json

{
  "helloLocation": {
    "sensitive": false,
    "type": "string",
    "value": "nbg1"
  },
  "helloIpAddress": {
    "sensitive": false,
    "type": "string",
    "value": "159.69.152.37"
  }
}

exercise No. 14

Adding ssh public keys and firewall

Q:

Start from Your first server by Terraform. and:

Expected results:

  • On executing terraform apply you should see something like:

    terraform apply
    ...
    hcloud_server.mySrv: Still creating... [10s elapsed]
    hcloud_server.mySrv: Creation complete after 14s [id=46961197]
    
    Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
    
    Outputs:
    
    hello_location = "hel1"
    hello_ip_addr = "95.217.154.104"
  • You should be able to open a ssh connection to your server without requiring a password:

    ssh root@<your_server_ip>
  • Due to your firewall configuration your server should not respond to ICMP echo requests:

    ping <your_server_ip>

Add another rule to your hcloud_firewall enabling ICMP as well. Hit terraform apply. This should modify your existing firewall allowing for pinging your server.