diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/disabled/README.md b/examples/disabled/README.md new file mode 100644 index 0000000..0fddb95 --- /dev/null +++ b/examples/disabled/README.md @@ -0,0 +1 @@ +# Example: Disabled by enabled variable diff --git a/examples/disabled/main.tf b/examples/disabled/main.tf new file mode 100644 index 0000000..5976a93 --- /dev/null +++ b/examples/disabled/main.tf @@ -0,0 +1,7 @@ +module "s3" { + source = "../../" + names = ["disabled"] + environment = "${var.environment}" + organization = "${var.organization}" + enabled = false +} diff --git a/examples/disabled/outputs.tf b/examples/disabled/outputs.tf new file mode 100644 index 0000000..70b5e47 --- /dev/null +++ b/examples/disabled/outputs.tf @@ -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}" +} diff --git a/test/provider.tf b/examples/disabled/provider.tf similarity index 100% rename from test/provider.tf rename to examples/disabled/provider.tf diff --git a/test/variables.tf b/examples/disabled/variables.tf similarity index 100% rename from test/variables.tf rename to examples/disabled/variables.tf diff --git a/examples/multiple/README.md b/examples/multiple/README.md new file mode 100644 index 0000000..740400b --- /dev/null +++ b/examples/multiple/README.md @@ -0,0 +1 @@ +# Example: Managing multiple S3 buckets diff --git a/examples/multiple/main.tf b/examples/multiple/main.tf new file mode 100644 index 0000000..a32278c --- /dev/null +++ b/examples/multiple/main.tf @@ -0,0 +1,6 @@ +module "s3" { + source = "../../" + names = ["bucket-1", "bucket2", "bucket_3"] + environment = "${var.environment}" + organization = "${var.organization}" +} diff --git a/examples/multiple/outputs.tf b/examples/multiple/outputs.tf new file mode 100644 index 0000000..70b5e47 --- /dev/null +++ b/examples/multiple/outputs.tf @@ -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}" +} diff --git a/examples/multiple/provider.tf b/examples/multiple/provider.tf new file mode 100644 index 0000000..0977ba5 --- /dev/null +++ b/examples/multiple/provider.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "${var.region}" +} diff --git a/examples/multiple/variables.tf b/examples/multiple/variables.tf new file mode 100644 index 0000000..1433c5b --- /dev/null +++ b/examples/multiple/variables.tf @@ -0,0 +1,11 @@ +variable "environment" { + default = "dev" +} + +variable "organization" { + default = "testorg" +} + +variable "region" { + default = "us-west-2" +} diff --git a/examples/none/README.md b/examples/none/README.md new file mode 100644 index 0000000..e760978 --- /dev/null +++ b/examples/none/README.md @@ -0,0 +1 @@ +# Example: Disabled by providing an empty list diff --git a/examples/none/main.tf b/examples/none/main.tf new file mode 100644 index 0000000..64b84bb --- /dev/null +++ b/examples/none/main.tf @@ -0,0 +1,6 @@ +module "s3" { + source = "../../" + names = [] + environment = "${var.environment}" + organization = "${var.organization}" +} diff --git a/examples/none/outputs.tf b/examples/none/outputs.tf new file mode 100644 index 0000000..70b5e47 --- /dev/null +++ b/examples/none/outputs.tf @@ -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}" +} diff --git a/examples/none/provider.tf b/examples/none/provider.tf new file mode 100644 index 0000000..0977ba5 --- /dev/null +++ b/examples/none/provider.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "${var.region}" +} diff --git a/examples/none/variables.tf b/examples/none/variables.tf new file mode 100644 index 0000000..1433c5b --- /dev/null +++ b/examples/none/variables.tf @@ -0,0 +1,11 @@ +variable "environment" { + default = "dev" +} + +variable "organization" { + default = "testorg" +} + +variable "region" { + default = "us-west-2" +} diff --git a/examples/single/README.md b/examples/single/README.md new file mode 100644 index 0000000..445a0eb --- /dev/null +++ b/examples/single/README.md @@ -0,0 +1 @@ +# Example: Managing one S3 buckets diff --git a/examples/single/main.tf b/examples/single/main.tf new file mode 100644 index 0000000..e9ca7ad --- /dev/null +++ b/examples/single/main.tf @@ -0,0 +1,6 @@ +module "s3" { + source = "../../" + names = ["bucket"] + environment = "${var.environment}" + organization = "${var.organization}" +} diff --git a/examples/single/outputs.tf b/examples/single/outputs.tf new file mode 100644 index 0000000..70b5e47 --- /dev/null +++ b/examples/single/outputs.tf @@ -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}" +} diff --git a/examples/single/provider.tf b/examples/single/provider.tf new file mode 100644 index 0000000..0977ba5 --- /dev/null +++ b/examples/single/provider.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "${var.region}" +} diff --git a/examples/single/variables.tf b/examples/single/variables.tf new file mode 100644 index 0000000..1433c5b --- /dev/null +++ b/examples/single/variables.tf @@ -0,0 +1,11 @@ +variable "environment" { + default = "dev" +} + +variable "organization" { + default = "testorg" +} + +variable "region" { + default = "us-west-2" +} diff --git a/main.tf b/main.tf index 1dbfd17..429b18a 100644 --- a/main.tf +++ b/main.tf @@ -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}" @@ -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]}" } /* diff --git a/test/main.tf b/test/main.tf deleted file mode 100644 index 60ad2d5..0000000 --- a/test/main.tf +++ /dev/null @@ -1,20 +0,0 @@ -module "s3-none" { - source = ".." - names = [] - environment = "${var.environment}" - org = "${var.organization}" -} - -module "s3-single" { - source = ".." - names = ["bucket"] - environment = "${var.environment}" - org = "${var.organization}" -} - -module "s3-multi" { - source = ".." - names = ["bucket-1", "bucket2", "bucket_3"] - environment = "${var.environment}" - org = "${var.organization}" -} diff --git a/variables.tf b/variables.tf index a3f368c..57481db 100644 --- a/variables.tf +++ b/variables.tf @@ -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: -" + 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: -. If both env and org namespaces are used, format will be --" 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 = "*"