👨‍💻
Mike's Notes
  • Introduction
  • MacOs Setup
    • System Preferences
    • Homebrew
      • Usage
    • iTerm
      • VIM
      • Tree
      • ZSH
    • Visual Studio Code
    • Git
    • SSH Keys
  • DevOps Knowledge
    • SRE
      • Scaling Reliably
        • Splitting a Monolith into Microservices
      • Troubleshooting Common Issues
      • Service Level Terminology
      • Toil
      • Monitoring
      • Release Engineering
      • Best Practices
      • On-Call
      • Alerting
    • Containers
      • Docker
        • Best Practices
          • Image Building
          • Docker Development
        • CLI Cheat Sheet
      • Container Orchestration
        • Kubernetes
          • Benefits
          • Cheat Sheet
          • Components
          • Pods
          • Workload Resources
          • Best Practices
    • Developer Portal 👨‍💻
      • Solution Overview 🎯
      • System Architecture 🏗️
      • Implementation Journey 🛠️
      • Cross-team Collaboration 🤝
      • Lessons & Future 🎓
    • Provisioning
      • Terraform
        • Installation
        • Usage
    • Configuration Management
      • Ansible
        • Benefits
        • Installation
    • Build Systems
      • Bazel
        • Features
  • Security
    • Secure Software Engineering
    • Core Concepts
    • Security Design Principles
    • Software Security Requirements
    • Compliance Standards and Policies
      • Sarbanes-Oxley (SOX)
      • HIPAA and HITECH
      • Payment Card Industry Data Security Standard (PCI-DSS)
      • General Data Protection Regulation (GDPR)
      • California Consumer Privacy Act (CCPA)
      • Federal Risk and Authorization Management Program (FedRAMP)
    • Privacy & Data
  • Linux Fundamentals
    • Introduction to Linux
    • Architecture
    • Server Administration
      • User / Groups
      • File Permissions
      • SSH
      • Process Management
    • Networking
      • Diagrams
      • Browser URL Example
      • Network Topologies
      • Signal Routing
      • DNS (Domain Name System)
      • SSL (Secure Sockets Layer)
      • TLS (Transport Layer Security)
  • System Design
    • Process
    • Kafka
      • Advanced Topics
    • URL Shortener
Powered by GitBook
On this page
  • init
  • validate
  • get
  • plan
  • apply
  • destroy

Was this helpful?

  1. DevOps Knowledge
  2. Provisioning
  3. Terraform

Usage

PreviousInstallationNextConfiguration Management

Last updated 3 years ago

Was this helpful?

terraform init

It’s
 the
 first
 command
 you
 need
 to
 execute.
 Otherwise,
 terraform plan,
 apply,
 destroy
 and
 import
 will
 not
 work. It is safe to run this command multiple times.


The
 command will

:

  • find terraform
 modules based on source provided

  • configure and validate 
a
 backend (if present)

  • install provider(s) 
plugins

terraform validate

Once you’ve initialized the directory, it’s a good idea to run thevalidate command before you run plan or apply. Validation catches syntax errors, version errors and more.

It is safe to run this command automatically, for example as a post-save check in a text editor or as a test step for a re-usable module in a CI system.

This
 command
 is
 useful
 when you have
 some
 modules defined.


terraform get
­

The modules are downloaded into a .terraform subdirectory of the current working directory. Don't commit this directory to your version control repository.

update=true - If specified, modules that are already downloaded will be checked for updates and the updates will be downloaded if present.

The
 plan
 command creates an execution plan which allows previewing changes. Like a dry run, it won't actually apply any of the proposed changes.


terraform
 plan
­

By default, when Terraform creates a plan it:

  • Reads the current state of any already-existing remote objects to make sure that the Terraform state is up-to-date.

  • Compares the current configuration to the prior state and noting any differences.

  • Proposes a set of change actions that should, if applied, make the remote objects match the configuration.

Next comes the apply command which will execute the actions proposed in the plan.

terraform apply

-auto-approve - Skips interactive approval of plan before applying. This option is ignored when you pass a previously-saved plan file, because Terraform considers you passing the plan file as the approval and so will never prompt in that case.

Apply only one resource

terraform
 apply -target="module.s3"

terraform 
destroy

This command deletes all the resources in the configuration.

A
 deletion 
plan
 can
 be 
created
 before execution:


terraform 
plan 
–destroy

Deletions can take a target resource too.

terraform 
destroy -
­target="
aws_s3_bucket.my_bucket"

init
validate
get
plan
apply
destroy