38,760
edits
No edit summary |
(Updating to match new version of source page) |
||
Line 13: | Line 13: | ||
=== Accéder à OpenStack === | === Accéder à OpenStack === | ||
<div class="mw-translate-fuzzy"> | |||
Pour accéder à l'infonuage, voir [[Cloud/fr#Obtenir_un_projet_dans_l'environnement_infonuagique|Obtenir un projet d'infonuagique]] sur le wiki de l'Alliance. Si vous n'avez jamais utilisé OpenStack auparavant, vous devriez d'abord vous familiariser avec ce système en créant une VM, en attachant un volume, en associant une IP flottante et en vous assurant que vous pouvez vous connecter à la VM par la suite. Ce tutoriel suppose également que vous avez déjà créé une paire de clés SSH et que la clé publique a été importée dans OpenStack. | Pour accéder à l'infonuage, voir [[Cloud/fr#Obtenir_un_projet_dans_l'environnement_infonuagique|Obtenir un projet d'infonuagique]] sur le wiki de l'Alliance. Si vous n'avez jamais utilisé OpenStack auparavant, vous devriez d'abord vous familiariser avec ce système en créant une VM, en attachant un volume, en associant une IP flottante et en vous assurant que vous pouvez vous connecter à la VM par la suite. Ce tutoriel suppose également que vous avez déjà créé une paire de clés SSH et que la clé publique a été importée dans OpenStack. | ||
</div> | |||
Si vous ne savez pas encore comment faire cela, le [[Cloud_Quick_Start/fr|Guide de démarrage en infonuagique]] est une bonne introduction. La création de ces ressources à l'aide de l'interface web d'OpenStack vous permettra de comprendre à la fois ce que fait Terraform et son utilité. | Si vous ne savez pas encore comment faire cela, le [[Cloud_Quick_Start/fr|Guide de démarrage en infonuagique]] est une bonne introduction. La création de ces ressources à l'aide de l'interface web d'OpenStack vous permettra de comprendre à la fois ce que fait Terraform et son utilité. | ||
Line 48: | Line 50: | ||
== Defining OpenStack provider == | == Defining OpenStack provider == | ||
First, describe the ''provider'': this is where you tell Terraform to use OpenStack, and how. On initialization the most recent version of the OpenStack provider plugin will be installed in the working directory and on subsequent Terraform operations the included credentials will be used to connect to the specified cloud. | First, describe the ''provider'': this is where you tell Terraform to use OpenStack, and how. On initialization the most recent version of the OpenStack provider plugin will be installed in the working directory and on subsequent Terraform operations, the included credentials will be used to connect to the specified cloud. | ||
Your connection and credential information for OpenStack can be provided to Terraform in the specification, in the environment, or partially in the specification with the rest in the environment. | Your connection and credential information for OpenStack can be provided to Terraform in the specification, in the environment, or partially in the specification with the rest in the environment. | ||
Line 63: | Line 65: | ||
}</source> | }</source> | ||
For some OpenStack instances the above would specify the complete set of information necessary to connect to the instance and manage resources in the given project (“tenant”). However, Terraform supports | For some OpenStack instances, the above would specify the complete set of information necessary to connect to the instance and manage resources in the given project (“tenant”). However, Terraform supports <i>partial credentials</i> in which you could leave some values out of the Terraform configuration and supply them a different way. This would allow us, for example, to leave the password out of the configuration file, in which case it would need to be specified in the environment with <code>$OS_PASSWORD</code>. | ||
Alternatively, if you prefer to use <code>clouds.yaml</code>, specify <code>cloud</code> in the provider stanza: | Alternatively, if you prefer to use <code>clouds.yaml</code>, specify <code>cloud</code> in the provider stanza: | ||
Line 148: | Line 150: | ||
=== Trying it out === | === Trying it out === | ||
The command <code>terraform plan</code> compiles the Terraform definition and attempts to determine how to reconcile the resulting | The command <code>terraform plan</code> compiles the Terraform definition and attempts to determine how to reconcile the resulting state with the actual state on the cloud, and produces a plan of what it would if the changes were applied. | ||
<source lang="shell">$ terraform plan | <source lang="shell">$ terraform plan | ||
Line 215: | Line 217: | ||
<source lang="shell">Plan: 1 to add, 0 to change, 0 to destroy.</source> | <source lang="shell">Plan: 1 to add, 0 to change, 0 to destroy.</source> | ||
In this case we know we’re adding a resource so this looks right. If the other values were non-zero then we’d better have another look at our configuration, state and what’s actually defined in OpenStack and make whatever corrections are necessary. | In this case, we know we’re adding a resource so this looks right. If the other values were non-zero then we’d better have another look at our configuration, state and what’s actually defined in OpenStack and make whatever corrections are necessary. | ||
=== Side note: What happens to existing OpenStack resources? === | === Side note: What happens to existing OpenStack resources? === | ||
Line 354: | Line 356: | ||
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. | 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. | ||
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. | 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. | 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. | ||
Line 364: | Line 366: | ||
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 you do not already have a floating IP allocated for this use, declare a | Assuming you do not already have a floating IP allocated for this use, declare a floating IP resource like the following example. The only thing you need is to know the pool from which to allocate the floating IP; on our 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" { | ||
Line 608: | Line 610: | ||
=== Finding image and flavour UUIDs in Horizon === | === Finding image and flavour UUIDs in Horizon === | ||
For those more comfortable using the web interface to OpenStack, here is a quick cheat sheet on finding flavour and image UUIDs in Horizon. You’ll need to log into the web interface of the | For those more comfortable using the web interface to OpenStack, here is a quick cheat sheet on finding flavour and image UUIDs in Horizon. You’ll need to log into the web interface of the cloud for this information. | ||
To find an image’s UUID, find the ''Images'' menu item under ''Compute'' (1). | To find an image’s UUID, find the ''Images'' menu item under ''Compute'' (1). | ||
[[File:images-1.png|thumb|Find and select | [[File:images-1.png|thumb|Find and select an image]] | ||
You’ll get a list of images available to your project. Click on the one you’d like to use. (2) | You’ll get a list of images available to your project. Click on the one you’d like to use. (2) |