{"id":20179100,"url":"https://github.com/pratikshinde55/terraform-aws-count","last_synced_at":"2026-06-04T22:30:57.156Z","repository":{"id":230562668,"uuid":"779653893","full_name":"Pratikshinde55/terraform-aws-count","owner":"Pratikshinde55","description":"Create multiple EC2 instances and give dynamically name \u0026 instance type using terraform.","archived":false,"fork":false,"pushed_at":"2025-01-06T12:23:22.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-03T05:41:52.160Z","etag":null,"topics":["hcl","infrastucture-as-code","terraform","terraform-aws"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pratikshinde55.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-03-30T12:28:15.000Z","updated_at":"2025-01-07T09:29:28.000Z","dependencies_parsed_at":"2025-01-13T16:49:03.062Z","dependency_job_id":"cf510ab6-e364-45d6-8bb4-3bed41c6088b","html_url":"https://github.com/Pratikshinde55/terraform-aws-count","commit_stats":null,"previous_names":["pratikshinde55/terraform-aws-count_dynamically","pratikshinde55/terraform-aws-count"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Pratikshinde55/terraform-aws-count","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pratikshinde55%2Fterraform-aws-count","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pratikshinde55%2Fterraform-aws-count/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pratikshinde55%2Fterraform-aws-count/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pratikshinde55%2Fterraform-aws-count/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pratikshinde55","download_url":"https://codeload.github.com/Pratikshinde55/terraform-aws-count/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pratikshinde55%2Fterraform-aws-count/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33923173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-04T02:00:06.755Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hcl","infrastucture-as-code","terraform","terraform-aws"],"created_at":"2024-11-14T02:25:07.564Z","updated_at":"2026-06-04T22:30:57.118Z","avatar_url":"https://github.com/Pratikshinde55.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multi-Instance AWS EC2 Deployment with Terraform\nCreate multiple EC2 instance and give dynamically name \u0026 instance type\n\n![terraform-count](https://github.com/Pratikshinde55/Terraform-aws-Count_dynamically/assets/145910708/9d4138a1-8f73-4b97-87b8-cd0049d47f16)\n\n## Count: \nCount is Terraform meta-argument is used in resource block to specify that resource how many times run.count is a meta-argument defined by the Terraform \nlanguage. It can be used with modules and with every resource type.\n\n- Meta-argument: The terraform argument which is used in any resources are known as 'Meta-argument'.\n\n- Count.index: It's special variable which define length of list of count. such as os[0] , os[1], os[2]......\n  \nIn this work i have created below files for my code , mypsfile is created by \"-out\" keyword which store all setup code in binary format.  \n\" # terraform.exe plan -out=mypsfile \"\n\n![files-tf](https://github.com/Pratikshinde55/Terraform-aws-Count_dynamically/assets/145910708/4d156206-a87a-4482-b39e-3c5f682fe4e7)\n\n## Step-1:\nprovider file for plugin and put credentials info .(aws provider plugin)\n\n      notepad provider.tf \n\n![provider- tf](https://github.com/Pratikshinde55/Terraform-aws-Count_dynamically/assets/145910708/9111dd17-6f1b-44d5-8369-91a6735d75ef)\n\n## Step-2:\nHere main.tf file for all code related to aws_instance Resource block.\n\nData Source for AMI: It fetches the latest Amazon Linux 2 AMI with a specific naming convention (al2023-ami-*-x86_64) and other filters.\n\nEC2 Instance Resource: It defines an EC2 instance resource, using the AMI fetched in the previous step. It specifies the instance type, security group ID,\nand creates multiple instances using the count meta-argument.\n\nVariables: \"names\": A list of names for instances, \"instanceType\": A list of instance types, \"sec-grpID\": Security Group ID.\n\nOutput: It outputs a message based on the value of the Give-true-false variable. If it's true, it outputs a welcome message; otherwise, it suggests trying\nagain later.\n\nLocals: It defines some local values, such as admin name, owner, salary, and current time.\n   \n      notepad main.tf \n\n![main tf](https://github.com/Pratikshinde55/Terraform-aws-Count_dynamically/assets/145910708/6299137c-9f52-4559-9d75-8359dbd13481)\n\n\n![vari](https://github.com/Pratikshinde55/Terraform-aws-Count_dynamically/assets/145910708/751ad7b1-e91a-4f84-9f71-5acf83b0b048)\n\nIn terraform 'varible' we can't use terraform function, Because of this \"locals\" is used. (check main.tf file). Output block is required to run local value.\n\nmax(): max function is used to retrieve maximum value .\n\nformatdate(): It's is terraform function which give format for date.\n\ntimestamp(): It's terraform function which run in real time and give real time.\n\n## Step-3:\nNow, 1st use terraform init \u0026 then terraform apply command entire setup is launched, i give true value output is welcome show during apply command run. \u0026 current\ndate and time show .\n     \n      terraform init\n      terraform apply\n\n![terra-apply](https://github.com/Pratikshinde55/Terraform-aws-Count_dynamically/assets/145910708/caa4ea39-d93b-4b7c-a8f4-fed66c6bde34)\n\n\n![apply-output](https://github.com/Pratikshinde55/Terraform-aws-Count_dynamically/assets/145910708/4b4e0be7-bc4c-445d-8b86-9207aee4d47c)\n\n\n## Now check on AWS Console:---\n\n- here all three instances is launched with given instance type as well as instance name .\n\n![Screenshot 2024-03-30 181743](https://github.com/Pratikshinde55/Terraform-aws-Count_dynamically/assets/145910708/4e9a0893-8e40-4fec-8921-1f7d149126ed)\n\n- For each instance bellow security group created by terraform:\n\n- I give security group id in \"vpc_security_group_ids\" argument , the security group is created on aws console manually and only security_group id i give in terraform\n  main block.\n\n![Screenshot 2024-03-30 181902](https://github.com/Pratikshinde55/Terraform-aws-Count_dynamically/assets/145910708/5d9d8328-658c-425c-9c74-3e83f7f5d195)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpratikshinde55%2Fterraform-aws-count","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpratikshinde55%2Fterraform-aws-count","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpratikshinde55%2Fterraform-aws-count/lists"}