Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
modules/s3-remote-state: Add conditional region variable
Browse files Browse the repository at this point in the history
Added a `variable` to the main.tf file and updated the README accordingly

Fixes: #100

TODO: test this one the dev-sandbox
  • Loading branch information
Aniket Deshpande authored and ketzacoatl committed Aug 22, 2018
1 parent 999b0f6 commit 46e9215
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion modules/s3-remote-state/README.md
Expand Up @@ -50,6 +50,7 @@ Create a `terraform.tfvars`, for example:
```hcl
principals="<arn of principal>"
bucket_name="fpco-tf-remote-state-test"
region="us-east-1"
```

Now it's time to create the `IAM` policies and `S3` bucket using Terraform.
Expand Down Expand Up @@ -175,4 +176,4 @@ If for any reason you no longer need this state and bucket, you can delete it as
2. Manually delete the contents of the `S3` bucket
3. Run `terraform destroy`

[1]: https://www.terraform.io/docs/backends/config.html
[1]: https://www.terraform.io/docs/backends/config.html
12 changes: 11 additions & 1 deletion modules/s3-remote-state/main.tf
Expand Up @@ -4,8 +4,9 @@
* This module creates a private S3 bucket and IAM policy to access that bucket.
* The bucket can be used as a remote storage bucket for `terraform`, `kops`, or
* similar tools.
*
*
*/

variable "bucket_name" {
description = "the name to give the bucket"
}
Expand All @@ -20,14 +21,23 @@ variable "versioning" {
description = "enables versioning for objects in the S3 bucket"
}

variable "region" {
default = ""
description = "Region where the S3 bucket will be created"
type = "string"
}

variable "aws_cloud" {
description = "set to 'aws-us-gov' if using GovCloud, otherwise leave the default"
default = "aws"
}

data "aws_region" "current" {}

resource "aws_s3_bucket" "remote-state" {
bucket = "${var.bucket_name}"
acl = "private"
region = "${var.region == "" ? data.aws_region.current.name : var.region}"

versioning {
enabled = "${var.versioning}"
Expand Down

0 comments on commit 46e9215

Please sign in to comment.