Terraform/fr: Difference between revisions

Jump to navigation Jump to search
Updating to match new version of source page
No edit summary
(Updating to match new version of source page)
Line 1: Line 1:
<languages />
<languages />
<div class="mw-translate-fuzzy">
[https://www.terraform.io/ Terraform] est un outil permettant de définir et d'approvisionner l'infrastructure de centres de données, y compris des machines virtuelles.  Terraform est de plus en plus utilisé au sein de Compute Canada.  Son modèle d'infrastructure-en-code permet de maintenir les ressources OpenStack comme une collection de définitions qui peuvent être facilement mises à jour à l'aide de nos éditeurs de texte favoris, partagées entre les membres d'un groupe et stockées dans un système de contrôle de version.
[https://www.terraform.io/ Terraform] est un outil permettant de définir et d'approvisionner l'infrastructure de centres de données, y compris des machines virtuelles.  Terraform est de plus en plus utilisé au sein de Compute Canada.  Son modèle d'infrastructure-en-code permet de maintenir les ressources OpenStack comme une collection de définitions qui peuvent être facilement mises à jour à l'aide de nos éditeurs de texte favoris, partagées entre les membres d'un groupe et stockées dans un système de contrôle de version.
</div>


Cette page est écrite comme un tutoriel dans lequel nous présentons Terraform et démontrons son usage sur nos infonuages OpenStack.  Nous configurons notre espace de travail local pour Terraform et créons une machine virtuelle (VM) avec une IP flottante et un volume attaché.
Cette page est écrite comme un tutoriel dans lequel nous présentons Terraform et démontrons son usage sur nos infonuages OpenStack.  Nous configurons notre espace de travail local pour Terraform et créons une machine virtuelle (VM) avec une IP flottante et un volume attaché.
Line 13: Line 15:
=== 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 Compute Canada. 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é 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 Compute Canada. 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é dans OpenStack.
</div>


Si vous ne savez pas encore comment faire cela, le [[Cloud_Quick_Start/fr|Guide de démarrage en infonuagique]] vous y introduira facilement. 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]] vous y introduira facilement. 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 144: Line 148:
If using Horizon (the OpenStack web interface), this is semi-possible–see the [[#Finding_image_and_flavour_UUIDs_in_Horizon|guide in the appendix]].
If using Horizon (the OpenStack web interface), this is semi-possible–see the [[#Finding_image_and_flavour_UUIDs_in_Horizon|guide in the appendix]].


Note that no volumes are supplied. A compute instance in Compute Canada will already have an associated volume but a persistent instance will probably fail unless there is sufficient empty space in the image itself. It is [[Working_with_volumes#Booting_from_a_volume|recommended that a boot volume be created]] for VMs using persistent flavours.
Note that no volumes are supplied. A compute instance on our clouds will already have an associated volume but a persistent instance will probably fail unless there is sufficient empty space in the image itself. It is [[Working_with_volumes#Booting_from_a_volume|recommended that a boot volume be created]] for VMs using persistent flavours.


=== Trying it out ===
=== Trying it out ===
Line 259: Line 263:
   4: resource "openstack_compute_instance_v2" "myvm" {</source>
   4: resource "openstack_compute_instance_v2" "myvm" {</source>


This fails in this example.  OpenStack projects in Compute Canada have at least two networks defined: one private and one public.  Terraform needs to know which one to use.
This fails in this example.  OpenStack projects have at least two networks defined: one private and one public.  Terraform needs to know which one to use.


== Ajouter un réseau ==
== Ajouter un réseau ==


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:
The name of the private network differs from project to project and the naming convention can differ from cloud to cloud, 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 <i>Network -> Networks</i>.  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 364: Line 368:
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 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).
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; 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 417: Line 421:
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>'''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><b>Note</b>: 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>&lt;resource type&gt;.&lt;resource name&gt;.&lt;attribute&gt;</code>. Others you may soon see include <code>var.&lt;variable name&gt;</code>. At any rate, this resource forms an association between the created earlier, and the floating IP allocated in the next step.
References like this are typically <code>&lt;resource type&gt;.&lt;resource name&gt;.&lt;attribute&gt;</code>. Others you may soon see include <code>var.&lt;variable name&gt;</code>. At any rate, this resource forms an association between the created earlier, and the floating IP allocated in the next step.
Line 468: Line 472:
== Ajouter un volume ==
== Ajouter un volume ==


Next, add a root volume to the VM. Since this will replace its boot disk, ''this is a destructive operation''. This is something you need to watch out for in Terraform, and one of the chief reasons for reading your plans carefully before applying.  It’s unlikely you’re going to accidentally cause critical issues in creating new resources, but it can be deceptively easy to accidentally create configuration changes that require ''rebuilding'' existing VMs.
Next, add a root volume to the VM. Since this will replace its boot disk, <i>this is a destructive operation</i>. This is something you need to watch out for in Terraform, and one of the chief reasons for reading your plans carefully before applying.  It’s unlikely you’re going to accidentally cause critical issues in creating new resources, but it can be deceptively easy to accidentally create configuration changes that require ''rebuilding'' existing VMs.


Since this is a root volume, create it as part of the compute instance, as another subblock along with the network subblock:
Since this is a root volume, create it as part of the compute instance, as another subblock along with the network subblock:
Line 599: Line 603:
* [https://www.terraform.io/docs/providers/openstack/index.html OpenStack provider]
* [https://www.terraform.io/docs/providers/openstack/index.html OpenStack provider]
* [https://www.terraform.io/docs/providers/openstack/r/compute_instance_v2.html OpenStack compute instance resource]: many examples of different use cases for creating VMs under OpenStack with Terraform.
* [https://www.terraform.io/docs/providers/openstack/r/compute_instance_v2.html OpenStack compute instance resource]: many examples of different use cases for creating VMs under OpenStack with Terraform.
* [[Cloud|Compute Canada cloud documentation]] and the [[Cloud Quick Start]] Guide
* [[Cloud|Our cloud documentation]] and the [[Cloud Quick Start]] guide


=== Exemples ===
=== Exemples ===
Line 641: Line 645:
== Notes ==
== Notes ==


This material is adapted from a posting which appeared on [https://acme.c3.ca the ACME group blog] (Compute Canada staff only; login required).  The original is [https://acme.c3.ca/blog/getting-started-with-terraform/ here] and is the first article in a series on Terraform.
This material is adapted from a posting which appeared on [https://acme.c3.ca the ACME group blog] (Alliance staff only; login required).  The original is [https://acme.c3.ca/blog/getting-started-with-terraform/ here] and is the first article in a series on Terraform.
[[Category:Cloud]]
[[Category:Cloud]]
38,760

edits

Navigation menu