Skip to main content
In this lesson, we explore configuring and managing multiple providers within a single OpenTofu project directory. By the end, you’ll be able to initialize, apply, and troubleshoot provider plugins across various configurations.

Table of Contents

  1. Overview
  2. Inspecting an Existing Configuration
  3. Initializing Providers
  4. Creating a Multi-Provider Configuration
  5. Exploring Additional Provider Resources
  6. Practice Task: local_file Resource
  7. Adding a New Provider-Based Resource
  8. Summary & References

1. Overview

OpenTofu allows you to use multiple providers in the same configuration directory. This means you can manage local, random, AWS, Kubernetes, and other resources from a single project.
Make sure you have OpenTofu installed and your CLI configured before starting.
Read the OpenTofu Installation Guide for more details.

2. Inspecting an Existing Configuration

Navigate to the example directory:
You should see two resource files and no .terraform folder—initialized provider count: 0. Main configuration (main.tf):

3. Initializing Providers

Initialize the configuration to download provider plugins:
Inspect the plugins directory:
Total providers initialized: 2.

4. Creating a New Multi-Provider Configuration

Create and navigate to a new project:
Create pet-name.tf:
Initialize and apply:
Confirm with yes. Expected output:

5. Exploring Additional Provider Resources

Switch to another example directory:
In cloud-provider.tf (AWS EC2 instance):
  • Instance Type: t2.large
In kube.tf (Kubernetes namespace):
  • Namespace Resource Name: dev

6. Practice Task: Creating a local_file Resource

Create code.tf:
Run validation:
Everything should pass successfully.

7. Adding a New Provider-Based Resource

Update code.tf by appending a random_string resource:
Attempt to apply:
You may encounter an inconsistent dependency lock file error.
Run tofu init -upgrade to update the provider lock file and install the latest plugin version.
Upgrade and re-apply:
Confirm with yes. Expected output:

8. Summary & References

You’ve successfully:
  • Initialized and managed multiple providers
  • Created local, random, AWS, and Kubernetes resources
  • Upgraded provider lock files
Further reading:

Watch Video

Practice Lab