August 10, 2018

Terraform commands

Terraform Command Line Interface (Terraform CLI)

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

Common commands:

    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    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 new or existing Terraform configuration
    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
    push               Upload this Terraform module to Terraform Enterprise to run
    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:

    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

terraform -version
terraform taint -help

terraform init # will install provider plugins
terraform init -upgrade commands_exec/
terraform get

terraform plan
terraform plan -out=demo.tfplan
terraform plan --destroy -out destroy-plan
terraform apply
terraform apply demo.tfplan
terraform apply -var 'zones=["us-east-1b", "us-east-1d"]'
terraform apply -var-file=sample.tfvars
terraform destroy
terraform destroy -target=aws_security_group.elb_sg

terraform workspace list
terraform workspace new dev
terraform workspace select
$ terraform import aws_instance.example i-abcd1234 # import existing infrastructure
$ terraform import aws_key_pair.deployer deployer-key
terraform import aws_vpc.web_vpc vpc-25b7495d

terraform refresh
terraform show # to show the attributes in the state file
terraform state list
terraform state show aws_vpc.web_vpc
terraform graph

terraform output
terraform output ips_var
terraform output -module=network
site_address=$(terraform output site_address)
web_server_ip=$(terraform output -module=vm | cut -d " " -f 3)

terraform console
echo "2 + 8" | terraform console
terraform providers
terraform fmt
terraform fmt -check
terraform validate # performs syntax checks

Related Articles:

1 comment:

  1. Best, Live RPA Online Training In USA,Hyderabad | Online RPA Training In USA, Hyderabad
    Click Here Best RPA Online Training to go to RPA Online Training Institute Details.

    ReplyDelete