cc_staff
44
edits
Line 261: | Line 261: | ||
== Adding a network == | == Adding a network == | ||
The name of the private network differs from project to project and the naming convention can differ from cloud to cloud within Compute Canada, but typically they are on a 192.168.X.Y network, and can be found in the CLI using `network list` or on Horizon under ''Network''->''Networks''. If your project's private network is <code>my-tenant-net</code>, you will add a <code>network</code> resource sub-block to your VM definition similar to the following: | |||
<source lang="terraform">resource "openstack_compute_instance_v2" "myvm" { | <source lang="terraform">resource "openstack_compute_instance_v2" "myvm" { | ||
Line 271: | Line 271: | ||
network { | network { | ||
name = " | name = "my-tenant-net" | ||
} | } | ||
}</source> | }</source> | ||
Try again: | |||
<source lang="shell">$ terraform apply | <source lang="shell">$ terraform apply | ||
Line 332: | Line 333: | ||
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.</source> | Apply complete! Resources: 1 added, 0 changed, 0 destroyed.</source> | ||
You now have a VM created by Terraform. You should see your new VM on Horizon or in the output of <code>server list</code> in your OpenStack terminal window: | |||
<pre class="plaintext">(openstack) server list -c ID -c Name -c Status | <pre class="plaintext">(openstack) server list -c ID -c Name -c Status | ||
Line 343: | Line 345: | ||
| 9b42cbf3-3782-4472-bdd0-9028bbb73460 | lbr | ACTIVE | | | 9b42cbf3-3782-4472-bdd0-9028bbb73460 | lbr | ACTIVE | | ||
+--------------------------------------+--------+--------+</pre> | +--------------------------------------+--------+--------+</pre> | ||
In this example output, there are three other VMs created previously which survive untouched by Terraform. | |||
=== Recap === | |||
You now have a working VM which has successfully been initialized and is on the private network. You can’t log in and check it out however because you haven’t assigned a floating IP to this host, so it’s not directly accessible from outside the tenant. | |||
If you had another host in that tenant with a floating IP, you could use that host as a jump host (sometimes called a ''bastion host'') to the new VM, as they will both be on the same private network. This is a good strategy to use for nodes that do not need to be directly accessible from the internet, such as a database server, or just to preserve floating IPs, which are a limited resource. | |||
For now, add a floating IP to your new VM. | |||
First, though, note there is now a file in your workspace called <code>terraform.tfstate</code>. This was created by Terraform during the application of the new configuration and confirmation of its success. The state file contains details about the managed resources Terraform uses to determine how to arrive at a new state described by configuration updates. In general, you will not need to look at this file, but know that without it, Terraform cannot properly manage resources and if you delete it, you will need to restore it or recreate it, or manage those resources without Terraform. | |||
== Add a floating IP == | == Add a floating IP == |