/terraform

terraform practical tasks for hashicorp certified associate003

Primary LanguageHCL

  1. Every Task in this repository has individual README.md file, along with Task numbers that has details on how to execute each task with commands.

  2. Before you begin with Terraform, understand what is Infrastructure as a code: https://aws.amazon.com/what-is/iac/

  3. Terraform Installation: https://developer.hashicorp.com/terraform/tutorials/aws-get-started?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS

  4. Terraform Tutorials: https://developer.hashicorp.com/terraform/tutorials/certification-associate-tutorials-003

  5. Terraform Exam Registration :https://developer.hashicorp.com/certifications/infrastructure-automation

Terraform workflow

Write code
Init
Plan        #we called it either dry run or blueprint
Apply
  1. ####TERRAFORM COMMANDS and options Usage: terraform [global options] [args]

7a) The available commands for execution are listed below. The primary workflow commands are given first, followed by less common or more advanced commands.

7b) Main commands: init Prepare your working directory for other commands validate Check whether the configuration is valid plan Show changes required by the current configuration apply Create or update infrastructure destroy Destroy previously-created infrastructure

7c) All other commands: console Try Terraform expressions at an interactive command prompt fmt Reformat your configuration in the standard style force-unlock Release a stuck lock on the current workspace get Install or upgrade remote Terraform modules graph Generate a Graphviz graph of the steps in an operation import Associate existing infrastructure with a Terraform resource login Obtain and save credentials for a remote host logout Remove locally-stored credentials for a remote host metadata Metadata related commands output Show output values from your root module providers Show the providers required for this configuration refresh Update the state to match remote systems show Show the current state or a saved plan state Advanced state management taint Mark a resource instance as not fully functional test Experimental support for module integration testing untaint Remove the 'tainted' state from a resource instance version Show the current Terraform version workspace Workspace management

7d) Global options (use these before the subcommand, if any): -chdir=DIR Switch to a different working directory before executing the given subcommand. -help Show this help output, or the help for a specified subcommand. -version An alias for the "version" subcommand.

  1. TERRAFORM STATE subcommands:

8a) This command has subcommands for advanced state management.

8b) These subcommands can be used to slice and dice the Terraform state. This is sometimes necessary in advanced cases. For your safety, all state management commands that modify the state create a timestamped backup of the state prior to making modifications.

8c) The structure and output of the commands is specifically tailored to work well with the common Unix utilities such as grep, awk, etc. We recommend using those tools to perform more advanced state tasks

8d)Subcommands: list List resources in the state mv Move an item in the state pull Pull current state and output to stdout push Update remote state from a local state file replace-provider Replace provider in the state rm Remove instances from the state show Show a resource in the state

  1. IMPORTANT: TERRAFORM INIT Subcommands:

9a) Usage: terraform [global options] init [options]

9b) Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.

9c) This is the first command that should be run for any new or existing Terraform configuration per machine. This sets up all the local data necessary to run Terraform that is typically not committed to version control.

9d) This command is always safe to run multiple times. Though subsequent runs may give errors, this command will never delete your configuration or state. Even so, if you have important information, please back it up prior to running this command, just in case.

9e) Options:

-backend=false Disable backend or Terraform Cloud initialization for this configuration and use what was previously initialized instead.

                      aliases: -cloud=false

-backend-config=path Configuration to be merged with what is in the configuration file's 'backend' block. This can be either a path to an HCL file with key/value assignments (same format as terraform.tfvars) or a 'key=value' format, and can be specified multiple times. The backend type must be in the configuration itself.

-force-copy Suppress prompts about copying state data when initializating a new state backend. This is equivalent to providing a "yes" to all confirmation prompts.

-from-module=SOURCE Copy the contents of the given module into the target directory before initialization.

-get=false Disable downloading modules for this configuration.

-input=false Disable interactive prompts. Note that some actions may require interactive prompts and will error if input is disabled.

-lock=false Don't hold a state lock during backend migration. This is dangerous if others might concurrently run commands against the same workspace.

-lock-timeout=0s Duration to retry a state lock.

-no-color If specified, output won't contain any color.

-plugin-dir Directory containing plugin binaries. This overrides all default search paths for plugins, and prevents the automatic installation of plugins. This flag can be used multiple times.

-reconfigure Reconfigure a backend, ignoring any saved configuration.

-migrate-state Reconfigure a backend, and attempt to migrate any existing state.

-upgrade Install the latest module and provider versions allowed within configured constraints, overriding the default behavior of selecting exactly the version recorded in the dependency lockfile.

-lockfile=MODE Set a dependency lockfile mode. Currently only "readonly" is valid.

-ignore-remote-version A rare option used for Terraform Cloud and the remote backend only. Set this to ignore checking that the local and remote Terraform versions use compatible state representations, making an operation proceed even when there is a potential mismatch. See the documentation on configuring Terraform with Terraform Cloud for more information.