Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Configure the AWS variables
variable "aws_region" {
description = "AWS region"
type = string
default = "us-east-1"
}

# Configure the AWS Provider
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
random = {
source = "hashicorp/random"
version = "3.6.3"
}
}
}

# Configure the AWS
provider "aws" {
region = var.aws_region
}

# Create a new s3 bucket
resource "aws_s3_bucket" "s3bucket" {
bucket = "test-bucket-${random_string.bucket_suffix.result}"
force_destroy = true
}

# Generate a random suffix for bucket name
resource "random_string" "bucket_suffix" {
length = 8
special = false
upper = false
}

# Upload file to s3 bucket
resource "aws_s3_object" "bucket-data" {
bucket = aws_s3_bucket.s3bucket.bucket
source = "./myfile.txt"
key = "myfile.txt"
}