Skip to content

Commit

Permalink
Update to use labels module and standard tagging. Test cases reworked…
Browse files Browse the repository at this point in the history
… into examples
  • Loading branch information
Steven Nemetz committed May 17, 2018
1 parent be03448 commit 3b1c2ec
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 52 deletions.
Empty file added examples/README.md
Empty file.
1 change: 1 addition & 0 deletions examples/disabled/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Example: Disabled by enabled variable
7 changes: 7 additions & 0 deletions examples/disabled/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "s3" {
source = "../../"
names = ["disabled"]
environment = "${var.environment}"
organization = "${var.organization}"
enabled = false
}
29 changes: 29 additions & 0 deletions examples/disabled/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output "arns" {
description = "List of AWS S3 Bucket ARNs"
value = "${module.s3.arns}"
}

output "domain_names" {
description = "List of AWS S3 Bucket Domain Names"
value = "${module.s3.domain_names}"
}

output "hosted_zone_ids" {
description = "List of AWS S3 Bucket Hosted Zone IDs"
value = "${module.s3.hosted_zone_ids}"
}

output "ids" {
description = "List of AWS S3 Bucket IDs"
value = "${module.s3.ids}"
}

output "names" {
description = "List of AWS S3 Bucket Names"
value = "${module.s3.names}"
}

output "regions" {
description = "List of AWS S3 Bucket Regions"
value = "${module.s3.regions}"
}
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions examples/multiple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Example: Managing multiple S3 buckets
6 changes: 6 additions & 0 deletions examples/multiple/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module "s3" {
source = "../../"
names = ["bucket-1", "bucket2", "bucket_3"]
environment = "${var.environment}"
organization = "${var.organization}"
}
29 changes: 29 additions & 0 deletions examples/multiple/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output "arns" {
description = "List of AWS S3 Bucket ARNs"
value = "${module.s3.arns}"
}

output "domain_names" {
description = "List of AWS S3 Bucket Domain Names"
value = "${module.s3.domain_names}"
}

output "hosted_zone_ids" {
description = "List of AWS S3 Bucket Hosted Zone IDs"
value = "${module.s3.hosted_zone_ids}"
}

output "ids" {
description = "List of AWS S3 Bucket IDs"
value = "${module.s3.ids}"
}

output "names" {
description = "List of AWS S3 Bucket Names"
value = "${module.s3.names}"
}

output "regions" {
description = "List of AWS S3 Bucket Regions"
value = "${module.s3.regions}"
}
3 changes: 3 additions & 0 deletions examples/multiple/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "${var.region}"
}
11 changes: 11 additions & 0 deletions examples/multiple/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "environment" {
default = "dev"
}

variable "organization" {
default = "testorg"
}

variable "region" {
default = "us-west-2"
}
1 change: 1 addition & 0 deletions examples/none/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Example: Disabled by providing an empty list
6 changes: 6 additions & 0 deletions examples/none/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module "s3" {
source = "../../"
names = []
environment = "${var.environment}"
organization = "${var.organization}"
}
29 changes: 29 additions & 0 deletions examples/none/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output "arns" {
description = "List of AWS S3 Bucket ARNs"
value = "${module.s3.arns}"
}

output "domain_names" {
description = "List of AWS S3 Bucket Domain Names"
value = "${module.s3.domain_names}"
}

output "hosted_zone_ids" {
description = "List of AWS S3 Bucket Hosted Zone IDs"
value = "${module.s3.hosted_zone_ids}"
}

output "ids" {
description = "List of AWS S3 Bucket IDs"
value = "${module.s3.ids}"
}

output "names" {
description = "List of AWS S3 Bucket Names"
value = "${module.s3.names}"
}

output "regions" {
description = "List of AWS S3 Bucket Regions"
value = "${module.s3.regions}"
}
3 changes: 3 additions & 0 deletions examples/none/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "${var.region}"
}
11 changes: 11 additions & 0 deletions examples/none/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "environment" {
default = "dev"
}

variable "organization" {
default = "testorg"
}

variable "region" {
default = "us-west-2"
}
1 change: 1 addition & 0 deletions examples/single/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Example: Managing one S3 buckets
6 changes: 6 additions & 0 deletions examples/single/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module "s3" {
source = "../../"
names = ["bucket"]
environment = "${var.environment}"
organization = "${var.organization}"
}
29 changes: 29 additions & 0 deletions examples/single/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output "arns" {
description = "List of AWS S3 Bucket ARNs"
value = "${module.s3.arns}"
}

output "domain_names" {
description = "List of AWS S3 Bucket Domain Names"
value = "${module.s3.domain_names}"
}

output "hosted_zone_ids" {
description = "List of AWS S3 Bucket Hosted Zone IDs"
value = "${module.s3.hosted_zone_ids}"
}

output "ids" {
description = "List of AWS S3 Bucket IDs"
value = "${module.s3.ids}"
}

output "names" {
description = "List of AWS S3 Bucket Names"
value = "${module.s3.names}"
}

