{"id":15155657,"url":"https://github.com/atulkamble/terraform-cheat-sheet-","last_synced_at":"2025-03-01T00:36:29.004Z","repository":{"id":139085741,"uuid":"375118450","full_name":"atulkamble/terraform-cheat-sheet-","owner":"atulkamble","description":"Terraform Commands Cheatsheet © 2021","archived":false,"fork":false,"pushed_at":"2022-06-07T12:47:52.000Z","size":25,"stargazers_count":5,"open_issues_count":0,"forks_count":16,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-22T05:13:20.692Z","etag":null,"topics":["aws","azure","cheatsheet","cloud","cloudnative","gcp","hashicorp","hashicorp-terraform","terraform"],"latest_commit_sha":null,"homepage":"https://atulkamble.github.io/Terraform-Cheat-Sheet/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atulkamble.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"atulkamble","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-06-08T19:11:05.000Z","updated_at":"2024-09-25T22:18:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"cdc3fcf9-e964-4732-9f70-8062c1d499f8","html_url":"https://github.com/atulkamble/terraform-cheat-sheet-","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"2fb5b04cce62355de70528d9892d583d225e802b"},"previous_names":["atulkamble/terraform-cheat-sheet-"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fterraform-cheat-sheet-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fterraform-cheat-sheet-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fterraform-cheat-sheet-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fterraform-cheat-sheet-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atulkamble","download_url":"https://codeload.github.com/atulkamble/terraform-cheat-sheet-/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241292674,"owners_count":19939654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","azure","cheatsheet","cloud","cloudnative","gcp","hashicorp","hashicorp-terraform","terraform"],"created_at":"2024-09-26T18:41:48.597Z","updated_at":"2025-03-01T00:36:28.984Z","avatar_url":"https://github.com/atulkamble.png","language":null,"funding_links":["https://github.com/sponsors/atulkamble"],"categories":[],"sub_categories":[],"readme":"### Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.\n\n# [Terraform-Commands-Cheatsheet](https://atulkamble.github.io/Terraform-Commands-Cheatsheet/)\nNo need to run in terror from Terraform. Close that search engine tab and check out ultimate Terraform Cheatsheet by [Atul Kamble](https://atulkamble.github.io/).\n\n# Terraform Command Lines\n\n- Terraform CLI tricks\n```markdown terraform -install-autocomplete``` #Setup tab auto-completion, requires logging back in\n\n### Format and Validate Terraform code\n- ```terraform fmt``` #format code per HCL canonical standard\n- ```terraform validate``` #validate code for syntax\n- ```terraform validate -backend=false``` #validate code skip backend validation\n\n### Initialize your Terraform working directory\n- ```terraform init``` #initialize directory, pull down providers\n- ```terraform init -get-plugins=false``` #initialize directory, do not download plugins\n- ```terraform init -verify-plugins=false``` #initialize directory, do not verify plugins for Hashicorp signature\n\n### Plan, Deploy and Cleanup Infrastructure\n- ```terraform apply --auto-approve``` #apply changes without being prompted to enter “yes”\n- ```terraform destroy --auto-approve``` #destroy/cleanup deployment without being prompted for “yes”\n- ```terraform plan -out plan.out``` #output the deployment plan to plan.out\n- ```terraform apply plan.out``` #use the plan.out plan file to deploy infrastructure\n- ```terraform plan -destroy``` #outputs a destroy plan\n- ```terraform apply -target=aws_instance.my_ec2``` #only apply/deploy changes to the targeted resource\n- ```terraform apply -var my_region_variable=us-east-1``` #pass a variable via command-line while applying a configuration\n- ```terraform apply -lock=true``` #lock the state file so it can’t be modified by any other Terraform apply or modification action(possible only where backend allows locking)\n- ```terraform apply refresh=false``` # do not reconcile state file with real-world resources(helpful with large complex deployments for saving deployment time)\n- ```terraform apply --parallelism=5``` #number of simultaneous resource operations\n- ```terraform refresh``` #reconcile the state in Terraform state file with real-world resources\n- ```terraform providers``` #get information about providers used in current configuration\n\n### Terraform Workspaces\n- ```terraform workspace new mynewworkspace``` #create a new workspace\n- ```terraform workspace select default``` #change to the selected workspace\n- ```terraform workspace list``` #list out all workspaces\n\n### Terraform State Manipulation\n\n- ```terraform state show aws_instance.my_ec2``` #show details stored in Terraform state for the resource\n- ```terraform state pull \u003e terraform.tfstate``` #download and output terraform state to a file\n- ```terraform state mv aws_iam_role.my_ssm_role module.custom_module``` #move a resource tracked via state to different module\n- ```terraform state replace-provider hashicorp/aws registry.custom.com/aws``` #replace an existing provider with another\n- ```terraform state list``` #list out all the resources tracked via the current state file\n- ```terraform state rm  aws_instance.myinstace``` #unmanage a resource, delete it from Terraform state file\n\n### Terraform Import And Outputs\n- ```terraform import aws_instance.new_ec2_instance i-abcd1234``` #import EC2 instance with id i-abcd1234 into the Terraform resource named “new_ec2_instance” of type “aws_instance”\n- ```terraform import 'aws_instance.new_ec2_instance[0]' i-abcd1234``` #same as above, imports a real-world resource into an instance of Terraform resource\n- ```terraform output``` #list all outputs as stated in code\n- ```terraform output instance_public_ip``` # list out a specific declared output\n- ```terraform output -json``` #list all outputs in JSON format\n\n### Terraform Miscelleneous commands\n- ```terraform version``` #display Terraform binary version, also warns if version is old\n- ```terraform get -update=true``` #download and update modules in the “root” module.\n\n### Terraform Console(Test out Terraform interpolations)\n- ```echo 'join(\",\",[\"foo\",\"bar\"])' | terraform console``` #echo an expression into terraform console and see its expected result as output\n- ```echo '1 + 5' | terraform console``` #Terraform console also has an interactive CLI just enter “terraform console”\n- ```echo \"aws_instance.my_ec2.public_ip\" | terraform console``` #display the Public IP against the “my_ec2” Terraform resource as seen in the Terraform state file\n\n### Terraform Graph(Dependency Graphing)\n- ```terraform graph | dot -Tpng \u003e graph.png``` #produce a PNG diagrams showing relationship and dependencies between Terraform resource in your configuration/code\n\n### Terraform Taint/Untaint(mark/unmark resource for recreation -\u003e delete and then recreate)\n- ```terraform taint aws_instance.my_ec2``` #taints resource to be recreated on next apply\n- ```terraform untaint aws_instance.my_ec2``` #Remove taint from a resource\n- ```terraform force-unlock LOCK_ID``` #forcefully unlock a locked state file, LOCK_ID provided when locking the State file beforehand\n\n### Terraform Cloud\n- ```terraform login``` #obtain and save API token for Terraform cloud\n- ```terraform logout``` #Log out of Terraform Cloud, defaults to hostname app.terraform.io\n\n\n# Technical Author Profile (Study Guide + Notes):\n- [LinkedIn: atuljkamble](https://www.linkedin.com/in/atuljkamble) \n- [Twitter: atul_kamble](https://www.twitter.com/atul_kamble)\n- [Github: atulkamble](https://www.github.com/atulkamble)\n- [Medium: atuljkamble](https://atuljkamble.medium.com/)\n- [HashNode: atulkamble](https://hashnode.com/@atulkamble)\n- [Dev: atulkamble](https://dev.to/atulkamble)\n- [Twitch: atulkamble](https://www.twitch.tv/atulkamble)\n- [Kaggle: atuljkamble](https://www.kaggle.com/atuljkamble)\n- [GitLab: atulkamble](https://gitlab.com/atulkamble)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatulkamble%2Fterraform-cheat-sheet-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatulkamble%2Fterraform-cheat-sheet-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatulkamble%2Fterraform-cheat-sheet-/lists"}