Skip to content

Terraform Providers

← Back to all decks

28 cards — 🟢 5 easy | 🟡 9 medium | 🔴 4 hard

🟢 Easy (5)

1. What is a Terraform provider block and why do you need it?

Show answer The provider block in Terraform config specifies which provider (and version settings) to use, and usually contains authentication or region settings. For example, provider "aws" { region = "us-west-2" } configures the AWS provider for a region. It's needed so Terraform knows how to connect to the respective service's API.

2. Explain what is a "provider"

Show answer [terraform.io](https://www.terraform.io/docs/language/providers/index.html): "Terraform relies on plugins called "providers" to interact with cloud providers, SaaS providers, and other APIs...Each provider adds a set of resource types and/or data sources that Terraform can manage. Every resource type is implemented by a provider; without providers, Terraform can't manage any kind of infrastructure."

3. What are the names of the providers in this case?

Show answer The provider names are `azurerm` (for Azure Resource Manager) and `aws` (for Amazon Web Services). Providers are declared in the `required_providers` block inside `terraform {}`. Each provider has its own version constraints and configuration. Pin versions to avoid breaking changes: `version = "~> 5.0"` allows minor updates but not major.

4. What is a Terraform provider?

Show answer In Terraform, a provider is a plugin that enables communication between Terraform and a specific infrastructure platform or service. Providers define the resources and their behavior for a particular platform, such as AWS, Azure, or vSphere. Each provider has its set of resources that can be managed using Terraform configurations. Users can configure multiple providers in a single Terraform configuration to manage resources across different platforms.

5. True or False? You can install providers only from hashicorp

Show answer False. You can specify any provider from any URL, not only those from hashicorp.

Remember: "Provider configuration is inherited by all resources of that type." Override per-resource with the provider meta-argument.

🟡 Medium (9)

1. Explain the significance of the Terraform provider "alias."

Show answer The Terraform provider alias allows you to use multiple configurations for the same provider within a single Terraform configuration. This is useful in scenarios where you want to manage resources in the same provider but with different configurations. For example, you might use provider aliases to create multiple AWS S3 buckets with different configurations in the same configuration file. Provider aliases are declared using the provider block with an alias attribute.

2. Where can you find publicly available providers?

Show answer In the [Terraform Registry](https://registry.terraform.io/browse/providers)

Remember: "Pin provider versions to avoid surprises." version = "~> 5.0" means >= 5.0 and < 6.0.

3. Where Terraform installs providers from by default?

Show answer By default Terraform providers are installed from Terraform Registry

Remember: "Provider aliases = multiple configs for same provider." Use for multi-region or multi-account.

4. What can you do to NOT store provider credentials in Terraform configuration files in plain text?

Show answer 1. Use environment variables
2. Use password CLIs (like 1Password which is generic but there also specific provider options like aws-vault)

Remember: "Providers are Go binaries using gRPC." They translate HCL to API calls. The registry hosts thousands of providers.

5. Where providers are downloaded to? (when for example you run terraform init)

Show answer Providers are downloaded to the `.terraform/providers/` directory when you run `terraform init`. This directory is gitignored because providers are large binaries (often 100+ MB). `terraform init` recreates it from the lock file (`terraform.lock.hcl`). Commit `terraform.lock.hcl` to ensure all team members use identical provider versions and checksums.

6. Discuss the role of Terraform providers in supporting different cloud services.

Show answer Terraform providers are plugins that enable Terraform to interact with various infrastructure platforms and services. Providers abstract the underlying API interactions, allowing users to declare resources in a consistent manner regardless of the underlying cloud or service. For example, the AWS provider supports Amazon Web Services, while the Azure provider supports Microsoft Azure. By supporting multiple providers, Terraform facilitates multi-cloud and hybrid cloud infrastructure management, giving users flexibility and choice in their cloud environments.

7. What are "Terraform Providers" and how do they integrate with the Terraform core?

Show answer Terraform Providers are plugins that extend the functionality of Terraform by enabling it to interact with different infrastructure platforms. They integrate with the Terraform core by:
* Resource Handling: Providers define and manage resources specific to a target platform.
* Data Sources: Providers offer data sources for importing external information into Terraform.
* Authentication: They handle authentication and API communication with the platform.
* State Management: Providers interact with the Terraform state to track resource state.

8. How to install a provider?

Show answer You write a provider block like the following one and run `terraform init`

```\nprovider "aws" {\n region = "us-west-1"\n}\n```

Remember: "Required providers go in the terraform {} block." This is where you pin source and version.

9. Write a configuration of a Terraform provider (any type you would like)

Show answer AWS is one of the most popular providers in Terraform. Here is an example of how to configure it to use one specific region and specifying a specific version of the provider

```\nterraform {\n required_providers {\n aws = {\n source = "hashicorp/aws"\n version = "~> 3.0"\n }\n }\n}\n\n# Configure the AWS Provider\nprovider "aws" {\n region = "us-west-2"\n}\n```

Remember: "Community providers live outside the hashicorp namespace." Source format: namespace/name.

🔴 Hard (4)

1. What are "Terraform Providers" and how do they extend Terraform's capabilities?

Show answer Terraform Providers are plugins that extend Terraform's capabilities by enabling it to interact with different infrastructure platforms and services. Providers abstract the underlying API interactions, providing a consistent interface for managing resources. Each provider focuses on a specific platform (e.g., AWS, Azure, VMware). Providers define resource types, data sources, and provider-specific functionalities. By using different providers, Terraform supports multi-cloud and hybrid cloud scenarios, giving users flexibility in choosing and managing their infrastructure.

2. How can you use Terraform to manage resources across multiple cloud providers (multi-cloud)?

Show answer Terraform supports multi-cloud deployments by using provider-specific configurations. Key steps include:
* Provider Blocks: Define provider blocks for each cloud provider in the configuration.
* Resource Configuration: Create resources using provider-specific configurations.
* Variables and Conditional Logic: Use variables and conditional logic to customize configurations based on the target cloud.
* Terraform Workspaces: Utilize workspaces for environment-specific configurations.

3. What's the issue with the following provider configuration?

Show answer It's not secure! you should never store credentials in plain text this way.

Remember: "Provider authentication: use environment variables, not hardcoded credentials." Never put credentials in .tf files.

4. How to manage multiple regions in AWS provider configuration?

Show answer ```\nprovider "aws" {\n region = "us-west-1"\n alias = "west_region"\n}\n\nprovider "aws" {\n region = "us-east-1"\n alias = "east_region"\n}\n\ndata "aws_region" "west_region" {\n provider = aws.west_region\n}\n\ndata "aws_region" "east_region" {\n provider = aws.east_region\n}\n```

To use it:

```\nresource "aws_instance" "west_region_instance" {\n provider = aws.west_region\n instance_type = "t2.micro"\n ...\n}\n```