60 SECTIONS · 1529 TOPICS
Terraform Roadmap
Installing and Configuring Terraform CLI
- 1. Installing Terraform
- Example: Installing Terraform via Official Binary (Linux)
- 2. Verifying Installation
- Example: Check Terraform version
- 3. Enabling Tab Completion
- Example: Enabling Tab Completion in Bash
- Example: Enabling Tab Completion in Zsh
- 4. Configuring CLI Settings
- Example: Setting CLI Config File Path
- Example: Disabling Plugin Caching
- 5. Setting Up Credentials
- Example: AWS Provider Configuration
- 6. Configuring Plugin Cache
- Example: Setting Plugin Cache Directory
- 7. Setting Environment Variables
- Example: Setting TF_LOG for Debugging
- 8. Using Terraform Wrapper Tools
- Example: Using tfenv to manage Terraform versions
- Example: Using tfswitch to switch versions
- 9. Configuring Credential Helpers
- Example: Configuring AWS Credential Helper
- Example: Using AWS Credential Helper in Terraform
- 10. Setting Provider Installation Methods
- Example: Automatic Provider Installation
Writing Configuration Files (HCL)
- 1. Understanding HCL Syntax
- Example: Basic HCL Block
- Key Concepts
- 2. Creating Terraform Files
- Example: Basic Terraform Configuration File
- 3. Organizing Configuration Files
- Directory Structure Best Practices
- Example: Module Organization
- Key Principles
- 4. Using Comments (# single-line, /* */ multi-line)
- Example: Using Comments in HCL
- 5. Defining Resource Blocks
- Example: Basic Resource Block
- Example: Resource with Count
- Example: Resource with Dependencies
- 6. Setting Block Labels
- Example: Resource with Labels
- Example: Data Source with Labels
- 7. Using Arguments and Attributes (key = value)
- Example: Resource with Arguments and Attributes
- 8. Understanding Meta-Arguments
- Example: Using
- Example: Using
- Example: Using
- Example: Using
- 9. Formatting Code
- Example: Formatting with terraform fmt
- 10. Validating Syntax
- Example: Validating a Terraform Configuration
- 11. Using Override Files
- Example: Using override files for environments
- Example: Override variables in terraform.tfvars
Managing Terraform Providers
- 1. Declaring Provider Blocks
- Example: Basic Provider Block
- Example: Provider with Alias
- 2. Configuring Provider Settings
- Example: Provider Configuration
- 3. Using Multiple Provider Instances
- Example: Using Different AWS Regions
- 4. Setting Provider Version Constraints
- Example: Provider Version Constraint
- 5. Understanding Provider Requirements
- Example: Declaring a Provider Requirement
- 6. Configuring Provider Authentication
- Example: AWS Provider with IAM Role
- Example: GitHub Provider with Token
- 7. Installing Providers
- Example: Installing AWS Provider
- 8. Upgrading Providers
- Example: Upgrading Providers
- Example: Specifying Provider Version Constraints
- Upgrade Best Practices
- 9. Locking Provider Versions
- Example: Using provider version constraints
- 10. Using Custom Providers
- Example: Using a Custom Provider
- 11. Configuring Provider Proxy Settings
- Example: Setting Proxy in Terraform Configuration
Managing Input Variables
- 1. Declaring Input Variables
- Example: Declaring Variables in Terraform
- 2. Setting Variable Types
- Example: Declaring a variable with type
- Example: Using a list variable
- Example: Using a map variable
- 3. Defining Default Values
- Example: Using Default Values in a Variable Definition
- Example: Default Value in a Resource Block
- 4. Adding Variable Descriptions
- Example: Variable with Description
- 5. Validating Variable Values
- Example: Validating Instance Type
- Example: Validating Numeric Range
- 6. Marking Variables Sensitive
- Example: Declaring a Sensitive Variable
- 7. Setting Variables via CLI
- Example: Setting Variables via CLI
- 8. Using Variable Files
- Example: Using a .tfvars file
- Example: Using a JSON variable file
- 9. Using Environment Variables
- Example: Setting Environment Variables
- 10. Referencing Variables
- Example: Referencing Variables in Expressions
- 11. Setting Variable Precedence
- Example: Setting Variables via Environment
- Example: Setting Variables via CLI
- 12. Using Nullable Variables
- Example: Setting nullable variable
- Example: Using nullable variable in resource
Managing Local Values
- 1. Declaring Local Values
- Example: Declaring a local value
- Example: Using a local value in a resource
- 2. Computing Derived Values
- Example: Using
- Example: Using
- 3. Referencing Local Values
- Example: Referencing Local Values in Variables
- Example: Using Local Values in Resource Configuration
- 4. Using Locals for DRY
- Example: Reusing Region in Multiple Resources
- 5. Combining Multiple Expressions
- Example: Concatenating Strings
- Example: Combining Lists
- Example: Conditional Expression with Multiple Values
- 6. Using Locals with Functions
- 7. Organizing Locals by Purpose
- Example: Organizing locals in modules
- 8. Comparing Locals vs Variables
- When to Use Which?
- 9. Using Locals in Modules
- Example: Defining and Using Locals in Modules
- 10. Referencing Locals in Outputs
- Example: Outputting a Local Value
Defining Output Values
- 1. Declaring Output Values
- Example: Basic Output Declaration
- Example: Output with Description
- 2. Exposing Resource Attributes
- Example: Outputting Instance ID
- Example: Outputting S3 Bucket Domain Name
- 3. Adding Output Descriptions
- Example: Defining Output with Description
- 4. Marking Outputs Sensitive
- Example: Defining a Sensitive Output
- 5. Setting Output Dependencies
- Example: Defining Outputs with Dependencies
- 6. Viewing Output Values
- Example: Output Declaration
- Example: Viewing Outputs
- Example: Viewing Specific Output
- 7. Formatting Output
- Example: Using format function in output
- 8. Using Outputs in Parent Modules
- Example: Defining Output in Child Module
- Example: Consuming Output in Parent Module
- 9. Exporting State Data
- Example: Basic Output Definition
- Example: Sensitive Output
- 10. Using Preconditions in Outputs
- Example: Validating Output with Precondition
Working with Resources
- 1. Creating Resources
- Example: Creating an AWS Instance
- 2. Referencing Resource Attributes
- Example: Using Resource Attributes in Variables
- 3. Using Resource Dependencies
- Example: Defining Explicit Dependencies
- 4. Setting Resource Timeouts
- Example: Setting Custom Timeouts
- 5. Configuring Lifecycle Rules
- Example: Using Lifecycle Rules
- 6. Preventing Resource Destruction
- Example: Preventing Resource Destruction
- 7. Ignoring Attribute Changes
- Example: Ignoring Attribute Changes
- 8. Creating Resources Before Destroying
- Example: Creating Resources Before Destroying
- 9. Replacing Matched Resources
- Example: Replacing Matched Resources
- 10. Using Resource Preconditions
- Example: Using Resource Preconditions
- 11. Using Resource Postconditions
- Example: Using Resource Postconditions
- 12. Replacing Resources
- Example: Replacing Resources
Using Data Sources
- 1. Declaring Data Blocks
- Example: Using Data Block in Resource
- 2. Querying External Data
- Example: Fetching AWS Instance Information
- Example: Using Data Source in Resource Configuration
- Key Concepts
- 3. Filtering Data Source Results
- Example: Filtering EC2 Instances by Tag
- 4. Referencing Data Attributes
- Example: Referencing Data Attributes
- 5. Using Data Source Dependencies
- Example: Using depends_on with Data Sources
- 6. Reading Remote State
- Example: Reading remote state in Terraform
- 7. Using Template Data Sources
- Example: Using Template Data Source
- 8. Querying Cloud Provider APIs
- Example: Fetching Latest AMI ID from AWS
- Example: Using the Fetched AMI ID in a Resource
- 9. Using External Programs
- Example: Executing a Shell Script
- Example: Capturing JSON Output
- 10. Using Lifecycle with Data Sources
- Example: Preventing Destruction of Data Source
- 11. Combining Multiple Data Sources
- Example: Combining AWS AMI and VPC Data Sources
Working with Complex Data Types
- 1. Using Lists and Tuples
- Example: List Operations
- 2. Using Maps and Objects
- Example: Map Usage
- 3. Using Sets
- Example: Set Operations
- 4. Using Nested Objects
- Example: Nested Object Access
- 5. Using Optional Object Attributes
- Example: Optional Attribute Handling
- 6. Using Type Constraints
- Example: Type Constraint Enforcement
- 7. Converting Between Types
- Example: Type Conversion
- 8. Using Structural Types
- Example: Structural Type Usage
- 9. Merging Complex Objects
- Example: Merging Maps
- 10. Flattening Nested Structures
- Example: Flattening Nested Lists
Working with Expressions
- 1. Writing String Expressions
- Example: String Concatenation
- Example: String Interpolation
- 2. Using Arithmetic Operators (+, -, *, /)
- Example: Basic Arithmetic in Variables
- 3. Using Comparison Operators (==, !=,
- Example: Using Comparison Operators in Conditions
- 4. Using Logical Operators (&&, ||, !)
- Example: Combining Conditions
- Example: Negating Conditions
- 5. Using Conditional Expressions (condition ? true : false)
- Example: Conditional Resource Creation
- Example: Conditional Variable Assignment
- 6. Using For Expressions ([for item in list])
- Example: Transforming a List of Numbers
- Example: Building a Map from a List
- 7. Using Splat Expressions (resource.*.attribute)
- Example: Accessing Public IPs from Multiple Instances
- Example: Using Splat in a Variable
- 8. Accessing Map and Object Attributes
- Example: Accessing Map Attributes
- Example: Accessing Object Attributes with Bracket Notation
- 9. Using String Templates
- Example: Using templatefile()
- Example: Template file (user-data.sh.tmpl)
- 10. Understanding Type Constraints
- Example: Type Constraints in Variables
- Example: Type Constraints in Outputs
- 11. Using Null Values
- Example: Using null in conditional expressions
Using Numeric and Type Functions
- 1. Using abs Function
- Example: Calculating Absolute Values in Variables
- 2. Using ceil and floor Functions
- Example: Rounding Numbers in Terraform
- Example: Using floor for Resource Counting
- 3. Using max and min Functions
- Example: Using max() and min() in a variable
- Example: Using max() and min() in a conditional
- 4. Using parseint Function
- Example: Parsing Integer from String
- Example: Parsing Binary String
- 5. Using pow and signum Functions
- 6. Using tostring Function
- 7. Using tonumber Function
- 8. Using tobool Function
- Example: Converting String to Boolean
- Example: Using in Conditionals
- 9. Using tolist and toset Functions
- 10. Using tomap Function
- Example: Converting a List to a Map
- Example: Using tomap with a Set
Using String Functions
- 1. Using chomp and trim Functions
- Example: Using chomp and trim in a Terraform template
- 2. Using format and formatlist Functions
- Example: Using format Function
- Example: Using formatlist Function
- 3. Using join and split Functions
- Example: join Function Usage
- Example: split Function Usage
- 4. Using lower and upper Functions
- Example: Using lower() and upper() Functions
- 5. Using replace Function
- Example: Replace in a variable
- 6. Using substr Function
- Example: Extracting Substring
- Example: Using with Variables
- 7. Using regex and regexall Functions
- 8. Using startswith and endswith Functions
- 9. Using strrev Function
- Example: Reversing a String in Terraform
- 10. Using title Function
- Example: title Function Usage
Using Collection Functions
- 1. Using concat Function
- Example: Concatenating Lists
- Example: Concatenating Lists with Different Types
- 2. Using contains Function
- 3. Using distinct Function
- Example: Removing Duplicates from a List
- 4. Using flatten Function
- Example: Flattening a Nested List
- Example: Flattening Lists with Different Types
- 5. Using length Function
- Example: Calculating List Length
- Example: String Length Validation
- 6. Using element and index Functions
- 7. Using keys and values Functions
- Example: Using keys() and values()
- 8. Using lookup and try Functions
- 9. Using merge Function
- Example: Merging Maps in Terraform Configuration
- 10. Using range Function
- Example: Basic usage of range function
- Example: Using range with custom start and step
- 11. Using reverse and sort Functions
- Example: Reversing and Sorting Lists
- 12. Using slice Function
- Example: Slicing a List
Using Encoding Functions
- 1. Using base64encode and base64decode Functions
- Example: Encoding and Decoding a Secret
- Example: Decoding a Base64 Value
- 2. Using jsonencode and jsondecode Functions
- Example: Using jsonencode to format a map
- Example: Using jsondecode to parse a JSON string
- 3. Using yamlencode and yamldecode Functions
- Example: Using yamlencode to format data
- Example: Using yamldecode to parse data
- 4. Using csvdecode Function
- Example: Decoding CSV Data
- 5. Using urlencode Function
- Example: Encoding a URL Parameter
- 6. Using textencodebase64 and textdecodebase64 Functions
- Example: Encoding and Decoding with Base64
- Example: Decoding Base64 Data
- 7. Using base64gzip Function
- Example: Encoding and Decoding with base64gzip
- 8. Using md5 and sha256 Functions
- Example: Using md5() in a variable
- Example: Using sha256() in a resource
- 9. Using uuid and uuidv5 Functions
- 10. Using bcrypt Function
- Example: Hashing a Password with bcrypt
Using Filesystem Functions
- 1. Using file Function
- Example: Reading a File
- 2. Using fileexists Function
- Example: Check if a file exists before reading it
- 3. Using fileset Function
- Example: Using fileset to read all .tf files in a directory
- 4. Using filebase64 Function
- Example: Reading a file and encoding it in base64
- 5. Using templatefile Function
- Example: Basic usage of templatefile
- Example: Template file (user-data.sh)
- 6. Using abspath Function
- Example: Resolving Relative Paths
- 7. Using dirname and basename Functions
- Example: Using dirname and basename
- 8. Using pathexpand Function
- Example: Expanding a Path with Tilde
- Example: Using Environment Variables
- 9. Using filemd5 and filesha256 Functions
- 10. Using templatestring Function
- Example: Basic Usage
- Example: With Numbers
Using Date, Time, and Network Functions
- 1. Using timestamp Function
- Example: Using timestamp in resource naming
- 2. Using formatdate Function
- Example: Formatting Current Date
- Example: Formatting Specific Timestamp
- 3. Using timeadd Function
- Example: Adding one hour to a timestamp
- Example: Adding 30 minutes to a timestamp
- 4. Using timecmp Function
- Example: Comparing Time Values
- 5. Using plantimestamp Function
- Example: Using plantimestamp in a resource
- 6. Using cidrhost Function
- Example: Generate IP Address from CIDR Block
- 7. Using cidrsubnet Function
- Example: Basic Usage
- Example: Subnetting with Different Prefix Lengths
- 8. Using cidrnetmask Function
- Example: Using cidrnetmask in a Network Configuration
- 9. Using cidrsubnetloop Function
- Example: Using cidrsubnetloop to Generate Subnets
- 10. Using cidrcontains Function
- Example: Checking if an IP is within a subnet
- Example: Checking if a subnet is contained within another
Using Advanced Functions
- 1. Using alltrue and anytrue Functions
- 2. Using can and try Functions
- Example: Using
- Example: Using
- 3. Using coalesce and coalescelist Functions
- 4. Using compact Function
- Example: Using compact Function
- Usage Summary
- 5. Using one Function
- 6. Using matchkeys Function
- Example: Using matchkeys to select subnet CIDR blocks
- 7. Using setintersection and setunion Functions
- Example: Using setintersection()
- Example: Using setunion()
- 8. Using setsubtract and setproduct Functions
- Example: Using setsubtract to filter resources
- Example: Using setproduct to generate combinations
- 9. Using sum and product Functions
- Example: Using sum() to calculate total resource count
- Example: Using product() to calculate total CPU cores
- 10. Using sensitive and nonsensitive Functions
- Example: Using sensitive and nonsensitive Functions
Using Meta-Arguments
- 1. Using depends_on Meta-Argument
- Example: Using depends_on to enforce resource order
- 2. Using count Meta-Argument
- Example: Creating Multiple Instances
- Example: Using count with a Variable
- Key Points
- 3. Using for_each Meta-Argument
- Example: Creating Multiple S3 Buckets
- Example: Using for_each with Modules
- Key Points
- 4. Using provider Meta-Argument
- Example: Using provider alias
- 5. Using lifecycle Meta-Argument
- Example: Using lifecycle with prevent_destroy
- Example: Using lifecycle with ignore_changes
- 6. Understanding create_before_destroy
- Example: Using create_before_destroy
- 7. Understanding prevent_destroy
- Example: Using prevent_destroy
- 8. Understanding ignore_changes
- Example: ignore_changes in a resource block
- 9. Using precondition and postcondition
- Example: Using precondition and postcondition in a resource
- 10. Using replace_triggered_by
- Example: Triggering Resource Replacement
Using Count Meta-Argument
- 1. Creating Multiple Resources
- Example: Creating Multiple S3 Buckets
- Key Points
- 2. Referencing Count Index
- Example: Using count.index in resource configuration
- 3. Using Conditional Resource Creation (count = condition ? 1 : 0)
- Example: Conditional EC2 Instance Creation
- 4. Accessing Count Resources
- Example: Accessing Count Resources in Variables
- 5. Understanding Count Limitations
- 6. Using Count with Modules
- Example: Creating Multiple S3 Buckets
- 7. Handling Count Changes
- Example: Changing Count Value
- 8. Combining Count with Conditionals
- Example: Conditional Resource Creation with Count
- Example: Using Count with Conditionals in Variables
- 9. Using Count with Data Sources
- Example: Using count with data sources
- Example: Using for_each with data sources
- 10. Converting Count to For-Each
- Example: Converting Count to For-Each
Using For-Each Meta-Argument
- 1. Using For-Each with Maps
- Example: Creating Multiple S3 Buckets Using a Map
- Key Points
- 2. Using For-Each with Sets
- Example: Creating Multiple S3 Buckets Using a Set
- 3. Accessing Each Iterator
- Example: Using each.key and each.value
- 4. Referencing For-Each Resources
- Example: Referencing For-Each Resources in Expressions
- 5. Comparing Count vs For-Each
- Example: Count Usage
- Example: For-Each Usage
- When to Use Which?
- 6. Using For-Each with Modules
- Example: Using for_each with a Module
- Example: Module Input Variables
- Example: Variable Definition
- 7. Converting Lists to Maps
- Example: Converting a List to a Map
- 8. Handling For-Each Changes
- Example: Adding new elements to for_each
- 9. Using Dynamic Keys
- Example: Dynamic Keys from a Map
- Example: Converting Non-String Keys to Strings
- 10. Filtering For-Each Collections
- Example: Filtering with for_each
Using Dynamic Blocks
- 1. Creating Dynamic Blocks
- Example: Creating Dynamic Subnets
- Example: Using Dynamic Blocks with Maps
- 2. Iterating with for_each
- Example: Using for_each with a resource
- Example: Using for_each with a module
- 3. Using Iterator Object
- Example: Using iterator object in a dynamic block
- Example: Custom iterator name
- 4. Accessing Content Block
- Example: Using for_each to create multiple resources
- Example: Using dynamic blocks with content
- 5. Nesting Dynamic Blocks
- Example: Nesting Dynamic Blocks
- Nesting Dynamic Blocks - Key Points
- 6. Using Conditional Dynamic Blocks
- Example: Conditional Dynamic Block with
- Example: Using
- 7. Combining Dynamic and Static Blocks
- Example: Combining Dynamic and Static Blocks
- 8. Using Dynamic Blocks for Complex Objects
- Example: Using Dynamic Blocks for Security Group Rules
- Example: Complex Nested Object with Multiple Attributes
- 9. Setting Custom Iterator Names
- Example: Custom Iterator Name
- 10. Using Dynamic Labels
- Example: Defining Dynamic Labels
Using Looping Techniques
- 1. Using Nested For Expressions
- Example: Nested For Loop with Lists
- Example: Nested For Loop with Maps
- Example: Nested For Loop with Index
- 2. Using For-Each with Dynamic Blocks
- Example: Creating Multiple S3 Buckets
- Example: Using for_each with Dynamic Blocks
- 3. Filtering with For Expressions
- Example: Filtering Lists
- Example: Filtering with Index
- 4. Transforming Data with For
- Example: Using for_each to create multiple S3 buckets
- Example: Using for to transform a list of strings
- 5. Using Splat with For
- Example: Using Splat with For
- 6. Combining Count and For-Each
- Example: Combining Count and For-Each
- 7. Using For with Maps and Objects
- Example: Creating Multiple S3 Buckets
- 8. Using For with Conditional Logic
- Example: Using for_each with conditional logic
- Example: Using count with conditional logic
- 9. Flattening Nested Loops
- Example: Flattening nested loops with local values
- 10. Using For with Zip and Range
- Example: Using zipmap with range
- Example: Using range with for_each
Working with Modules
- 1. Creating Module Structure
- Example: Basic Module Structure
- Example: Module with Examples and Tests
- 2. Calling Modules
- Example: Basic Module Call
- Example: Module with Version
- 3. Passing Input Variables
- Example: Using a local module with input variables
- Example: Using a remote module with version constraint
- 4. Setting Module Sources
- Example: Using a Local Module Source
- Example: Using a Git Module Source
- 5. Versioning Modules
- Example: Using Module Version
- Example: Using Git Ref
- Best Practices for Module Versioning
- 6. Accessing Module Outputs
- Example: Using Module Outputs in Parent Configuration
- 7. Using Module Dependencies
- Example: Module with Version Constraint
- 8. Publishing Modules
- Example: Publishing to Terraform Registry
- 9. Using Private Module Registry
- Example: Using Private Module Registry
- 10. Managing Module Composition
- Example: Using a Module with Version Constraint
- Best Practices for Module Composition
- 11. Refactoring with Modules
- Example: Migrating to Modules
- Workflow: Refactoring Process
- 12. Using Module Providers
- Example: Using Module Providers
Building Reusable Modules
- 1. Designing Module Interfaces
- Example: Module Interface Design
- Best Practices for Module Interfaces
- 2. Using Variable Validation
- Example: Validating Input Length
- Example: Validating Numeric Range
- 3. Implementing Module Best Practices
- Module Best Practices Summary
- Example: Module with Validation
- Module vs. Resource
- Module Development Workflow
- 4. Documenting Modules
- Example: Module Documentation Structure
- Module Documentation Checklist
- 5. Using Output Descriptions
- Example: Defining Outputs with Descriptions
- 6. Handling Module Defaults
- Example: Setting Default Provider Configuration
- 7. Implementing Module Testing
- Example: Basic Module Test Setup
- Example: Test Configuration
- Example: Test Case Definition
- Testing Best Practices
- 8. Versioning Module Releases
- Example: Module Version in Registry
- Best Practices for Module Versioning
- 9. Creating Module Examples
- Example: Basic Module Structure
- 10. Publishing to Registry
- Example: Publishing a module to the Terraform Registry
Managing Module Composition Patterns
- 1. Using Root Modules
- Example: Root Module Configuration
- 2. Creating Child Modules
- Example: Creating a child module
- 3. Implementing Module Nesting
- Example: Using Nested Modules
- 4. Using Module Dependencies
- Example: Module with Dependencies
- Example: Registry Module with Version
- 5. Sharing Data Between Modules
- Example: Referencing Module Outputs
- Example: Using Output Values in Variables
- 6. Implementing Module Abstraction
- Example: Abstracting EC2 Instance Creation
- 7. Creating Module Wrappers
- Example: Basic Module Wrapper
- Wrapper vs Direct Module Usage
- 8. Using Module Factory Patterns
- Example: Factory Module for EC2 Instances
- Example: Factory Module Implementation
- 9. Implementing Module Versioning Strategies
- Example: Using Registry Module with Version Pinning
- Example: Using Git Tag for Module Version
- 10. Managing Cross-Module State
- Example: Using Module Outputs
Initializing Working Directories
- 1. Initializing Working Directory
- Example: Initialize a Terraform working directory
- Initialization Process Overview
- 2. Downloading Providers and Modules
- Example: Initializing Providers and Modules
- Initialization Process
- 3. Upgrading Providers
- Example: Upgrading Providers
- 4. Migrating State Backend
- Example: Migrating from local to remote backend
- 5. Reconfiguring Backend
- Example: Reconfiguring Backend
- 6. Specifying Plugin Directory
- Example: Setting Plugin Cache Directory
- 7. Using Backend Configuration Files
- Example: S3 Backend Configuration
- 8. Generating Lock Files
- Example: Lock file content
- Lock File Management
- 9. Initializing for Specific Platforms
- Example: Initializing Terraform on macOS
- 10. Handling Init Errors
- Example: Resolving Plugin Installation Failure
Planning Infrastructure Changes
- 1. Creating Execution Plan
- Example: Creating a basic plan
- 2. Saving Plan Files
- Example: Saving a plan file
- 3. Reviewing Plan Output
- Example: Plan output format
- 4. Using Target Resources
- Example: Targeting specific resources
- 5. Refreshing State
- Example: Skipping refresh for faster plan generation
- 6. Generating Destroy Plan
- Example: Generating a destroy plan
- 7. Disabling Refresh
- 8. Setting Variable Values
- Example: Setting variables from command line
- 9. Using Variable Files
- Example: Using variable files
- 10. Generating Machine-Readable Output
- Example: Generating JSON plan output
Applying Infrastructure Changes
- 1. Applying Configuration
- Example: Applying Configuration
- 2. Auto-Approving Changes
- Example: Enabling Auto-Approve in CI/CD
- 3. Applying Saved Plans
- Example: Applying a Saved Plan
- 4. Targeting Specific Resources
- Example: Targeting a Specific Resource
- Example: Targeting a Module
- 5. Replacing Resources
- Example: Replacing a Resource Safely
- 6. Using Parallelism
- Example: Limiting Parallelism
- 7. Applying with Variable Files
- Example: Using Variable Files
- Example: Variable File Content
- 8. Handling Apply Errors
- Example: Resource Dependency Error
- 9. Using Compact Warnings
- Example: Enabling Compact Warnings
- 10. Limiting Input Prompts
- Example: Using -auto-approve flag
Destroying Infrastructure
- 1. Destroying All Resources
- Example: Destroying All Resources
- 2. Auto-Approving Destruction
- Example: Destroy with auto-approval
- 3. Destroying Specific Resources
- Example: Destroying a Specific S3 Bucket
- Example: Targeted Destruction Command
- 4. Generating Destroy Plans
- Example: Generating a destroy plan
- 5. Using Variable Files
- Example: Defining Variables in
- Example: Setting Values in
- Example: Using Variables in
- Workflow: Applying Variables from Files
- 6. Understanding Destroy Order
- Example: Destroy Order in Practice
- Destroy Order Workflow
- Key Points
- 7. Handling Destroy Errors
- Example: Resolving Dependency Conflicts
- 8. Using Parallelism
- Example: Setting max parallelism
- Parallelism Best Practices
- 9. Confirming Destruction
- Example: Approving Destruction
- 10. Preventing Accidental Destruction
- Example: Using -auto-approve with caution
- Best Practices for Safe Destruction
Managing Terraform State
- 1. Understanding State Files
- Example: State file structure
- 2. Listing State Resources
- Example: Listing all resources in state
- Example: Listing resources with a specific state file
- 3. Showing Resource State
- Example: Displaying state for a specific resource
- Example: Displaying state in JSON format
- 4. Moving Resources
- Example: Moving a Resource
- Example: Moving a Module
- 5. Removing Resources
- Example: Removing an AWS Instance
- 6. Replacing Provider Addresses
- Example: Replacing Provider Address
- 7. Pulling Remote State
- Example: Pulling Remote State
- 8. Pushing Local State
- Example: Pushing State to S3 Backend
- 9. Refreshing State
- Example: Refreshing State
- 10. Backing Up State Files
- Example: Manual backup using terraform state pull
- Example: Restore state from backup
- 11. Recovering from State Corruption
- Example: Force Unlocking State
- Example: Reverting to Backup
- Recovery Steps Summary
Configuring Remote Backends
- 1. Declaring Backend Configuration
- Example: Declaring a remote backend in Terraform
- 2. Using S3 Backend
- Example: S3 Backend Configuration
- 3. Using Azure Blob Backend
- Example: Basic Configuration with Access Key
- Example: Configuration with Azure AD Authentication
- 4. Using GCS Backend
- Example: GCS Backend Configuration
- 5. Configuring State Locking
- Example: DynamoDB State Locking Configuration
- 6. Migrating Backend Configuration
- Migration Process Overview
- Example: Migrating from Local to S3 Backend
- 7. Using HTTP Backend
- Example: HTTP Backend Configuration
- 8. Configuring Terraform Cloud Backend
- Example: Basic Terraform Cloud Backend Configuration
- 9. Setting Backend Encryption
- Example: S3 Backend with Encryption
- 10. Using Partial Backend Configuration
- Example: Partial Backend Configuration
Implementing State Locking
- 1. Understanding State Locking
- Example: Enabling State Locking
- 2. Configuring Lock Mechanisms
- Example: S3 Backend with Locking
- 3. Forcing Unlock
- Example: Forcing Unlock
- When to Use Force Unlock
- 4. Handling Lock Conflicts
- Steps to Resolve Lock Conflicts
- 5. Using Lock Timeout
- Example: Setting Lock Timeout in Backend Configuration
- 6. Monitoring Lock Status
- Example: Checking Lock Status
- 7. Disabling Locking
- Example: Disabling Locking in Backend Configuration
- 8. Using Locks with Automation
- Example: Automating State Locking with Terraform Cloud
- Best Practices for Automation
- 9. Implementing Custom Locks
- Example: Custom Lock Implementation with HTTP
- 10. Troubleshooting Lock Issues
- Example: Force unlock a stale lock
Working with Workspaces
- 1. Understanding Workspaces
- Example: Creating a new workspace
- 2. Listing Workspaces
- Example: Listing Workspaces
- 3. Creating Workspaces
- Example: Creating a New Workspace
- 4. Switching Workspaces
- Example: Switching to a workspace
- 5. Deleting Workspaces
- Example: Deleting a Workspace
- 6. Showing Current Workspace
- 7. Using Workspace in Configuration
- Example: Using workspace in configuration
- 8. Managing Workspace State
- Example: Creating and Switching Workspaces
- 9. Comparing Workspaces vs Modules
- Example: Workspace Variables
- Example: Module Usage
- 10. Implementing Workspace Naming Strategies
- Example: Workspace Naming Convention
- Best Practices for Workspace Naming
Managing Multi-Environment Deployments
- 1. Using Workspaces for Environments
- Example: Creating and Switching Workspaces
- Example: Listing Workspaces
- 2. Using Separate Directories
- Example: Directory Structure
- Best Practices
- 3. Using Variable Files per Environment
- Example: Environment-specific variables
- Example: Using variable files in CLI
- 4. Using Remote State per Environment
- Example: S3 Backend Configuration
- Example: Environment-Specific State Keys
- 5. Implementing Environment-Specific Resources
- Example: Environment-specific S3 Bucket
- Example: Environment-specific EC2 Instance
- 6. Using Modules for Shared Code
- Example: Using a Module
- Module Best Practices
- 7. Managing Environment Variables
- Example: Setting Environment Variables
- Example: Using Variables in Configuration
- 8. Using Terraform Cloud Workspaces
- Example: Creating a Workspace
- Key Features of Workspaces
- 9. Implementing Promotion Workflows
- Example: Promotion Workflow with Environment Variables
- Key Considerations
- 10. Using GitOps for Environments
- Example: GitOps Workflow with Terraform
- GitOps Benefits
Managing Dependencies
- 1. Using Implicit Dependencies
- Example: Implicit dependency via resource reference
- 2. Using Explicit Dependencies
- Example: Module with Explicit Dependencies
- 3. Understanding Dependency Graph
- Example: Explicit Dependency Declaration
- Dependency Resolution Workflow
- 4. Visualizing Dependencies
- Example: Dependency Graph with
- Example: Exporting Graph to PNG
- Key Features of Dependency Visualization
- 5. Handling Circular Dependencies
- Example: Circular Module Dependency
- Workflow to Resolve Circular Dependencies
- Best Practices to Avoid Circular Dependencies
- 6. Using Module Dependencies
- Example: Using a Module from the Registry
- Example: Using a Local Module
- 7. Managing Provider Dependencies
- Example: Using provider version constraints
- Example: Using multiple provider configurations
- 8. Ordering Resource Creation
- Example: Using depends_on
- Example: Using lifecycle preconditions
- 9. Using Data Source Dependencies
- Example: Fetching AMI ID from AWS
- Example: Using Data Source in Resource
- 10. Debugging Dependency Issues
- Example: Resolving Provider Version Conflicts
Visualizing Terraform Graph
- 1. Generating Dependency Graph
- Example: Generating a dependency graph
- Example: Generating a graph with cycle detection
- Summary of terraform graph command
- 2. Exporting Graph to DOT Format
- Example: Exporting Graph to DOT Format
- Example: Visualizing DOT Graph with Graphviz
- 3. Rendering Graph Images
- Example: Render graph as PNG
- Example: Render graph as SVG
- 4. Filtering Graph by Type
- 5. Generating Plan Graphs
- Example: Generate a plan graph
- Example: Save plan to file and generate graph
- Example: Generate JSON graph output
- 6. Analyzing Resource Dependencies
- Example: Dependency Analysis with
- 7. Identifying Circular Dependencies
- Example: Direct Circular Dependency
- How to Identify Circular Dependencies
- Common Causes of Circular Dependencies
- Circular Dependency vs. Valid Dependency
- 8. Using Graph Tools
- Example: Generating a Graph with
- Example: Converting DOT to PNG
- Comparison: Graph Visualization Tools
- 9. Interpreting Graph Nodes
- Example: Resource Node
- Example: Data Source Node
- 10. Optimizing Graph Structure
- Example: Using depends_on for explicit ordering
- Best Practices for Graph Optimization
Implementing Provisioners
- 1. Using Local-Exec Provisioner
- Example: Running a local command
- Example: Setting environment variables
- 2. Using Remote-Exec Provisioner
- Example: Execute a script remotely
- 3. Using File Provisioner
- Example: Copying a file to remote instance
- Example: Writing content directly to a file
- 4. Configuring Connection Blocks
- Example: SSH Connection Configuration
- 5. Setting Provisioner Timing
- Example: Setting provisioner timing
- 6. Handling Provisioner Failures
- Example: Using on_failure to continue on error
- Best Practices for Provisioner Failures
- 7. Using Null Resource
- Example: Using null_resource with local-exec provisioner
- 8. Using terraform_data Resource
- Example: Using terraform_data to trigger a refresh
- Example: Using terraform_data to manage a file
- 9. Using Time Provider
- Example: Using Time Provider
- 10. Understanding Provisioner Limitations
Implementing Check Blocks
- 1. Declaring Check Blocks
- Example: Basic Check Block
- 2. Defining Check Assertions
- Example: Basic Check Assertion
- Example: Check with Multiple Conditions
- 3. Configuring Check Scoped Data Sources
- Example: Basic Check Block Configuration
- Example: Using Data Sources in Checks
- 4. Using Conditions in Checks
- Example: Conditional Check with Variables
- Example: Check with Resource Attributes
- 5. Adding Error Messages
- Example: Basic Error Message in Check Block
- 6. Running Continuous Validation
- Example: Continuous Validation with Terraform Cloud
- Key Points
- 7. Comparing Checks vs Preconditions
- Key Differences Summary
- 8. Handling Check Failures
- Example: Using assert to fail checks
- Check Failure Handling Summary
- 9. Using Checks for Drift Detection
- Example: Drift Detection with Check Blocks
- 10. Implementing Health Checks
- Example: Basic Health Check
Importing Existing Resources
- 1. Importing Resources
- Example: Importing an AWS EC2 Instance
- 2. Writing Import Blocks
- Example: Basic Import Block
- 3. Using Import Address
- Example: Importing an AWS Instance
- 4. Verifying Imported State
- Example: Check imported resource state
- Verification Steps
- 5. Importing Multiple Resources
- Example: Importing Multiple Resources with a Loop
- 6. Generating Configuration
- Example: Generate configuration for an existing AWS S3 bucket
- Steps to Generate Configuration
- 7. Handling Import Errors
- Common Import Error Scenarios and Solutions
- Example: Resolving State Mismatch
- 8. Using For-Each with Import
- Example: Importing Multiple Resources with For-Each
- 9. Importing into Modules
- Example: Importing into a Module
- 10. Documenting Imported Resources
- Example: Importing and Documenting a Google Compute Instance
- Best Practices for Importing Resources
Migrating to Terraform
- 1. Discovering Existing Infrastructure
- Example: Importing an AWS EC2 instance
- Workflow: Discovering and Importing Infrastructure
- 2. Importing Resources
- Example: Importing an AWS EC2 Instance
- 3. Generating Configuration
- Example: Basic Terraform Configuration
- 4. Using Import Blocks
- Example: Importing an AWS EC2 Instance
- 5. Validating Imported State
- Example: Validate imported state
- 6. Handling Import Conflicts
- Example: Resolving Duplicate Resource IDs
- Workflow: Resolving Import Conflicts
- Comparison: Import vs. Refresh
- 7. Migrating from CloudFormation
- Example: Migrating a Simple EC2 Instance
- Migration Steps Overview
- 8. Migrating from ARM Templates
- Example: Migrating a Resource Group
- Example: Migrating a Virtual Machine
- 9. Using Third-Party Import Tools
- Example: Using tfimport to import AWS resources
- 10. Documenting Migration Process
- Example: Migration Documentation Structure
Refactoring Terraform Configuration
- 1. Renaming Resources
- Example: Renaming a Resource in Configuration
- Workflow: Renaming a Resource Safely
- 2. Moving Resources Between Modules
- Example: Moving a Resource
- Workflow: Migrating Resource to New Module
- 3. Splitting Modules
- Example: Splitting Resources into Modules
- Best Practices for Module Splitting
- 4. Consolidating Resources
- Example: Consolidating S3 Buckets with for_each
- Example: Consolidating EC2 Instances with count
- 5. Removing Unused Resources
- Example: Removing an unused S3 bucket
- 6. Updating Resource Addresses
- Example: Updating Resource Address in State
- Example: Updating Resource Address in Configuration
- 7. Migrating from Count to For-Each
- Example: Migrating from Count to For-Each
- 8. Replacing Deprecated Features
- Example: Replacing
- 9. Using State Commands
- Example: Moving a resource
- Example: Removing a resource from state
- 10. Validating Refactoring
- Example: Validate refactored configuration
- Example: Validate with specific configuration directory
- Comparison: Validate vs Plan
Using Terraform Registry
- 1. Finding Provider Documentation
- Example: Using provider documentation in a module
- 2. Finding Module Documentation
- Example: Module Documentation URL Format
- 3. Publishing Public Modules
- Example: Publishing a Module
- Steps to Publish a Module
- 4. Versioning Published Modules
- Example: Module Version Constraint
- Example: Using Wildcard Version
- 5. Using Module Examples
- Example: Using a Public Module
- Example: Using a Module with Variables
- 6. Searching Registry
- Example: Search for AWS modules
- Example: Search with version filter
- 7. Viewing Module Sources
- Example: Viewing Module Source in Registry
- 8. Using Verified Modules
- Example: Using a Verified Module
- 9. Reviewing Module Downloads
- Example: Module Source Configuration
- Module Download Process
- 10. Contributing to Modules
- Example: Module structure
- Key Guidelines
Working with JSON and YAML Configuration
- 1. Using JSON Configuration Files
- Example: Basic JSON Configuration
- 2. Converting HCL to JSON
- Example: Converting HCL to JSON
- 3. Using jsonencode Function
- Example: Encoding a Map to JSON
- 4. Using jsondecode Function
- Example: Parsing JSON String
- 5. Using yamlencode Function
- 6. Using yamldecode Function
- 7. Loading External JSON Files
- Example: Reading JSON from a file
- Example: Using jsondecode() in Terraform
- 8. Generating JSON Output
- Example: Exporting Outputs to JSON
- Example: Exporting Specific Output to JSON
- 9. Using JSON in Templates
- Example: Encoding a Map to JSON
- Example: Decoding JSON from a Variable
- 10. Validating JSON Schema
- Example: Validating JSON with Schema
Handling Sensitive Data
- 1. Marking Variables Sensitive
- Example: Declaring a sensitive variable
- 2. Marking Outputs Sensitive
- Example: Marking an Output as Sensitive
- 3. Using Environment Variables
- Example: Setting Environment Variables
- 4. Storing Secrets in Vault
- Example: Using Vault with Terraform
- 5. Using Cloud Secret Managers
- Example: Retrieving Secret from AWS SSM Parameter Store
- Example: Using GCP Secret Manager
- 6. Encrypting State Files
- Example: S3 Backend with Encryption
- 7. Redacting Sensitive Values
- Example: Using sensitive flag
- 8. Using .gitignore for Secrets
- Example: .gitignore content
- 9. Rotating Credentials
- Example: Rotating AWS IAM Access Key
- 10. Auditing Secret Access
- Example: Enable Secret Access Auditing
- Secret Access Auditing Best Practices
Debugging Terraform
- 1. Enabling Debug Logging
- Example: Setting Debug Logging
- 2. Setting Log Levels
- Example: Setting Log Level via Environment Variable
- Example: Setting Log Level via CLI Flag
- 3. Logging to File
- Example: Enable detailed logging to file
- 4. Using Terraform Console
- Example: Evaluating Variables
- Example: Evaluating Expressions
- 5. Testing Expressions
- Example: Testing Expression Evaluation
- 6. Validating Configuration
- Example: Validating a Terraform Configuration
- 7. Checking Formatting
- Example: Format Terraform files
- 8. Reviewing Plan Output
- Example: Plan Output Summary
- Key Elements to Review
- 9. Using Terraform Show
- Example: Displaying state in human-readable format
- Example: Displaying state in JSON format
- 10. Debugging Provider Issues
- Example: Provider Configuration with Debugging
- 11. Handling Rate Limits
- Example: Configuring Retry Logic in Terraform
Optimizing Terraform Performance
- 1. Using Parallelism
- Example: Setting Max Parallelism in Configuration
- 2. Implementing Resource Targeting
- Example: Targeting a Specific Resource
- Example: Targeting Multiple Resources
- 3. Disabling Refresh
- Example: Disabling Refresh in Plan
- 4. Splitting Large Configurations
- Example: Module-Based Splitting
- Best Practices for Splitting Configurations
- 5. Using Remote State Caching
- Example: Configuring S3 Backend with Caching
- 6. Minimizing Provider API Calls
- Example: Reducing API Calls with Data Sources
- 7. Using Local Caching
- Example: Enabling Local Caching for Modules
- 8. Optimizing Module Structure
- Example: Efficient Module Structure
- Key Tips for Module Optimization
- 9. Reducing Plan Time
- Example: Using -target to reduce plan time
- Best Practices to Reduce Plan Time
- 10. Monitoring Apply Duration
- Example: Logging Apply Duration
Testing Terraform Code
- 1. Using Terraform Validate
- Example: Running terraform validate
- 2. Using Terraform Test Framework
- Example: Basic Test Case
- Workflow for Writing Tests
- 3. Writing Unit Tests
- Example: Test a simple data source
- Example: Using test block to validate resource creation
- 4. Writing Integration Tests
- Example: Basic Integration Test Structure
- Best Practices for Integration Tests
- 5. Using Terraform Plan Tests
- Example: Basic Plan Test
- Plan Test Summary
- 6. Implementing Policy Tests
- Example: Basic Policy Test
- Key Concepts
- 7. Using Mock Providers
- Example: Defining a Mock Provider
- Example: Using Mock Resources
- 8. Testing Module Outputs
- Example: Define and Test Module Output
- Example: Test Output in Terraform
- 9. Implementing End-to-End Tests
- Example: Basic E2E Test Setup
- Workflow: E2E Test Execution
- 10. Automating Test Runs
- Example: CI/CD Pipeline with Terraform Tests
- Best Practices for Test Automation
Implementing Security Best Practices
- 1. Using Least Privilege IAM
- Example: Define a minimal IAM role with least privilege
- 2. Encrypting State Files
- Example: S3 Backend with Encryption
- 3. Enabling State Locking
- Example: Enabling State Locking with S3 Backend
- 4. Validating Input Variables
- Example: Validating Input with Condition
- 5. Using Sentinel Policies
- Example: Basic Sentinel Policy
- 6. Scanning for Security Issues
- Example: Using tfsec to scan a Terraform configuration
- Example: Using Checkov to scan a directory
- 7. Implementing Network Restrictions
- Example: Allow HTTPS traffic only from a specific IP
- Example: Deny all outbound traffic
- Key Concepts
- 8. Using Private Module Registry
- Example: Using Private Module
- 9. Auditing Changes
- Example: Reviewing Terraform Plan Output
- Key Points for Auditing Changes
- 10. Implementing Drift Detection
- Example: Using Terraform Cloud for Drift Detection
- Drift Detection Summary
Implementing Compliance and Governance
- 1. Using Sentinel Policy Language
- Example: Hard Constraint Policy
- Example: Soft Constraint Policy
- Sentinel Policy Components
- 2. Implementing OPA Policies
- Example: Enforcing Resource Limits with OPA
- 3. Enforcing Tagging Standards
- Example: Tagging with Terraform
- 4. Validating Naming Conventions
- Example: Naming Convention Validation
- 5. Implementing Cost Controls
- Example: Setting up a Cost Budget
- Key Cost Control Strategies
- 6. Enforcing Security Baselines
- Example: Using tfsec to enforce security rules
- Example: Enforcing AWS security baseline with checkov
- 7. Using Policy Sets
- Example: Creating a Policy Set
- 8. Testing Policies
- Example: Policy Test Structure
- Example: Policy Test Case
- Testing Policy Best Practices
- 9. Auditing Policy Violations
- Example: Enforcing Tagging Policy
- Policy Enforcement Summary
- 10. Implementing Custom Policies
- Example: Terraform Sentinel Policy
- Policy Enforcement Levels
Using Terraform with CI/CD
- 1. Integrating with GitHub Actions
- Example: GitHub Actions Workflow
- Best Practices for CI/CD Integration
- 2. Integrating with GitLab CI
- Example: GitLab CI Pipeline Configuration
- 3. Integrating with Jenkins
- Example: Jenkins Pipeline Configuration
- Comparison: Jenkins vs Other CI/CD Tools
- 4. Integrating with Azure DevOps
- Example: Azure Pipeline YAML for Terraform
- Key Steps for Integration
- 5. Automating Terraform Init
- Example: Automating terraform init in a CI pipeline
- 6. Automating Plan and Apply
- Example: CI/CD Pipeline with Terraform Plan and Apply
- Best Practices for Automating Terraform Plan and Apply
- 7. Storing State Remotely
- Example: Configuring S3 Backend
- 8. Managing Secrets
- Example: Using Sensitive Variables
- Example: Using Environment Variables
- 9. Using Terraform Cloud Runs
- Example: Configuring Terraform Cloud Runs
- 10. Implementing GitOps Workflows
- Example: GitHub Actions Workflow
- Key GitOps Principles
Using Terraform Cloud and Enterprise
- 1. Configuring Terraform Cloud Backend
- Example: Remote Backend Configuration
- 2. Creating Organizations and Workspaces
- Example: Creating a Workspace via API
- Key Concepts
- 3. Connecting VCS Repositories
- Example: GitHub App Setup
- 4. Configuring Remote Execution
- Example: Remote Execution Configuration
- 5. Setting Up Sentinel Policies
- Example: Hard-Mandatory Policy
- Setting Up Sentinel Policies
- 6. Using Private Module Registry
- Example: Using a Private Module
- 7. Managing Teams and Permissions
- Example: Creating a Team and Assigning Members
- Example: Setting Up a Workspace with Variables
- Key Concepts
- 8. Configuring Notifications
- Example: Slack Notification Configuration
- Example: Webhook Notification Configuration
- 9. Using Cost Estimation
- Example: Enabling Cost Estimation
- 10. Setting Up Run Triggers
- Example: Setting up a Workspace Trigger
Using Terraform Stacks
- 1. Understanding Terraform Stacks
- Example: Basic Stack Structure
- Stacks vs Workspaces
- 2. Creating Stack Configuration
- Example: Stack Configuration File
- 3. Defining Stack Deployments
- Example: Defining a Stack Deployment
- 4. Using Orchestration Rules
- Example: Orchestration with depends_on
- 5. Managing Stack Dependencies
- Example: Using remote state to reference another stack
- 6. Using Stack Variables
- Example: Defining Stack Variables in HCL
- Example: Using Stack Variables in Resource Configuration
- 7. Implementing Stack Outputs
- Example: Defining Stack Outputs
- Example: Using Outputs in Parent Stacks
- 8. Deploying Stacks
- Example: Deploying a Stack
- Deployment Workflow
- 9. Managing Stack State
- Example: Configure S3 Backend
- State Management Best Practices
- 10. Using Stacks with Terraform Cloud
- Example: Enabling Stacks in Terraform Cloud
- Stacks with Terraform Cloud Summary
Using Terraform CDK
- 1. Installing CDK for Terraform
- Example: Initialize a CDK Project
- 2. Creating CDKTF Projects
- Example: Initialize a CDKTF Project
- 3. Defining Infrastructure in Code
- Example: Defining an S3 Bucket
- Example: Using Parameters
- 4. Synthesizing Configuration
- Example: Synthesizing a Simple Resource
- Synthesis Workflow
- 5. Deploying with CDKTF
- Example: Deploying a CDKTF Stack
- 6. Using CDKTF Providers
- Example: Using AWS Provider
- Example: Using Multiple AWS Regions
- 7. Converting HCL to CDKTF
- Example: Converting a simple HCL resource to CDKTF
- 8. Managing CDKTF State
- Example: Setting up S3 backend for CDKTF
- 9. Testing CDKTF Code
- Example: Unit Testing with Jest
- Testing Best Practices
- 10. Integrating CDKTF with CI/CD
- Example: GitHub Actions Workflow
- Best Practices
Working with AWS Provider
- 1. Configuring AWS Provider
- Example: Basic AWS Provider Configuration
- Example: Using Named Profile
- Example: Assume Role Configuration
- 2. Using AWS Authentication
- Example: Using Static Credentials
- Example: Using IAM Role from EC2 Instance
- 3. Managing AWS Resources
- Example: Creating an EC2 Instance
- Example: Creating an S3 Bucket
- Example: Creating an IAM Role
- 4. Using AWS Data Sources
- Example: Fetching AMI ID from a specific AMI name
- Example: Using availability zones to create subnets
- 5. Configuring Multiple Regions
- Example: Using Multiple Regions with Aliases
- 6. Using AWS Assume Role
- Example: Assume Role Configuration
- 7. Managing AWS Tags
- Example: Tagging an EC2 Instance
- Tagging Best Practices
- 8. Using AWS-Specific Functions
- Example: Using aws_ami_id in a launch configuration
- Example: Using aws_caller_identity to get account ID
- 9. Configuring S3 Backend
- Example: S3 Backend Configuration
- 10. Handling AWS API Throttling
- Example: Configuring Retry Settings
Working with Azure Provider
- 1. Configuring Azure Provider
- Example: Basic Azure Provider Configuration
- 2. Using Azure Authentication
- Example: Service Principal with Client Secret
- Example: Using Azure CLI
- 3. Managing Azure Resources
- Example: Create a Resource Group
- Example: Create a Virtual Machine
- Example: Create a Storage Account
- 4. Using Azure Data Sources
- Example: Using Azure Client Config
- Example: Using Azure Resource Group
- 5. Configuring Multiple Subscriptions
- Example: Multiple Subscriptions Configuration
- Subscription Management Best Practices
- 6. Managing Azure Tags
- Example: Assigning Tags to Azure Resource
- Example: Using Tags in Data Sources
- Example: Tag Inheritance from Parent
- 7. Using Azure-Specific Features
- Example: Using Azure AD Application
- Example: Using Managed Identity
- Key Azure-Specific Features
- 8. Configuring Azure Blob Backend
- Example: Basic Azure Blob Backend Configuration
- Example: Using Azure AD Authentication
- 9. Using Azure Key Vault
- Example: Accessing Azure Key Vault Secret in a VM
- 10. Handling Azure API Limits
- Example: Configuring Azure Provider with Retry Logic
Working with Google Cloud Provider
- 1. Configuring GCP Provider
- Example: Basic GCP Provider Configuration
- Example: Using Environment Variables
- 2. Using GCP Authentication
- Example: Service Account Key File Authentication
- Example: Using ADC with gcloud
- 3. Managing GCP Resources
- Example: Creating a Compute Instance
- Example: Creating a Storage Bucket
- 4. Using GCP Data Sources
- Example: Retrieve GCP Compute Image
- Example: Retrieve GCP Compute Network
- Example: Retrieve GCP Container Cluster
- 5. Configuring Multiple Projects
- Example: Multiple Projects Configuration
- Key Points
- 6. Managing GCP Labels
- Example: Applying Labels to GCP Compute Instance
- 7. Using GCP-Specific Features
- Example: Using GCP Service Account for Terraform
- 8. Configuring GCS Backend
- Example: GCS Backend Configuration
- 9. Using Google Secret Manager
- Example: Create a Secret
- Example: Add a Secret Version
- Example: Access Secret in a Cloud Function
- 10. Handling GCP API Quotas
- Example: Checking API Quota Usage
Upgrading Terraform
- 1. Checking Version Compatibility
- Example: Checking Terraform Version
- 2. Upgrading Terraform Binary
- Example: Upgrade Terraform Binary on macOS (Homebrew)
- Example: Upgrade Terraform Binary on Linux (via package manager)
- Example: Manual Download and Install (Linux x86_64)
- 3. Upgrading Provider Versions
- Example: Updating Provider Version in Configuration
- Example: Migrating from Old to New Provider
- 4. Using Terraform Upgrade Commands
- Example: Upgrading Terraform version
- Example: Upgrading provider versions
- 5. Updating State Format
- Example: Upgrading State Format
- 6. Handling Breaking Changes
- Example: Updating Resource Schema
- Steps to Handle Breaking Changes
- 7. Testing Upgrades
- Example: Test Upgrade Workflow
- 8. Using Version Constraints
- Example: Using version constraints in a Terraform module
- 9. Managing Provider Version Locks
- Example: Lock File Entry
- Managing Provider Locks
- 10. Rolling Back Upgrades
- Example: Reverting Terraform Binary
Implementing Disaster Recovery
- 1. Backing Up State Files
- Example: S3 Backend Configuration
- Best Practices for State Backup
- 2. Versioning State Files
- Example: Enabling Versioning in S3 Backend
- 3. Using Remote State Replication
- Example: S3 Backend with Replica Configuration
- 4. Implementing State Recovery
- Example: Recovering State from a Backup
- State Recovery Best Practices
- 5. Testing Disaster Recovery
- Example: Testing Recovery Procedures
- Recovery Testing Checklist
- 6. Using State File Snapshots
- Example: Creating a Full State Snapshot
- Example: Creating a Partial State Snapshot
- 7. Documenting Recovery Procedures
- Example: Recovery Procedure Documentation Structure
- Recovery Procedure Best Practices
- 8. Implementing Automated Backups
- Example: Scheduled Backup with CloudWatch Events
- Backup Strategy Summary
- 9. Using State Locking for DR
- Example: Enabling State Locking in Backend Configuration
- 10. Validating Restored State
- Example: Validate restored state with Terraform plan
- Validation Steps
Working with Ephemeral Values
- 1. Understanding Ephemeral Values
- Example: Defining Ephemeral Values
- 2. Using Ephemeral Variables
- Example: Defining an Ephemeral Variable
- 3. Using Ephemeral Outputs
- Example: Defining an Ephemeral Output
- 4. Managing Ephemeral Resources
- Example: Using for_each with ephemeral resources
- Example: Using lifecycle rules to manage ephemeral resources
- 5. Using Ephemeral Data Sources
- Example: Using Ephemeral Data Source for Runtime Values
- 6. Handling Ephemeral Provider Configuration
- Example: Ephemeral Provider Configuration
- 7. Comparing Ephemeral vs Sensitive
- 8. Using Ephemeral Values in Modules
- Example: Defining an Ephemeral Value in a Module
- 9. Understanding Ephemeral Limitations
- 10. Implementing Ephemeral Patterns
- Example: Using ephemeral values in a data source
- Example: Using ephemeral values in a resource
- Key Points
Implementing Common Terraform Patterns
- 1. Using Conditional Resource Creation
- Example: Conditional Resource Creation with
- Example: Conditional Resource Creation with
- 2. Implementing Resource Factories
- Example: Basic Resource Factory
- Example: Using Variables with Resource Factories
- Best Practices for Resource Factories
- 3. Creating Wrapper Modules
- Example: Basic Wrapper Module
- 4. Using Dynamic Configuration
- Example: Conditional Security Group Rules
- Example: Dynamic Variables in Modules
- Key Points
- 5. Implementing Feature Flags
- Example: Using Feature Flags in Module
- Example: Conditional Resource Creation
- 6. Using Null Labels Pattern
- Example: Conditional Resource Creation with null_resource
- 7. Implementing Environment Patterns
- Example: Environment-Specific Module Usage
- Best Practices for Environment Patterns
- 8. Using Remote State Pattern
- Example: S3 Backend Configuration
- Benefits of Remote State
- 9. Implementing Module Composition
- Example: Basic Module Composition
- Best Practices for Module Composition
- 10. Using Provider Configuration Patterns
- Example: Using Provider Aliases for Multi-Region Deployment