output "regions" {
description = "List of AWS S3 Bucket Regions"
value = "${module.s3.regions}"
}
3 changes: 3 additions & 0 deletions examples/single/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "${var.region}"
}
11 changes: 11 additions & 0 deletions examples/single/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "environment" {
default = "dev"
}

variable "organization" {
default = "testorg"
}

variable "region" {
default = "us-west-2"
}
40 changes: 18 additions & 22 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,31 @@ module "enabled" {
value = "${var.enabled}"
}

/*
module "label" {
source = "devops-workflow/label/local"
version = "0.1.3"
organization = "${var.organization}"
name = "${var.name}"
module "labels" {
source = "devops-workflow/labels/null"
version = "0.1.0"
attributes = "${var.attributes}"
component = "${var.component}"
delimiter = "${var.delimiter}"
enabled = "${module.enabled.value}"
environment = "${var.environment}"
monitor = "${var.monitor}"
names = "${var.names}"
namespace-env = "${var.namespace-env}"
namespace-org = "${var.namespace-org}"
environment = "${var.environment}"
delimiter = "${var.delimiter}"
attributes = "${var.attributes}"
organization = "${var.organization}"
owner = "${var.owner}"
product = "${var.product}"
service = "${var.service}"
tags = "${var.tags}"
team = "${var.team}"
}
*/

resource "aws_s3_bucket" "this" {
count = "${module.enabled.value ? length(var.names) : 0}"

bucket = "${var.namespaced ?
format("%s-%s-%s", var.org, var.environment, replace(element(var.names, count.index), "_", "-")) :
format("%s-%s", var.org, replace(element(var.names, count.index), "_", "-"))}"

acl = "${var.public ? "public-read" : "private"}"
bucket = "${module.labels.id[count.index]}"
acl = "${var.public ? "public-read" : "private"}"

versioning {
enabled = "${var.versioned}"
Expand All @@ -69,13 +71,7 @@ resource "aws_s3_bucket" "this" {
#region
#request_payer
#replication_configuration {}
tags = "${ merge(
var.tags,
map("Name", var.namespaced ?
format("%s-%s", var.environment, replace(element(var.names, count.index), "_", "-")) :
format("%s", replace(element(var.names, count.index), "_", "-")) ),
map("Environment", var.environment),
map("Terraform", "true") )}"
tags = "${module.labels.tags[count.index]}"
}

/*
Expand Down
20 changes: 0 additions & 20 deletions test/main.tf

This file was deleted.

77 changes: 67 additions & 10 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,35 +1,92 @@
// Standard Variables
//
// Variables specific to module label
//
variable "attributes" {
description = "Suffix name with additional attributes (policy, role, etc.)"
type = "list"
default = []
}

variable "component" {
description = "TAG: Underlying, dedicated piece of service (Cache, DB, ...)"
type = "string"
default = "UNDEF-S3-Buckets"
}

variable "delimiter" {
description = "Delimiter to be used between `name`, `namespaces`, `attributes`, etc."
type = "string"
default = "-"
}

variable "environment" {
description = "Environment (ex: `dev`, `qa`, `stage`, `prod`). (Second or top level namespace. Depending on namespacing options)"
type = "string"
}

variable "monitor" {
description = "TAG: Should resource be monitored"
type = "string"
default = "UNDEF-S3-Buckets"
}

variable "names" {
description = "List of S3 bucket names"
type = "list"
}

variable "environment" {
description = "Environment (ex: dev, qa, stage, prod)"
variable "namespace-env" {
description = "Prefix name with the environment. If true, format is: <env>-<name>"
default = true
}

variable "namespaced" {
description = "Namespace all resources (prefixed with the environment)?"
variable "namespace-org" {
description = "Prefix name with the organization. If true, format is: <org>-<env namespaced name>. If both env and org namespaces are used, format will be <org>-<env>-<name>"
default = true
}

variable "organization" {
description = "Organization name (Top level namespace)"
type = "string"
default = ""
}

variable "owner" {
description = "TAG: Owner of the service"
type = "string"
default = "UNDEF-S3-Buckets"
}

variable "product" {
description = "TAG: Company/business product"
type = "string"
default = "UNDEF-S3-Buckets"
}

variable "service" {
description = "TAG: Application (microservice) name"
type = "string"
default = "UNDEF-S3-Buckets"
}

variable "tags" {
description = "A map of tags to add to all resources"
description = "A map of additional tags"
type = "map"
default = {}
}

variable "org" {
description = "Organization name to prefix S3 buckets with"
variable "team" {
description = "TAG: Department/team of people responsible for service"
type = "string"
default = "UNDEF-S3-Buckets"
}

// Module specific Variables
variable "enabled" {
description = "Set to false to prevent the module from creating anything"
default = true
}

// Module specific Variables

variable "principal" {
description = "principal"
default = "*"
Expand Down

0 comments on commit 3b1c2ec

Please sign in to comment.