Skip to content

Commit

Permalink
tf file configs
Browse files Browse the repository at this point in the history
  • Loading branch information
rogers7levi committed Oct 18, 2024
1 parent 30c2b4e commit c0ef10f
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
41 changes: 41 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
README.md
# Core Infrastructure

This directory contains Terraform configurations for the core infrastructure components of our
project. These are foundational elements that other parts of our infrastructure rely upon.

## Overview

The `core` directory manages the following resources:

- **AWS S3 Bucket** for Terraform state storage: Ensures that our Terraform state is stored
securely and is accessible across our team for state management.
- **DynamoDB Table** for Terraform state locking: Prevents concurrent operations from
corrupting the state.

## Structure

- `s3.tf`: Contains the configuration for the S3 bucket used for state storage.
- `dynamodb.tf`: Defines the DynamoDB table used for locking the Terraform state during
modifications.
- `providers.tf`: Sets up provider configurations and specifies the required versions.
- `variables.tf`: Declares variables used across multiple configurations within the core
infrastructure.

## Usage

To deploy or modify the core infrastructure, follow these steps:

1. **Initialization**:
Navigate to the `core` directory and run:

`terraform init`

This will prepare your directory for Terraform operations, setting up the backend and initializing
provider plugins.

2. **Planning**:
To see what changes Terraform plans to make to your infrastructure based on the current
configurations, run:

`terraform plan`

3. **Applying Changes**:
To apply the changes proposed in the plan, run:

`terraform apply`

Always review the plan before applying it to prevent unintended changes.

## Best Practices

- **Review changes**: Always review the output of `terraform plan` before applying changes.
- **Keep secrets secure**: Never hard-code sensitive information. Use environment variables
and secrets management practices.
- **Version control**: Keep all changes in version control and review changes through pull
requests.

## Contributing

Contributions to the core infrastructure should follow the company's guidelines on
infrastructure changes, including approval and review processes.

---

For more detailed information on each resource, refer to the individual `.tf` files within this
directory.

14 changes: 14 additions & 0 deletions dynamodb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "aws_dynamodb_table" "terraform_lock" {
name = var.dynamodb_table_name
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}

tags = {
Name = "Terraform State Lock"
}
}

14 changes: 14 additions & 0 deletions providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
provider "aws" {
region = var.region
}
#s3 provider
terraform {

required_providers {
aws = {
source = "hashicorp/aws"
version = "4.31.0"
}

}
}
36 changes: 36 additions & 0 deletions s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resource "aws_s3_bucket" "terraform_state_for_intro" {
bucket = "s3-backend-${random_string.unique_suffix.result}"
acl = "private"

versioning {
enabled = true
}

server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}

lifecycle {
prevent_destroy = true
}

lifecycle_rule {
id = "delete_old_versions"
enabled = true

noncurrent_version_expiration {
days = 30
}
}
}

resource "random_string" "unique_suffix" {
length = 7
special = false
upper = false

}
7 changes: 7 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "region" {
default = "eu-west-2"
}

variable "dynamodb_table_name" {
default = "project-name-terraform-state-lock"
}

0 comments on commit c0ef10f

Please sign in to comment.