Example:
# with no provider configuration at all, terraform will identify this by the
# it's resource type "aws" and assume that the user meant "hashicorp/aws"
resource "aws_instance" {
# resource config
}
Example:
# With no required_providers entries, terraform will identify the provider type as "aws"
# and assume the user meant "hashicorp/aws"
provider "aws" {
# provider config
}
resource "aws_instance" {
# resource config
}
Example:
terraform {
required_providers {
# the original syntax (version string) is still supported
# with no "source" attribute, terraform assumes the user meant "hashicorp/aws"
aws = "2.0"
}
}
# terraform maps the resource type name "aws" to the map key "aws" and uses "hashicorp/aws"
resource "aws_instance" "example" {
# resource config
}
When the localname (the map keys in required_providers) match the provider type, the user doesn't need to specify the provider for resources.
terraform {
required_providers {
google = {
# Why? For e.g., perhaps they forked the google provider to enforce security requirements
source = "tfe.example.com/myorg/google"
}
happycloud = {
source = "tfe.example.com/myorg/happycloud"
}
}
}
resource "google_thing" "example" {
# will use tfe.example.com/myorg/google
}
resource "happycloud_thing" "example" {
# will use tfe.example.com/myorg/happycloud
}
terraform {
required_providers {
# this "google" entry is entirely optional, since it's a default (HashiCorp) provider,
# but helps readability.
google = {
# This is short hand for "registry.terraform.io/hashicorp/google"
# If the host portion is omitted, terraform assumes "registry.terraform.io"
source = "hashicorp/google"
}
google-beta = {
source = "hashicorp/google-beta"
}
}
}
resource "google_thing" "example_1" {
# With no "provider" attribute, this resource will default to hashicorp/google.
}
resource "google_thing" "example_2" {
# When the localname (google-beta) does not match the resource type name (google),
# the "provider" attribute is always required.
provider = google-beta
}
Confusing but entirely valid:
terraform {
required_providers {
// This is actively confusing.
google = {
source = "hashicorp/google-beta"
}
}
}
resource "google_thing" "example" {
# this will use hashicorp/google-beta,
# since the localname google matches the resource type name
# This will confuse everyone. Please let's not.
}
This looks good! Just wanted to note that having the
provider
argument value in quotes is a 0.11-style thing we still support for backward compatibility, but the current canonical syntax would be like this: