Terraform: Difference between revisions

193 bytes removed ,  5 years ago
Line 49: Line 49:
== Defining OpenStack provider ==
== Defining OpenStack provider ==


First, we describe the OpenStack Provider we want to use. This is where we tell Terraform we want to use OpenStack, and how. On <code>terraform init</code> the most recent version of the plugin will be installed in the working directory and on <code>terraform apply</code> 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.


There are three ways to define the credentials Terraform will need to connect to a cloud instance and manage resources in the appropriate project (“tenant” in the older OpenStack parlance). The first is to explicity define them directly in Terraform.
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.
 
The following is an example of a provider specification with connection and credential information:


<source lang="terraform">provider "openstack" {
<source lang="terraform">provider "openstack" {
Line 61: Line 63:
   user_domain_name = "CentralID"
   user_domain_name = "CentralID"
}</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 ''partial credentials'' 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.


There are two ways to specify OpenStack credentials outside of Terraform: Using environment variables or a definition in <code>clouds.yaml</code>. These can be combined so that, typically, passwords are not stored in <code>clouds.yaml</code> either.
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 ''partial credentials'' 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>.


To specify OpenStack credentials using <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:


<source lang="terraform">provider "openstack" {
<source lang="terraform">provider "openstack" {
   cloud = "my_cloud"
   cloud = "my_cloud"
}</source>
}</source>
…or it could be defined in the environment as <code>$OS_CLOUD</code>, and the provider definition could be empty:
 
It's acceptable to leave the provider definition completely empty:


<source lang="terraform">provider "openstack" {
<source lang="terraform">provider "openstack" {
}</source>
}</source>
Similarly, environment variables can be used alone to specify the project ID, authentication URL, etc. or can be combined with a partial definition in the provider stanza.
 
In this case, either <code>$OS_CLOUD</code> or the variables set by the appropriate RC file would need to be in the executing environment for Terraform to proceed.


The [https://www.terraform.io/docs/providers/openstack/index.html configuration reference of the OpenStack Provider] describes the available options in detail.
The [https://www.terraform.io/docs/providers/openstack/index.html configuration reference of the OpenStack Provider] describes the available options in detail.
cc_staff
44

edits