Terraform: Difference between revisions

Jump to navigation Jump to search
371 bytes removed ,  5 years ago
Line 24: Line 24:
=== Credentials ===
=== Credentials ===


You will also need credentials for access to your OpenStack project available to Terraform. There are three ways to provide your credentials to Terraform, described in the [[#Defining_OpenStack_provider|next section]]. Horizon, the OpenStack web interface, offers a simple way to download credentials: once logged in, click on ''API Access'' in the navigation bar, and on that page is a drop-down menu entitled “Download OpenStack RC File”. From here you may download a <code>clouds.yaml</code> file or an RC file which can be sourced from your shell session.
There are two ways to provide your OpenStack credentials in a command-line environment: via environment variables or in a configuration file.  We'll need to use one of these methods with Terraform, described in the [[#Defining_OpenStack_provider|next section]]. Regardless of your preferred method, the OpenStack web interface offers a simple way to download credentials: once logged in, click on ''API Access'' in the navigation bar, and on that page is a drop-down menu entitled “Download OpenStack RC File”. From here you may download a <code>clouds.yaml</code> file or an RC file which can be sourced from your shell session.


The third method is to take the credentials and represent them directly in the Terraform configuration.
The RC file is a series of shell commands which export environment variables to your current shell session.  It's not a standalone script and must be sourced in the context of the current session, like so:
 
The RC file is a series of shell commands sourced from your existing session. Because it exports variables which must be available in your ''current'' shell session, this file is not run directly, as a script (in which case all exported variables would disappear when the script exited and its shell context destroyed). So, once downloaded, the RC file can then be sourced like so:


<source lang="shell">$ . openrc.sh</source>
<source lang="shell">$ . openrc.sh</source>
It will then prompt your for your OpenStack password, which along with necessary information about you, your tenant and the cloud you’re connecting to will be stored in a bunch of environment variables prefixed by <code>OS_</code>, such as <code>$OS_AUTH_URL</code> and so on. Have a look at the RC file to see what it’s doing. In Bash, you can type <code>echo $OS_&lt;tab&gt;</code> and auto-completion will list variables with that prefix.
It will then prompt you for your OpenStack password, which along with necessary information about you, your tenant and the cloud you’re connecting to will be stored in environment variables prefixed by <code>OS_</code>, such as <code>$OS_AUTH_URL</code> and so on.


My preferred method is to create a configuration in <code>$HOME/.config/openstack/clouds.yaml</code>. If you don’t have such a file already, you can download one as described above and move it into place. I also recommend changing the name given to the cloud in the downloaded file to something meaningful, especially if you use more than one OpenStack cloud. Then, to use the CLI tools described below, you simply create an environment variable <code>$OS_CLOUD</code> with the name of the cloud you want to use.
The other method is to create a configuration in <code>$HOME/.config/openstack/clouds.yaml</code>. If you don’t have such a file already, you can download `clouds.yaml` as described above and move it into place. We recommend changing the name given to the cloud in the downloaded file to something meaningful, especially if you use more than one OpenStack cloud. Then, to use the CLI tools described below, simply create an environment variable <code>$OS_CLOUD</code> with the name of the cloud you want to use.


<source lang="shell">$ export OS_CLOUD=arbutus</source>
<source lang="shell">$ export OS_CLOUD=arbutus</source>
Later on I’ll explain how to use those with Terraform.
 
Whichever you have chosen, you will use this soon to configure Terraform.


=== OpenStack session ===
=== OpenStack session ===
cc_staff
44

edits

Navigation menu