Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-hashicorp authored Jan 26, 2024
0 parents commit d696e63
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.DS_Store

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc

# ignore lock files
*.lock.hcl


# ingore backend file
backend.tf
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# terraform-aws-s3-test

S3 bucket code for proof of concepts in Terraform cloud.

## Instructions

* Rename `terraform.auto.tfvars.example` to `terraform.auto.tfvars` and fill in the values.
* Fill in your Organization name and your workspace name in the `main.tf` file
27 changes: 27 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
terraform {
# cloud {
# # Change this to your organization name
# organization = "billgrant"

# workspaces {
# # change this to your workspace name
# name = "ravi-cli"
# }
# }
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}

provider "aws" {
region = var.aws_region
}

resource "aws_s3_bucket" "example" {
tags = {
Name = var.name
Environment = var.environment
}
}
9 changes: 9 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "bucket_id" {
value = aws_s3_bucket.example.id
description = "The ID of the S3 bucket"
}

output "bucket_arn" {
value = aws_s3_bucket.example.arn
description = "The ARN of the S3 bucket"
}
3 changes: 3 additions & 0 deletions terraform.auto.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Rename this file to terraform.auto.tfvars and fill in the values.
name = "name-tag"
environment = "environment-tag"
36 changes: 36 additions & 0 deletions tests/main.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# WARNING: Generated module tests should be considered experimental and be reviewed by the module author.

variables {
aws_region = "us-east-1"
name = "test-bucket"
environment = "test-env"
}

run "resource_validation" {
assert {
condition = aws_s3_bucket.example.tags.Name == "test-bucket"
error_message = "incorrect bucket name"
}

assert {
condition = aws_s3_bucket.example.tags.Environment == "test-env"
error_message = "incorrect environment"
}
}

run "variables_validation" {
assert {
condition = var.aws_region == "us-east-1"
error_message = "incorrect AWS region"
}

assert {
condition = var.name == "test-bucket"
error_message = "incorrect bucket name"
}

assert {
condition = var.environment == "test-env"
error_message = "incorrect environment"
}
}
15 changes: 15 additions & 0 deletions tests/outputs.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# WARNING: Generated module tests should be considered experimental and be reviewed by the module author.

run "outputs_validation" {
assert {
condition = output.bucket_id != ""
error_message = "bucket_id should not be empty"
}

assert {
condition = output.bucket_arn != ""
error_message = "bucket_arn should not be empty"
}
}

# Please note that these tests are generated and should be reviewed by the module author to ensure they are testing the correct conditions.
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
variable "aws_region" {
default = "us-east-1"
description = "AWS region to deploy resources."
}

variable "name" {
description = "Name of the S3 bucket."
}

variable "environment" {
description = "Environment to deploy resources."
}

0 comments on commit d696e63

Please sign in to comment.