Table of Contents
- Overview
- Inspecting an Existing Configuration
- Initializing Providers
- Creating a Multi-Provider Configuration
- Exploring Additional Provider Resources
- Practice Task:
local_fileResource - Adding a New Provider-Based Resource
- 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.
Read the OpenTofu Installation Guide for more details.
2. Inspecting an Existing Configuration
Navigate to the example directory:.terraform folder—initialized provider count: 0.
Main configuration (main.tf):
3. Initializing Providers
Initialize the configuration to download provider plugins:| Provider | Plugin Count |
|---|---|
| local | 1 |
| random | 1 |
4. Creating a New Multi-Provider Configuration
Create and navigate to a new project:pet-name.tf:
yes. Expected output:
5. Exploring Additional Provider Resources
Switch to another example directory:cloud-provider.tf (AWS EC2 instance):
- Instance Type: t2.large
kube.tf (Kubernetes namespace):
- Namespace Resource Name: dev
6. Practice Task: Creating a local_file Resource
Create code.tf:
7. Adding a New Provider-Based Resource
Updatecode.tf by appending a random_string resource:
Run
tofu init -upgrade to update the provider lock file and install the latest plugin version.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