cc_staff
44
edits
(→Recap) |
|||
Line 361: | Line 361: | ||
Floating IPs are not created directly on a VM in OpenStack: they are allocated to the project from a pool and associated with the VM’s private network interface. | Floating IPs are not created directly on a VM in OpenStack: they are allocated to the project from a pool and associated with the VM’s private network interface. | ||
Assuming | Assuming you do not already have a floating IP allocated for this use, declare a desired floating IP resource like the following example. The only thing you need is to know the pool from which to allocate the floating IP; in Compute Canada clouds this is the external network (<code>ext_net</code> in this example). | ||
<source lang="terraform">resource "openstack_networking_floatingip_v2" "myvm_fip" { | <source lang="terraform">resource "openstack_networking_floatingip_v2" "myvm_fip" { | ||
pool = " | pool = "ext_net" | ||
}</source> | }</source> | ||
You may either apply this change immediately or just use <code>terraform plan</code> to show what would happen. | |||
<source lang="shell">$ terraform apply | <source lang="shell">$ terraform apply | ||
Line 403: | Line 403: | ||
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.</source> | Apply complete! Resources: 1 added, 0 changed, 0 destroyed.</source> | ||
This floating IP is now ''allocated'' but not yet associated with your VM. Add the following definition: | |||
<source lang="terraform">resource "openstack_compute_floatingip_associate_v2" "myvm_fip" { | <source lang="terraform">resource "openstack_compute_floatingip_associate_v2" "myvm_fip" { | ||
Line 411: | Line 409: | ||
instance_id = openstack_compute_instance_v2.myvm.id | instance_id = openstack_compute_instance_v2.myvm.id | ||
}</source> | }</source> | ||
This new resource defines as its attributes references to other resources and their attributes. | This new resource defines as its attributes references to other resources and their attributes. | ||
<blockquote> | <blockquote>'''Note''': Current documentation of the OpenStack provider documentation uses syntax which differs from what is presented here as it has not yet been updated for changes to Terraform v.12. | ||
</blockquote> | </blockquote> | ||
References like this are typically <code><resource type>.<resource name>.<attribute></code>. Others you may soon see include <code>var.<variable name></code>. | References like this are typically <code><resource type>.<resource name>.<attribute></code>. Others you may soon see include <code>var.<variable name></code>. At any rate, this resource forms an association between the created earlier, and the floating IP allocated in the next step. | ||
<source lang="shell">$ terraform apply | <source lang="shell">$ terraform apply | ||
Line 450: | Line 449: | ||
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.</source> | Apply complete! Resources: 1 added, 0 changed, 0 destroyed.</source> | ||
Note that it has an associated floating IP, you could probably SSH into the new VM right now. | |||
Note that it has an associated floating IP | |||
<source lang="shell">$ ssh centos@X.Y.Z.W hostname | <source lang="shell">$ ssh centos@X.Y.Z.W hostname | ||
Line 468: | Line 458: | ||
Warning: Permanently added 'X.Y.Z.W' (ECDSA) to the list of known hosts. | Warning: Permanently added 'X.Y.Z.W' (ECDSA) to the list of known hosts. | ||
myvm.novalocal</source> | myvm.novalocal</source> | ||
If not, it may be necessary to add your workstation's IP address to the project's default security group. | |||
== Add a volume == | == Add a volume == |