This Terraform configuration sets up the necessary AWS resources for a feed worker instance, including its associated security group, subnet, and AMI creation from the instance, utilizing provided default values for quick setup.
- An AWS account
- Terraform installed on your machine
- An existing VPC (unless you're using the default provided)
- An existing security group (unless you're using the default provided)
-
AWS Instance (
feed_worker): An EC2 instance based on the specified base AMI, instance type, and subnet. It's configured to install AWS CLI and Docker upon initialization. Additional user data scripts are used for setup. -
AWS AMI (
feed_worker_ami): A new AMI created from the EC2 instance, intended for subsequent use in scaling or replication. The AMI includes the AWS CLI and Docker, installed during the EC2 instance's initialization. -
AWS Subnet (
private_subnet): A private subnet within the specified VPC, tailored for the feed worker instances. -
AWS Security Group (
private_sg): A security group with configured inbound and outbound rules. It allows inbound traffic from an existing security group and all outbound traffic.
-
Initialize your Terraform workspace with the command
terraform init, which will download the necessary plugins and modules. -
Plan your deployment with
terraform planto see the resources that will be created. -
Apply your configuration with
terraform apply. Confirm the action to proceed with the resource creation.
This configuration uses the following variables with default values:
aws_region: The AWS region where resources will be created. Default is"eu-central-1"(Frankfurt).availability_zone: The availability zone for the subnet. Default is"eu-central-1a".base_ami: The base AMI ID for the EC2 instance. Default is a Canonical Ubuntu 22.04 LTS image.user_name: The username for the EC2 instance. Default is"ubuntu".instance_type: The type of EC2 instance to deploy. Default is"t2.micro".vpc_id: The ID of the VPC for the security group and subnet. Default is a specific VPC ID.subnet_id: The ID of the subnet where the EC2 instance will reside. Default is a specific subnet ID.existing_security_group_name: The name of the existing security group for inbound rules. Default is a specific security group ID.
After applying the Terraform configuration, the following outputs will be available:
ami_id: The ID of the newly created AMI.instance_id: The ID of the created EC2 instance.subnet_id: The ID of the created subnet.security_group_id: The ID of the created security group.
- Ensure your AWS credentials are correctly set up, either through the AWS CLI or environment variables.
- Review and modify the security group rules according to your organization's security policies.
- You can override any default variable value by creating a
terraform.tfvarsfile or passing them directly via the command line.