0
0
Terraformcloud~20 mins

Terraform in GitHub Actions - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform GitHub Actions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Terraform GitHub Action Workflow Behavior

Consider this GitHub Actions workflow snippet that runs Terraform commands:

name: Terraform Apply
on: [push]
jobs:
  terraform:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v2
        with:
          terraform_version: 1.5.0
      - name: Terraform Init
        run: terraform init
      - name: Terraform Apply
        run: terraform apply -auto-approve

What will happen if the Terraform configuration has syntax errors?

AThe workflow will fail at the 'Terraform Init' step with an error.
BThe workflow will skip the 'Terraform Apply' step automatically.
CThe workflow will succeed but no changes will be applied.
DThe workflow will fail at the 'Terraform Apply' step with an error.
Attempts:
2 left
💡 Hint

Think about when Terraform validates the configuration syntax.

Configuration
intermediate
2:00remaining
Correct Terraform GitHub Action Step for State Storage

You want to configure your GitHub Actions workflow to use an AWS S3 bucket as the Terraform remote backend for state storage. Which step correctly initializes Terraform with this backend?

Arun: terraform init -backend-config="bucket=mybucket" -backend-config="region=us-east-1"
Brun: terraform apply -backend-config="bucket=mybucket" -backend-config="region=us-east-1"
Crun: terraform plan -backend-config="bucket=mybucket" -backend-config="region=us-east-1"
Drun: terraform validate -backend-config="bucket=mybucket" -backend-config="region=us-east-1"
Attempts:
2 left
💡 Hint

Which Terraform command sets up the backend configuration?

security
advanced
2:00remaining
Securely Managing AWS Credentials in GitHub Actions for Terraform

You want to run Terraform in GitHub Actions to deploy AWS resources. What is the best practice to provide AWS credentials securely to the workflow?

AUse GitHub Secrets to store AWS credentials and reference them in the workflow environment variables.
BHardcode AWS credentials in Terraform configuration files checked into the repository.
CUse public AWS credentials with limited permissions in the workflow.
DStore AWS access key and secret key directly in the workflow YAML file.
Attempts:
2 left
💡 Hint

Think about how to keep secrets safe in GitHub repositories.

Architecture
advanced
2:00remaining
Handling Terraform State Locking in Concurrent GitHub Actions Runs

Your team runs Terraform apply in GitHub Actions on multiple branches simultaneously. What mechanism prevents state corruption when multiple runs try to modify the Terraform state at the same time?

AGitHub Actions disables parallel runs by default for workflows using Terraform.
BTerraform automatically queues runs in GitHub Actions to avoid conflicts.
CTerraform state locking via the configured backend (e.g., DynamoDB for S3 backend) prevents concurrent modifications.
DTerraform uses local state files to avoid conflicts in GitHub Actions.
Attempts:
2 left
💡 Hint

Think about how Terraform backends handle concurrency.

Best Practice
expert
2:00remaining
Optimizing Terraform Runs in GitHub Actions for Cost and Speed

You want to optimize your Terraform GitHub Actions workflow to reduce cloud costs and speed up runs. Which approach is the best practice?

ARun 'terraform apply' on every push to any branch without filtering.
BUse 'terraform plan' on pull requests and only run 'terraform apply' on merges to the main branch.
CRun 'terraform apply' manually only, never automate in GitHub Actions.
DRun 'terraform destroy' after every successful apply to clean resources.
Attempts:
2 left
💡 Hint

Consider when to apply changes to avoid unnecessary resource creation.