{"id":25144028,"url":"https://github.com/kelomo2502/terraform-ec2instane-ami-creation","last_synced_at":"2026-05-07T18:43:35.648Z","repository":{"id":274146147,"uuid":"922055148","full_name":"kelomo2502/terraform-ec2instane-ami-creation","owner":"kelomo2502","description":"This demonstrates the use Terraform to automate the creation of an EC2 instance on AWS and then create an Amazon Machine Image (AMI) from that instance.","archived":false,"fork":false,"pushed_at":"2025-01-29T18:50:51.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T19:38:48.132Z","etag":null,"topics":["aws","hcl","terraform"],"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/kelomo2502.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":"2025-01-25T07:31:55.000Z","updated_at":"2025-01-29T18:50:54.000Z","dependencies_parsed_at":"2025-01-25T08:33:54.433Z","dependency_job_id":null,"html_url":"https://github.com/kelomo2502/terraform-ec2instane-ami-creation","commit_stats":null,"previous_names":["kelomo2502/terraform-ec2instane-ami-creation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelomo2502%2Fterraform-ec2instane-ami-creation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelomo2502%2Fterraform-ec2instane-ami-creation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelomo2502%2Fterraform-ec2instane-ami-creation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelomo2502%2Fterraform-ec2instane-ami-creation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kelomo2502","download_url":"https://codeload.github.com/kelomo2502/terraform-ec2instane-ami-creation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246944384,"owners_count":20858773,"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","hcl","terraform"],"created_at":"2025-02-08T19:36:21.946Z","updated_at":"2026-05-07T18:43:35.642Z","avatar_url":"https://github.com/kelomo2502.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"Terraform EC2 Instance \u0026 AMI Creation\nPurpose\nThis project demonstrates the use of Terraform to automate the launch of an EC2 instance on AWS, including key pair generation and the execution of a user data script to install and configure Apache HTTP server.\n\nObjectives\nTerraform Configuration: Write Terraform code to launch an EC2 instance.\nKeypair Generation: Generate a key pair using aws tls_private_key.\nUser Data Execution: Execute user data to install Apache HTTP server.\nGetting Started\nPrerequisites\nTerraform installed\nAWS account with proper permissions\nAWS CLI configured\nFiles Overview\nmain.tf: Terraform configuration for EC2 instance, key pair, and user data.\nvariables.tf: Variables for instance type, availability zone, etc.\nCode Snippets\nKey Pair Generation\nresource \"tls_private_key\" \"key_pair\" {\n  algorithm = \"RSA\"\n  rsa_bits  = 2048\n}\n\nresource \"aws_key_pair\" \"gb_key\" {\n  key_name   = \"gb_key\"\n  public_key = tls_private_key.key_pair.public_key_openssh\n}\n\nresource \"local_file\" \"private_key\" {\n  filename = \"gb_key.pem\"\n  content  = tls_private_key.key_pair.private_key_pem\n\n  provisioner \"local-exec\" {\n    command = \"chmod 400 gb_key.pem\"\n  }\n}\n\nresource \"local_file\" \"public_key\" {\n  filename = \"gb_key.pem\"\n  content  = tls_private_key.key_pair.public_key_pem\n\n  provisioner \"local-exec\" {\n    command = \"chmod 400 gb_key.pem\"\n  }\n}\n\nEC2 Instance with Apache HTTP Setup\nresource \"aws_instance\" \"web\" {\n  ami                    = data.aws_ami.amazon_linux.id\n  instance_type          = var.instance_type\n  key_name               = aws_key_pair.gb_key.key_name\n  vpc_security_group_ids = [aws_security_group.gb_sg.id]\n  availability_zone      = var.availability_zone\n  count                  = var.number_of_instances\n\n  tags = {\n    Name = var.ec2_instance_name\n  }\n\n  user_data = \u003c\u003c-EOF\n                #!/bin/bash\n                yum update -y\n                yum install -y httpd\n                systemctl start httpd\n                systemctl enable httpd\n                echo \"\u003ch1\u003eHello World from $(hostname -f)\u003c/h1\u003e\" \u003e /var/www/html/index.html\n                EOF\n}\n\noutput \"instance_public_ip_addr\" {\n  value = [for instance in aws_instance.web : instance.public_ip]\n}\n\nSteps to Deploy\nClone the repository.\n\nRun terraform init to initialize the Terraform configuration.\n\nApply the configuration with terraform apply.\n\nAccess the Apache HTTP server using the EC2 instance's public IP.\n\nConclusion\nThis project demonstrates the automation of launching EC2 instances with Terraform, including key pair management and configuring Apache HTTP server using a user data script.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelomo2502%2Fterraform-ec2instane-ami-creation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkelomo2502%2Fterraform-ec2instane-ami-creation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelomo2502%2Fterraform-ec2instane-ami-creation/lists"}