This Terraform project allows you to provision AWS resources, including EC2 instances and security groups, in your chosen AWS region. It's designed to be easily configurable for different environments.
Before using this Terraform configuration, make sure you have the following prerequisites:
- Terraform installed locally.
- AWS credentials with appropriate permissions configured either via environment variables, AWS CLI configuration, or other secure methods.
-
Clone this repository to your local machine.
-
Customize the Terraform variables by creating a
terraform.tfvars
file in the project directory. You can use theterraform.tfvars.example
file as a template. -
Modify the
terraform.tfvars
file with your own values for AWS region, instance type, security group rules, etc.
The user data script user_data.sh
included in this project is executed on each EC2 instance during provisioning. It performs the following actions:
- Installs K3s - A lightweight Kubernetes distribution.
- Initializes a K3s cluster on the instance.
- Sets the
KUBECONFIG
environment variable to point to the cluster configuration file.
You can customize the user_data.sh
script as needed for your specific setup.
-
Initialize the Terraform working directory:
terraform init
-
View the execution plan to ensure that the changes will be made as expected:
terraform plan
-
Apply the configuration to create AWS resources:
terraform apply
-
When you're finished, you can destroy the created resources:
terraform destroy
-
variables.tf
: Defines the variables used in this configuration. -
main.tf
: Specifies the AWS resources to be provisioned, such as EC2 instances and security groups. -
user_data.sh
: A Bash script that is executed on each EC2 instance during provisioning.
The .gitignore
file is configured to exclude sensitive files like terraform.tfvars
from version control.
Do not upload sensitive information, such as AWS access keys or secret keys, to public repositories. Use environment variables or a secrets management system to securely provide credentials to Terraform.