From 8652f7e12402404d2679dd096a7f7297d774111b Mon Sep 17 00:00:00 2001 From: leej3 Date: Wed, 31 Jul 2024 17:43:39 +0100 Subject: [PATCH] fix, set up bucket and dynamodb separately --- .gitignore | 2 ++ web_api/deploy.sh | 4 ++-- web_api/terraform/main.tf | 34 +++------------------------------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 178dc41f..b30efa29 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ venv/ .vscode/settings.json .DS_Store osm_output +.terraform +.terraform.lock.hcl diff --git a/web_api/deploy.sh b/web_api/deploy.sh index aead6969..ee3da14e 100755 --- a/web_api/deploy.sh +++ b/web_api/deploy.sh @@ -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 @@ -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 diff --git a/web_api/terraform/main.tf b/web_api/terraform/main.tf index 3bcbe46e..f8bb83d2 100644 --- a/web_api/terraform/main.tf +++ b/web_api/terraform/main.tf @@ -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 @@ -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" } @@ -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" } @@ -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" @@ -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 }