From 444f9566f211a394eef2a750636c09fc832b2d12 Mon Sep 17 00:00:00 2001 From: Adam Crews Date: Mon, 6 Jan 2020 07:35:33 -0800 Subject: [PATCH] Use the latest label module to support the environment attribute (#19) --- README.md | 141 ++++++++++++++++++++++++++++++---------------- docs/terraform.md | 13 +++-- main.tf | 31 +++++----- variables.tf | 29 ++++++---- 4 files changed, 133 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index 969967ee..4af484c2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,43 @@ - + [![README Header][readme_header_img]][readme_header_link] [![Cloud Posse][logo]](https://cpco.io/homepage) @@ -88,21 +127,22 @@ Available targets: | allow_encrypted_uploads_only | Set to `true` to prevent uploads of unencrypted objects to S3 bucket | bool | `false` | no | | allowed_bucket_actions | List of actions the user is permitted to perform on the S3 bucket | list(string) | `` | no | | attributes | Additional attributes (e.g. `1`) | list(string) | `` | no | -| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no | -| enabled | Set to `false` to prevent the module from creating any resources | bool | `true` | no | +| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no | +| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no | +| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `` | no | | force_destroy | A boolean string that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable | bool | `false` | no | | kms_master_key_arn | The AWS KMS master key ARN used for the `SSE-KMS` encryption. This can only be used when you set the value of `sse_algorithm` as `aws:kms`. The default aws/s3 AWS KMS master key is used if this element is absent while the `sse_algorithm` is `aws:kms` | string | `` | no | | lifecycle_rule_enabled | Enable or disable lifecycle rule | bool | `false` | no | -| name | Name (e.g. `app` or `cluster`) | string | - | yes | -| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no | +| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no | +| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no | | noncurrent_version_expiration_days | Specifies when noncurrent object versions expire | number | `90` | no | | noncurrent_version_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier infrequent access tier | number | `30` | no | | policy | A valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy | string | `` | no | | prefix | Prefix identifying one or more objects to which the rule applies | string | `` | no | | region | If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee | string | `` | no | | sse_algorithm | The server-side encryption algorithm to use. Valid values are `AES256` and `aws:kms` | string | `AES256` | no | -| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no | -| tags | Additional tags (e.g. `{ BusinessUnit = "XYZ" }` | map(string) | `` | no | +| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no | +| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map(string) | `` | no | | user_enabled | Set to `true` to create an IAM user with permission to access the bucket | bool | `false` | no | | versioning_enabled | A state of versioning. Versioning is a means of keeping multiple variants of an object in the same bucket | bool | `false` | no | @@ -146,34 +186,33 @@ Check out these related projects. ## Help -**Got a question?** +**Got a question?** We got answers. File a GitHub [issue](https://github.com/cloudposse/terraform-aws-s3-bucket/issues), send us an [email][email] or join our [Slack Community][slack]. [![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link] -## Commercial Support - -Work directly with our team of DevOps experts via email, slack, and video conferencing. - -We provide [*commercial support*][commercial_support] for all of our [Open Source][github] projects. As a *Dedicated Support* customer, you have access to our team of subject matter experts at a fraction of the cost of a full-time engineer. +## DevOps Accelerator for Startups -[![E-Mail](https://img.shields.io/badge/email-hello@cloudposse.com-blue.svg)][email] -- **Questions.** We'll use a Shared Slack channel between your team and ours. -- **Troubleshooting.** We'll help you triage why things aren't working. -- **Code Reviews.** We'll review your Pull Requests and provide constructive feedback. -- **Bug Fixes.** We'll rapidly work to fix any bugs in our projects. -- **Build New Terraform Modules.** We'll [develop original modules][module_development] to provision infrastructure. -- **Cloud Architecture.** We'll assist with your cloud strategy and design. -- **Implementation.** We'll provide hands-on support to implement our reference architectures. +We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us. +[![Learn More](https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge)][commercial_support] +Work directly with our team of DevOps experts via email, slack, and video conferencing. -## Terraform Module Development - -Are you interested in custom Terraform module development? Submit your inquiry using [our form][module_development] today and we'll get back to you ASAP. +We deliver 10x the value for a fraction of the cost of a full-time engineer. Our track record is not even funny. If you want things done right and you need it done FAST, then we're your best bet. +- **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code. +- **Release Engineering.** You'll have end-to-end CI/CD with unlimited staging environments. +- **Site Reliability Engineering.** You'll have total visibility into your apps and microservices. +- **Security Baseline.** You'll have built-in governance with accountability and audit logs for all changes. +- **GitOps.** You'll be able to operate your infrastructure via Pull Requests. +- **Training.** You'll receive hands-on training so your team can operate what we build. +- **Questions.** You'll have a direct line of communication between our teams via a Shared Slack channel. +- **Troubleshooting.** You'll get help to triage when things aren't working. +- **Code Reviews.** You'll receive constructive feedback on Pull Requests. +- **Bug Fixes.** We'll rapidly work with you to fix any bugs in our projects. ## Slack Community @@ -181,7 +220,13 @@ Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Ou ## Newsletter -Signup for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover. +Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover. + +## Office Hours + +[Join us every Wednesday via Zoom][office_hours] for our weekly "Lunch & Learn" sessions. It's **FREE** for everyone! + +[![zoom](https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png")][office_hours] ## Contributing @@ -206,7 +251,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. ## Copyright -Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright) +Copyright © 2017-2020 [Cloud Posse, LLC](https://cpco.io/copyright) @@ -273,33 +318,31 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply [joshmyers_homepage]: https://github.com/joshmyers [joshmyers_avatar]: https://img.cloudposse.com/150x150/https://github.com/joshmyers.png - - [![README Footer][readme_footer_img]][readme_footer_link] [![Beacon][beacon]][website] [logo]: https://cloudposse.com/logo-300x69.svg - [docs]: https://cpco.io/docs - [website]: https://cpco.io/homepage - [github]: https://cpco.io/github - [jobs]: https://cpco.io/jobs - [hire]: https://cpco.io/hire - [slack]: https://cpco.io/slack - [linkedin]: https://cpco.io/linkedin - [twitter]: https://cpco.io/twitter - [testimonial]: https://cpco.io/leave-testimonial - [newsletter]: https://cpco.io/newsletter - [email]: https://cpco.io/email - [commercial_support]: https://cpco.io/commercial-support - [we_love_open_source]: https://cpco.io/we-love-open-source - [module_development]: https://cpco.io/module-development - [terraform_modules]: https://cpco.io/terraform-modules - [readme_header_img]: https://cloudposse.com/readme/header/img?repo=cloudposse/terraform-aws-s3-bucket - [readme_header_link]: https://cloudposse.com/readme/header/link?repo=cloudposse/terraform-aws-s3-bucket - [readme_footer_img]: https://cloudposse.com/readme/footer/img?repo=cloudposse/terraform-aws-s3-bucket - [readme_footer_link]: https://cloudposse.com/readme/footer/link?repo=cloudposse/terraform-aws-s3-bucket - [readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img?repo=cloudposse/terraform-aws-s3-bucket - [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?repo=cloudposse/terraform-aws-s3-bucket + [docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=docs + [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=website + [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=github + [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=jobs + [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=hire + [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=slack + [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=linkedin + [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=twitter + [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=testimonial + [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=office_hours + [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=newsletter + [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=email + [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=commercial_support + [we_love_open_source]: https://cpco.io/we-love-open-source?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=we_love_open_source + [terraform_modules]: https://cpco.io/terraform-modules?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=terraform_modules + [readme_header_img]: https://cloudposse.com/readme/header/img + [readme_header_link]: https://cloudposse.com/readme/header/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=readme_header_link + [readme_footer_img]: https://cloudposse.com/readme/footer/img + [readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=readme_footer_link + [readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img + [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=readme_commercial_support_link [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-aws-s3-bucket&url=https://github.com/cloudposse/terraform-aws-s3-bucket [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-aws-s3-bucket&url=https://github.com/cloudposse/terraform-aws-s3-bucket [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-aws-s3-bucket diff --git a/docs/terraform.md b/docs/terraform.md index cf3cfc2d..f9c8d080 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -6,21 +6,22 @@ | allow_encrypted_uploads_only | Set to `true` to prevent uploads of unencrypted objects to S3 bucket | bool | `false` | no | | allowed_bucket_actions | List of actions the user is permitted to perform on the S3 bucket | list(string) | `` | no | | attributes | Additional attributes (e.g. `1`) | list(string) | `` | no | -| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no | -| enabled | Set to `false` to prevent the module from creating any resources | bool | `true` | no | +| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no | +| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no | +| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `` | no | | force_destroy | A boolean string that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable | bool | `false` | no | | kms_master_key_arn | The AWS KMS master key ARN used for the `SSE-KMS` encryption. This can only be used when you set the value of `sse_algorithm` as `aws:kms`. The default aws/s3 AWS KMS master key is used if this element is absent while the `sse_algorithm` is `aws:kms` | string | `` | no | | lifecycle_rule_enabled | Enable or disable lifecycle rule | bool | `false` | no | -| name | Name (e.g. `app` or `cluster`) | string | - | yes | -| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no | +| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no | +| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no | | noncurrent_version_expiration_days | Specifies when noncurrent object versions expire | number | `90` | no | | noncurrent_version_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier infrequent access tier | number | `30` | no | | policy | A valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy | string | `` | no | | prefix | Prefix identifying one or more objects to which the rule applies | string | `` | no | | region | If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee | string | `` | no | | sse_algorithm | The server-side encryption algorithm to use. Valid values are `AES256` and `aws:kms` | string | `AES256` | no | -| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no | -| tags | Additional tags (e.g. `{ BusinessUnit = "XYZ" }` | map(string) | `` | no | +| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no | +| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map(string) | `` | no | | user_enabled | Set to `true` to create an IAM user with permission to access the bucket | bool | `false` | no | | versioning_enabled | A state of versioning. Versioning is a means of keeping multiple variants of an object in the same bucket | bool | `false` | no | diff --git a/main.tf b/main.tf index abf874a5..061d9d9d 100644 --- a/main.tf +++ b/main.tf @@ -1,17 +1,18 @@ -module "default_label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.1" - enabled = var.enabled - namespace = var.namespace - stage = var.stage - name = var.name - delimiter = var.delimiter - attributes = var.attributes - tags = var.tags +module "label" { + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0" + enabled = var.enabled + namespace = var.namespace + environment = var.environment + stage = var.stage + name = var.name + delimiter = var.delimiter + attributes = var.attributes + tags = var.tags } resource "aws_s3_bucket" "default" { count = var.enabled ? 1 : 0 - bucket = module.default_label.id + bucket = module.label.id acl = var.acl region = var.region force_destroy = var.force_destroy @@ -22,10 +23,10 @@ resource "aws_s3_bucket" "default" { } lifecycle_rule { - id = module.default_label.id + id = module.label.id enabled = var.lifecycle_rule_enabled prefix = var.prefix - tags = module.default_label.tags + tags = module.label.tags noncurrent_version_transition { days = var.noncurrent_version_transition_days @@ -37,7 +38,6 @@ resource "aws_s3_bucket" "default" { } } - # https://docs.aws.amazon.com/AmazonS3/latest/dev/bucket-encryption.html # https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#enable-default-server-side-encryption server_side_encryption_configuration { @@ -49,13 +49,14 @@ resource "aws_s3_bucket" "default" { } } - tags = module.default_label.tags + tags = module.label.tags } module "s3_user" { - source = "git::https://github.com/cloudposse/terraform-aws-iam-s3-user.git?ref=tags/0.4.0" + source = "git::https://github.com/cloudposse/terraform-aws-iam-s3-user.git?ref=tags/0.5.0" namespace = var.namespace stage = var.stage + environment = var.environment name = var.name attributes = var.attributes tags = var.tags diff --git a/variables.tf b/variables.tf index 914747c0..eb7b705e 100644 --- a/variables.tf +++ b/variables.tf @@ -1,24 +1,37 @@ variable "namespace" { type = string - description = "Namespace (e.g. `eg` or `cp`)" default = "" + description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'" +} + +variable "environment" { + type = string + default = "" + description = "Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT'" } variable "stage" { type = string - description = "Stage (e.g. `prod`, `dev`, `staging`)" default = "" + description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'" } variable "name" { type = string - description = "Name (e.g. `app` or `cluster`)" + default = "" + description = "Solution name, e.g. 'app' or 'jenkins'" +} + +variable "enabled" { + type = bool + default = true + description = "Set to false to prevent the module from creating any resources" } variable "delimiter" { type = string default = "-" - description = "Delimiter to be used between `namespace`, `stage`, `name` and `attributes`" + description = "Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`" } variable "attributes" { @@ -30,7 +43,7 @@ variable "attributes" { variable "tags" { type = map(string) default = {} - description = "Additional tags (e.g. `{ BusinessUnit = \"XYZ\" }`" + description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`" } variable "acl" { @@ -75,12 +88,6 @@ variable "kms_master_key_arn" { description = "The AWS KMS master key ARN used for the `SSE-KMS` encryption. This can only be used when you set the value of `sse_algorithm` as `aws:kms`. The default aws/s3 AWS KMS master key is used if this element is absent while the `sse_algorithm` is `aws:kms`" } -variable "enabled" { - type = bool - default = true - description = "Set to `false` to prevent the module from creating any resources" -} - variable "user_enabled" { type = bool default = false