Difference between revisions of "Terraform multiple providers"

From wikieduonline
Jump to navigation Jump to search
(Redirected page to Multiple providers)
Tag: New redirect
(Removed redirect to Multiple providers)
Tag: Removed redirect
Line 1: Line 1:
#redirect [[Multiple providers]]
+
You can optionally define multiple configurations for the same [[provider]], and select which one to use on a per-resource or per-module basis. <ref>https://www.terraform.io/language/providers/configuration</ref>
 +
 
 +
=== Example ===
 +
 
 +
<pre>
 +
# The default provider configuration; resources that begin with `aws_` will use
 +
# it as the default, and it can be referenced as `aws`.
 +
provider "aws" {
 +
  region = "us-east-1"
 +
}
 +
 
 +
# Additional provider configuration for west coast region; resources can
 +
# reference this as `aws.west`.
 +
provider "aws" {
 +
  alias  = "west"
 +
  region = "us-west-2"
 +
}
 +
</pre>
 +
 
 +
<pre>
 +
terraform {
 +
  required_providers {
 +
    mycloud = {
 +
      source  = "mycorp/mycloud"
 +
      version = "~> 1.0"
 +
      configuration_aliases = [ mycloud.alternate ]
 +
    }
 +
  }
 +
}
 +
</pre>
 +
 
 +
<pre>
 +
resource "aws_instance" "foo" {
 +
  provider = aws.west
 +
 +
  # ...
 +
}</pre>
 +
 
 +
== Related ==
 +
 
 +
* [[Terraform providers]]
 +
* <code>[[alias]]</code>
 +
* [[Terraform Associate]]
 +
 
 +
== See also ==
 +
* {{terraform providers}}
 +
* {{Certifications}}
 +
 
 +
[[Category:Terraform]]

Revision as of 05:31, 15 September 2022

You can optionally define multiple configurations for the same provider, and select which one to use on a per-resource or per-module basis. [1]

Example

# The default provider configuration; resources that begin with `aws_` will use
# it as the default, and it can be referenced as `aws`.
provider "aws" {
  region = "us-east-1"
}

# Additional provider configuration for west coast region; resources can
# reference this as `aws.west`.
provider "aws" {
  alias  = "west"
  region = "us-west-2"
}
terraform {
  required_providers {
    mycloud = {
      source  = "mycorp/mycloud"
      version = "~> 1.0"
      configuration_aliases = [ mycloud.alternate ]
    }
  }
}
 resource "aws_instance" "foo" {
   provider = aws.west
 
   # ...
 }

Related

See also

  • https://www.terraform.io/language/providers/configuration
  • Advertising: