diff --git a/main.tf b/main.tf index 42d3e21..db14146 100644 --- a/main.tf +++ b/main.tf @@ -12,10 +12,10 @@ resource "aws_s3_bucket" "default" { # - Bucket names must not contain uppercase characters or underscores. # - Bucket names must start with a lowercase letter or number. # https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html#bucketnamingrules - bucket = "${var.name}" + bucket = var.name # The AWS region this bucket should reside in. Otherwise, the region used by the callee. - region = "${local.bucket_region}" + region = local.bucket_region # S3 access control lists (ACLs) enable you to manage access to buckets and objects. # https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html @@ -24,7 +24,7 @@ resource "aws_s3_bucket" "default" { # Server access logging provides detailed records for the requests that are made to a bucket. # https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerLogs.html logging { - target_bucket = "${var.logging_target_bucket}" + target_bucket = var.logging_target_bucket target_prefix = "logs/${var.name}/" } @@ -35,7 +35,7 @@ resource "aws_s3_bucket" "default" { # You can, however, suspend versioning on that bucket. # https://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html versioning { - enabled = "${var.versioning_enabled}" + enabled = var.versioning_enabled } # S3 encrypts your data at the object level as it writes it to disks in its data centers @@ -55,20 +55,20 @@ resource "aws_s3_bucket" "default" { # To manage your objects so that they are stored cost effectively throughout their lifecycle, configure their lifecycle. # https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html lifecycle_rule { - enabled = "${var.lifecycle_rule_enabled}" - prefix = "${var.lifecycle_rule_prefix}" + enabled = var.lifecycle_rule_enabled + prefix = var.lifecycle_rule_prefix # The STANDARD_IA and ONEZONE_IA storage classes are designed for long-lived and infrequently accessed data. # https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html#sc-infreq-data-access transition { - days = "${var.standard_ia_transition_days}" + days = var.standard_ia_transition_days storage_class = "STANDARD_IA" } # The GLACIER storage class is suitable for archiving data where data access is infrequent. # https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html#sc-glacier transition { - days = "${var.glacier_transition_days}" + days = var.glacier_transition_days storage_class = "GLACIER" } @@ -79,36 +79,36 @@ resource "aws_s3_bucket" "default" { # S3 removes the expired object delete marker. # https://docs.aws.amazon.com/AmazonS3/latest/dev/intro-lifecycle-rules.html expiration { - days = "${var.expiration_days}" + days = var.expiration_days } # Specifies when noncurrent objects transition to a specified storage class. # https://docs.aws.amazon.com/AmazonS3/latest/dev/intro-lifecycle-rules.html#intro-lifecycle-rules-actions noncurrent_version_transition { - days = "${var.glacier_noncurrent_version_transition_days}" + days = var.glacier_noncurrent_version_transition_days storage_class = "GLACIER" } # Specifies when noncurrent object versions expire. # https://docs.aws.amazon.com/AmazonS3/latest/dev/intro-lifecycle-rules.html#intro-lifecycle-rules-actions noncurrent_version_expiration { - days = "${var.noncurrent_version_expiration_days}" + days = var.noncurrent_version_expiration_days } } # A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. # These objects are not recoverable. # https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#force_destroy - force_destroy = "${var.force_destroy}" + force_destroy = var.force_destroy # A mapping of tags to assign to the bucket. - tags = "${var.tags}" + tags = var.tags } # https://www.terraform.io/docs/providers/aws/r/s3_bucket_policy.html resource "aws_s3_bucket_policy" "default" { - bucket = "${aws_s3_bucket.default.id}" - policy = "${data.aws_iam_policy_document.default.json}" + bucket = aws_s3_bucket.default.id + policy = data.aws_iam_policy_document.default.json } # https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-logging-bucket-permissions @@ -118,7 +118,7 @@ data "aws_iam_policy_document" "default" { principals { type = "AWS" - identifiers = ["${data.aws_elb_service_account.default.arn}"] + identifiers = [data.aws_elb_service_account.default.arn] } actions = [ @@ -139,5 +139,5 @@ data "aws_elb_service_account" "default" {} data "aws_region" "current" {} locals { - bucket_region = "${var.region == "" ? data.aws_region.current.name : var.region}" + bucket_region = var.region == "" ? data.aws_region.current.name : var.region } diff --git a/outputs.tf b/outputs.tf index 14c35ad..19ad73e 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,24 +1,24 @@ output "s3_bucket_id" { - value = "${aws_s3_bucket.default.id}" + value = aws_s3_bucket.default.id description = "The name of the bucket." } output "s3_bucket_arn" { - value = "${aws_s3_bucket.default.arn}" + value = aws_s3_bucket.default.arn description = "The ARN of the bucket. Will be of format arn:aws:s3:::bucketname." } output "s3_bucket_domain_name" { - value = "${aws_s3_bucket.default.bucket_domain_name}" + value = aws_s3_bucket.default.bucket_domain_name description = "The bucket domain name. Will be of format bucketname.s3.amazonaws.com." } output "s3_bucket_hosted_zone_id" { - value = "${aws_s3_bucket.default.hosted_zone_id}" + value = aws_s3_bucket.default.hosted_zone_id description = "The Route 53 Hosted Zone ID for this bucket's region." } output "s3_bucket_region" { - value = "${aws_s3_bucket.default.region}" + value = aws_s3_bucket.default.region description = "The AWS region this bucket resides in." } diff --git a/variables.tf b/variables.tf index 493a567..e7903c6 100644 --- a/variables.tf +++ b/variables.tf @@ -1,75 +1,75 @@ variable "name" { - type = "string" + type = string description = "The name of the bucket, which must comply with DNS naming conventions." } variable "logging_target_bucket" { - type = "string" + type = string description = "The name of the bucket that will receive the log objects." } variable "versioning_enabled" { default = true - type = "string" + type = string description = "Enable versioning. Versioning is a means of keeping multiple variants of an object in the same bucket." } variable "lifecycle_rule_enabled" { default = true - type = "string" + type = string description = "Specifies lifecycle rule status." } variable "lifecycle_rule_prefix" { default = "" - type = "string" + type = string description = "Object key prefix identifying one or more objects to which the rule applies." } variable "standard_ia_transition_days" { default = "30" - type = "string" + type = string description = "Specifies a period in the object's STANDARD_IA transitions." } variable "glacier_transition_days" { default = "60" - type = "string" + type = string description = "Specifies a period in the object's Glacier transitions." } variable "expiration_days" { default = "90" - type = "string" + type = string description = "Specifies a period in the object's expire." } variable "glacier_noncurrent_version_transition_days" { default = "30" - type = "string" + type = string description = "Specifies when noncurrent object versions transitions." } variable "noncurrent_version_expiration_days" { default = "60" - type = "string" + type = string description = "Specifies when noncurrent object versions expire." } variable "force_destroy" { default = false - type = "string" + type = string description = "A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error." } variable "tags" { - type = "map" + type = map(string) default = {} description = "A mapping of tags to assign to the bucket." } variable "region" { - type = "string" + type = string description = "(Optional) If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee." default = "" } diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..d9b6f79 --- /dev/null +++ b/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.12" +}