https://www.youtube.com/c/AWSLinuxWindows
a. terraform init b. terraform plan c terraform apply
-
terraform destroy -target resource_type.resource_logical_name
-
terraform get -update=true
-
terraform output -module=module-name
4.terraform plan -target=module.cloudgeeks.ca-vpc ---> only plan specific modules or terraform apply -target resource_type.resource_logical_name
Example: terraform.exe apply -target aws_ecs_service.aws-ecs-service-driver-prod
5.terraform apply -target=module.cloudgeeks.ca-vpc ---> only apply specific modules
6.terraform state pull----> ok
7.terraform state push---->danger
8.terraform state rm module.cloudgeeks.ca-rds-app1 ----> https://stackoverflow.com/questions/43950097/how-to-import-manual-changes-into-terraform-remote-state
9.terraform show ---> see after deployment
- terraform state list
#Note: Pull directly from git hub
#https://www.terraform.io/docs/modules/sources.html
- source = "github.com/quickbooks2018/Terraform-Classic-Modules/modules/vpc"
-
ssh-keygen -y -f terraform.pem > terraform.pub
-
terraform apply -var-file=dmz.tfvars
-
terraform destroy -var-file=dmz.tfvars
-
terraform import -var-file=dmz.tfvars module.sg7.aws_security_group.security_group sg-00afc6e255cc55387
-
terraform plan -var-file=secrets.tfvars -var-file=dmz.tfvars -target=module.directory-service -out plan
#############################################################################################################
List the Terraform commands:
terraform Common commands: apply: Builds or changes infrastructure console: Interactive console for Terraform interpolations destroy: Destroys Terraform-managed infrastructure fmt: Rewrites configuration files to canonical format get: Downloads and installs modules for the configuration graph: Creates a visual graph of Terraform resources import: Imports existing infrastructure into Terraform init: Initializes a new or existing Terraform configuration output: Reads an output from a state file plan: Generates and shows an execution plan providers: Prints a tree of the providers used in the configuration push: Uploads this Terraform module to Terraform Enterprise to run refresh: Updates local state file against real resources show: Inspects Terraform state or plan taint: Manually marks a resource for recreation untaint: Manually unmarks a resource as tainted validate: Validates the Terraform files version: Prints the Terraform version workspace: Workspace management
Set up the environment:
mkdir -p terraform/basics cd terraform/basics Create a Terraform script:
vi main.tf main.tf contents:
resource "docker_image" "image_id" { name = "ghost:latest" } Initialize Terraform:
terraform init Validate the Terraform file:
terraform validate List providers in the folder:
ls .terraform/plugins/linux_amd64/ List providers used in the configuration:
terraform providers Terraform Plan:
terraform plan Useful flags for plan: -out=path: Writes a plan file to the given path. This can be used as input to the "apply" command. -var 'foo=bar': Set a variable in the Terraform configuration. This flag can be set multiple times.
Terraform Apply:
terraform apply Useful flags for apply: -auto-approve: This skips interactive approval of plan before applying. -var 'foo=bar': This sets a variable in the Terraform configuration. It can be set multiple times.
Confirm your apply by typing yes. The apply will take a bit to complete.
List the Docker images:
docker image ls Terraform Show:
terraform show Terraform Destroy:
terraform destroy Confirm your destroy by typing yes.
Useful flags for destroys: -auto-approve: Skip interactive approval of plan before applying.
Re-list the Docker images:
docker image ls Using a plan:
terraform plan -out=tfplan Applying a plan:
terraform apply tfplan Show the Docker Image resource:
terraform show Destroy the resource once again:
terraform destroy