Skip to content

Commit

Permalink
fix, set up bucket and dynamodb separately
Browse files Browse the repository at this point in the history
  • Loading branch information
leej3 committed Jul 31, 2024
1 parent 888a5e7 commit 8652f7e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ venv/
.vscode/settings.json
.DS_Store
osm_output
.terraform
.terraform.lock.hcl
4 changes: 2 additions & 2 deletions web_api/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ echo $DOCKER_HUB_ACCESS_TOKEN | docker login --username $DOCKER_HUB_USERNAME --p

# Build and push Docker image
echo "Building and pushing Docker image..."
DOCKER_BUILDKIT=1 docker build -t $DOCKER_IMAGE_TAG -f ./web_api/docker_images/web_api/Dockerfile .
DOCKER_BUILDKIT=1 docker build -t $DOCKER_IMAGE_TAG -f ./web_api/Dockerfile .
docker push $DOCKER_IMAGE_TAG

# Set up Terraform
Expand All @@ -32,7 +32,7 @@ pushd web_api/terraform

# Initialize Terraform
echo "Initializing Terraform..."
tofu init -reconfigure -backend-config="./backend-config-${ENVIRONMENT}.tf"
tofu init -reconfigure


# Plan Terraform changes
Expand Down
34 changes: 3 additions & 31 deletions web_api/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
provider "aws" {
region = var.aws_region
region = "us-east-1"
}

terraform {
backend "s3" {
bucket = "osm-storage"
bucket = "osm-terraform-storage"
key = "terraform/staging/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
}
}


# Data source to find the latest Ubuntu AMI
data "aws_ami" "ubuntu" {
most_recent = true
Expand All @@ -25,7 +24,6 @@ data "aws_ami" "ubuntu" {
# VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"

tags = {
Name = "${var.environment}-vpc"
}
Expand All @@ -36,7 +34,6 @@ resource "aws_subnet" "main" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"

tags = {
Name = "${var.environment}-subnet"
}
Expand Down Expand Up @@ -78,7 +75,7 @@ resource "aws_instance" "app" {
instance_type = var.instance_type
subnet_id = aws_subnet.main.id
key_name = "dsst2023"
security_groups = [aws_security_group.app.id]
security_groups = [aws_security_group.app.name]

tags = {
Name = "${var.environment}-instance"
Expand All @@ -93,31 +90,6 @@ resource "aws_instance" "app" {
EOF
}

# S3 Bucket for Terraform State
resource "aws_s3_bucket" "terraform_state" {
bucket = var.s3_bucket
tags = {
Name = "${var.environment}-terraform-state"
}
}

# DynamoDB Table for Terraform State Locking
resource "aws_dynamodb_table" "terraform_locks" {
name = var.dynamodb_table
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"

attribute {
name = "LockID"
type = "S"
}

tags = {
Name = "${var.environment}-terraform-locks"
}
}

# Outputs
output "instance_id" {
value = aws_instance.app.id
}
Expand Down

0 comments on commit 8652f7e

Please sign in to comment.