diff --git a/.gitignore b/.gitignore index 65eca7a..3d95f7d 100755 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ network_images/*.tar.xz .vscode/settings.json .vscode ansible/clab_vars.yml +terraform/backend.conf diff --git a/README.md b/README.md index 7c971d7..d01caaf 100755 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Before you begin, ensure you have the following prerequisites installed and conf ```bash cd terraform - terraform init + terraform init --backend-config="backend.conf" ``` 4. **Apply Terraform Configuration** diff --git a/terraform/README.md b/terraform/README.md index 290d2ef..993da9f 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -10,22 +10,27 @@ This directory contains the Terraform configuration files for deploying an AWS E ## Configuration -1. **Set AWS Credentials and Variables** +1. **Backend Configuration** - Rename the `terraform.tfvars.sample` to `terraform.tfvars` and update the following variables with your own values: + To easily manage the backend configuration, we will store the tfstate files on an S3 bucket. + To update it, please adapt the `backend.conf` file, using the provided sample as a reference. - ```tfvars - AWS_ACCESS_KEY = "your_access_key" - AWS_SECRET_KEY = "your_secret_key" - AWS_KEY_NAME = "your_key_pair_name" - AWS_KEY_LOCATION = "path_to_your_private_key" - ``` +2. **Set AWS Credentials and Variables** + + Rename the `terraform.tfvars.sample` to `terraform.tfvars` and update the following variables with your own values: + + ```tfvars + AWS_ACCESS_KEY = "your_access_key" + AWS_SECRET_KEY = "your_secret_key" + AWS_KEY_NAME = "your_key_pair_name" + AWS_KEY_LOCATION = "path_to_your_private_key" + ``` **Important** : Never commit `terraform.tfvars` to version control as it contains sensitive information. -2. **Customize Terraform Variables** +3. **Customize Terraform Variables** - You can customize the deployment by modifying the Terraform variables in `variables.tf`. + You can customize the deployment by modifying the Terraform variables in `variables.tf`. ## Action made by the EC2.tf file diff --git a/terraform/backend.conf.sample b/terraform/backend.conf.sample new file mode 100644 index 0000000..159a7f8 --- /dev/null +++ b/terraform/backend.conf.sample @@ -0,0 +1,3 @@ +bucket = "YOUR_UNIQUE_BUCKET_NAME" +key = "YOUR_OBJECT_KEY" +region = "YOUR_REGION" \ No newline at end of file diff --git a/terraform/ec2.tf b/terraform/ec2.tf index 04c4df3..0c2781f 100755 --- a/terraform/ec2.tf +++ b/terraform/ec2.tf @@ -1,9 +1,3 @@ -provider "aws" { - region = var.AWS_REGION - access_key = var.AWS_ACCESS_KEY - secret_key = var.AWS_SECRET_KEY -} - resource "aws_security_group" "netlab_sg" { name = "netlab_sg" diff --git a/terraform/provider.tf b/terraform/provider.tf new file mode 100644 index 0000000..04bb798 --- /dev/null +++ b/terraform/provider.tf @@ -0,0 +1,9 @@ +provider "aws" { + region = var.AWS_REGION + access_key = var.AWS_ACCESS_KEY + secret_key = var.AWS_SECRET_KEY +} + +terraform { + backend "s3" {} +} \ No newline at end of file