Terraform: Difference between revisions

From 탱이의 잡동사니
Jump to navigation Jump to search
Line 54: Line 54:
The '.tf' files in your working directory when you run 'terraform plan' or 'terraform apply' together form the root module. That module may call other modules and connect them together by passing output values from one to input values of another.
The '.tf' files in your working directory when you run 'terraform plan' or 'terraform apply' together form the root module. That module may call other modules and connect them together by passing output values from one to input values of another.


=== Strcuture ===
=== Structure ===
* Input variables to accept values from the calling module.
* Input variables to accept values from the calling module.
* Output variables to return results to the calling module, which it can then use to populate arguments elsewhere.
* Output variables to return results to the calling module, which it can then use to populate arguments elsewhere.

Revision as of 10:00, 20 May 2020

Overview

Terraform 내용 정리.

CLI

Usage: terraform [-version] [-help] <command> [args]

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    0.12upgrade        Rewrites pre-0.12 module source code for v0.12
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    push               Obsolete command for Terraform Enterprise legacy (v1)
    state              Advanced state management


Configurations

Syntax

Provider

provider "google" {
  credentials = "${file("account.json")}"
  project     = "my-project-id"
  region      = "us-central1"
}

Module

A module is a container for multiple resources that are used together. Modules can be used to create lightweight abstractions, so that you can describe your infrastructure in terms of its architecture, rather than directly in terms of physical objects.

The '.tf' files in your working directory when you run 'terraform plan' or 'terraform apply' together form the root module. That module may call other modules and connect them together by passing output values from one to input values of another.

Structure

  • Input variables to accept values from the calling module.
  • Output variables to return results to the calling module, which it can then use to populate arguments elsewhere.
  • Resources to define one or more infrastructure objects that the module will manage.

To define a module, create a new directory for it and place one or more .tf files inside just as the user would do for a root module. Terraform can load modules either from local relative paths or from remote repositories; if a module will be re-used by lots of configurations you may wish to place it in its own version control repository.

Modules can also call other modules using a module block, but the recommendation is keeping the module tree relatively flat and using module composition as an alternative to a deelpy-nested tree of modules, because this makes the individual modules easier to re-use in different combinations.

See also