From b9b79ce1eef93ecd28b09037813d629d1ac990e1 Mon Sep 17 00:00:00 2001 From: "Stephen J. Lawrence Jr" Date: Thu, 29 Nov 2018 11:55:33 -0800 Subject: [PATCH] Add environemt_variables to module (#36) * Add environemt_variables to module * Cleanup and docs built --- README.md | 116 ++++++++++++++++++++++++++++++++++++---------- README.yaml | 15 +++++- docs/targets.md | 3 +- docs/terraform.md | 3 +- main.tf | 33 ++++++------- variables.tf | 11 +++++ 6 files changed, 137 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 30e97ab..704f276 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ +[![README Header][readme_header_img]][readme_header_link] -[![Cloud Posse](https://cloudposse.com/logo-300x69.svg)](https://cloudposse.com) +[![Cloud Posse][logo]](https://cpco.io/homepage) # terraform-aws-cicd [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-cicd.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-cicd) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-cicd.svg)](https://github.com/cloudposse/terraform-aws-cicd/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) @@ -32,7 +33,17 @@ To activate this mode, don't specify the ``app`` and ``env`` attributes for the --- -This project is part of our comprehensive ["SweetOps"](https://docs.cloudposse.com) approach towards DevOps. +This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps. +[][share_email] +[][share_googleplus] +[][share_facebook] +[][share_reddit] +[][share_linkedin] +[][share_twitter] + + +[![Terraform Open Source Modules](https://docs.cloudposse.com/images/terraform-open-source-modules.svg)][terraform_modules] + It's 100% Open Source and licensed under the [APACHE2](LICENSE). @@ -43,6 +54,11 @@ It's 100% Open Source and licensed under the [APACHE2](LICENSE). +We literally have [*hundreds of terraform modules*][terraform_modules] that are Open Source and well-maintained. Check them out! + + + + @@ -84,6 +100,19 @@ module "build" { aws_account_id = "xxxxxxxxxx" image_repo_name = "ecr-repo-name" image_tag = "latest" + # Optional extra environment variables + environment_variables = [{ + name = "JENKINS_URL" + value = "https://jenkins.example.com" + }, + { + name = "COMPANY_NAME" + value = "Amazon" + }, + { + name = "TIME_ZONE" + value = "Pacific/Auckland" + }] } ``` @@ -177,8 +206,9 @@ CMD [ "npm", "start" ] ``` Available targets: - help This help screen + help Help screen help/all Display help for all targets + help/short This help short screen lint Lint terraform code ``` @@ -198,12 +228,13 @@ Available targets: | delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no | | enabled | Enable ``CodePipeline`` creation | string | `true` | no | | env | Elastic Beanstalk environment name. If not provided or set to empty string, the ``Deploy`` stage of the pipeline will not be created | string | `` | no | +| environment_variables | A list of maps, that contain both the key 'name' and the key 'value' to be used as additional environment variables for the build. | list | `` | no | | github_oauth_token | GitHub Oauth Token with permissions to access private repositories | string | - | yes | | image_repo_name | ECR repository name to store the Docker image built by this module. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | `UNSET` | no | | image_tag | Docker image tag in the ECR repository, e.g. 'latest'. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | `latest` | no | | name | Solution name, e.g. 'app' or 'jenkins' | string | `app` | no | | namespace | Namespace, which could be your organization name, e.g. 'cp' or 'cloudposse' | string | `global` | no | -| poll_source_changes | Periodically check the location of your source content and run the pipeline if changes are detected | string | `false` | no | +| poll_source_changes | Periodically check the location of your source content and run the pipeline if changes are detected | string | `true` | no | | privileged_mode | If set to true, enables running the Docker daemon inside a Docker container on the CodeBuild instance. Used when building Docker images | string | `false` | no | | repo_name | GitHub repository name of the application to be built (and deployed to Elastic Beanstalk if configured) | string | - | yes | | repo_owner | GitHub Organization or Person name | string | - | yes | @@ -219,26 +250,38 @@ Available targets: File a GitHub [issue](https://github.com/cloudposse/terraform-aws-cicd/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. -[![E-Mail](https://img.shields.io/badge/email-hello@cloudposse.com-blue.svg)](mailto:hello@cloudposse.com) +[![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 to provision infrastructure. +- **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. -## Community Forum -Get access to our [Open Source Community Forum][slack] on Slack. It's **FREE** to join for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build *sweet* infrastructure. +## 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. + + +## Slack Community + +Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure. + +## 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. ## Contributing @@ -248,7 +291,7 @@ Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-cicd/ ### Developing -If you are interested in being a contributor and want to get involved in developing this project or [help out](https://github.com/orgs/cloudposse/projects/3) with our other projects, we would love to hear from you! Shoot us an [email](mailto:hello@cloudposse.com). +If you are interested in being a contributor and want to get involved in developing this project or [help out](https://cpco.io/help-out) with our other projects, we would love to hear from you! Shoot us an [email][email]. In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. @@ -263,7 +306,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. ## Copyright -Copyright © 2017-2018 [Cloud Posse, LLC](https://cloudposse.com) +Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright) @@ -304,26 +347,16 @@ All other trademarks referenced herein are the property of their respective owne ## About -This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at +This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know by [leaving a testimonial][testimonial]! -[![Cloud Posse](https://cloudposse.com/logo-300x69.svg)](https://cloudposse.com) +[![Cloud Posse][logo]][website] -We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We love [Open Source Software](https://github.com/cloudposse/)! +We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We ❤️ [Open Source Software][we_love_open_source]. -We offer paid support on all of our projects. +We offer [paid support][commercial_support] on all of our projects. -Check out [our other projects][github], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation. +Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation. - [docs]: https://docs.cloudposse.com/ - [website]: https://cloudposse.com/ - [github]: https://github.com/cloudposse/ - [commercial_support]: https://github.com/orgs/cloudposse/projects - [jobs]: https://cloudposse.com/jobs/ - [hire]: https://cloudposse.com/contact/ - [slack]: https://slack.cloudposse.com/ - [linkedin]: https://www.linkedin.com/company/cloudposse - [twitter]: https://twitter.com/cloudposse/ - [email]: mailto:hello@cloudposse.com ### Contributors @@ -337,3 +370,36 @@ Check out [our other projects][github], [apply for a job][jobs], or [hire us][hi [aknysh_avatar]: https://github.com/aknysh.png?size=150 + +[![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-cicd + [readme_header_link]: https://cloudposse.com/readme/header/link?repo=cloudposse/terraform-aws-cicd + [readme_footer_img]: https://cloudposse.com/readme/footer/img?repo=cloudposse/terraform-aws-cicd + [readme_footer_link]: https://cloudposse.com/readme/footer/link?repo=cloudposse/terraform-aws-cicd + [readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img?repo=cloudposse/terraform-aws-cicd + [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?repo=cloudposse/terraform-aws-cicd + [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-aws-cicd&url=https://github.com/cloudposse/terraform-aws-cicd + [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-aws-cicd&url=https://github.com/cloudposse/terraform-aws-cicd + [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-aws-cicd + [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-aws-cicd + [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-aws-cicd + [share_email]: mailto:?subject=terraform-aws-cicd&body=https://github.com/cloudposse/terraform-aws-cicd + [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-aws-cicd?pixel&cs=github&cm=readme&an=terraform-aws-cicd diff --git a/README.yaml b/README.yaml index 14bb222..5b8816f 100644 --- a/README.yaml +++ b/README.yaml @@ -92,6 +92,19 @@ usage: |- aws_account_id = "xxxxxxxxxx" image_repo_name = "ecr-repo-name" image_tag = "latest" + # Optional extra environment variables + environment_variables = [{ + name = "JENKINS_URL" + value = "https://jenkins.example.com" + }, + { + name = "COMPANY_NAME" + value = "Amazon" + }, + { + name = "TIME_ZONE" + value = "Pacific/Auckland" + }] } ``` @@ -191,4 +204,4 @@ contributors: - name: "Igor Rodionov" github: "goruha" - name: "Andriy Knysh" - github: "aknysh" \ No newline at end of file + github: "aknysh" diff --git a/docs/targets.md b/docs/targets.md index 09c39cd..3d4be2a 100644 --- a/docs/targets.md +++ b/docs/targets.md @@ -2,8 +2,9 @@ ``` Available targets: - help This help screen + help Help screen help/all Display help for all targets + help/short This help short screen lint Lint terraform code ``` diff --git a/docs/terraform.md b/docs/terraform.md index 68d45f2..509dc24 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -14,12 +14,13 @@ | delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no | | enabled | Enable ``CodePipeline`` creation | string | `true` | no | | env | Elastic Beanstalk environment name. If not provided or set to empty string, the ``Deploy`` stage of the pipeline will not be created | string | `` | no | +| environment_variables | A list of maps, that contain both the key 'name' and the key 'value' to be used as additional environment variables for the build. | list | `` | no | | github_oauth_token | GitHub Oauth Token with permissions to access private repositories | string | - | yes | | image_repo_name | ECR repository name to store the Docker image built by this module. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | `UNSET` | no | | image_tag | Docker image tag in the ECR repository, e.g. 'latest'. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html) | string | `latest` | no | | name | Solution name, e.g. 'app' or 'jenkins' | string | `app` | no | | namespace | Namespace, which could be your organization name, e.g. 'cp' or 'cloudposse' | string | `global` | no | -| poll_source_changes | Periodically check the location of your source content and run the pipeline if changes are detected | string | `false` | no | +| poll_source_changes | Periodically check the location of your source content and run the pipeline if changes are detected | string | `true` | no | | privileged_mode | If set to true, enables running the Docker daemon inside a Docker container on the CodeBuild instance. Used when building Docker images | string | `false` | no | | repo_name | GitHub repository name of the application to be built (and deployed to Elastic Beanstalk if configured) | string | - | yes | | repo_owner | GitHub Organization or Person name | string | - | yes | diff --git a/main.tf b/main.tf index d0cfae2..a0babae 100644 --- a/main.tf +++ b/main.tf @@ -133,22 +133,23 @@ data "aws_iam_policy_document" "codebuild" { } module "build" { - source = "git::https://github.com/cloudposse/terraform-aws-codebuild.git?ref=tags/0.6.2" - namespace = "${var.namespace}" - name = "${var.name}" - stage = "${var.stage}" - build_image = "${var.build_image}" - build_compute_type = "${var.build_compute_type}" - buildspec = "${var.buildspec}" - delimiter = "${var.delimiter}" - attributes = "${concat(var.attributes, list("build"))}" - tags = "${var.tags}" - privileged_mode = "${var.privileged_mode}" - aws_region = "${signum(length(var.aws_region)) == 1 ? var.aws_region : data.aws_region.default.name}" - aws_account_id = "${signum(length(var.aws_account_id)) == 1 ? var.aws_account_id : data.aws_caller_identity.default.account_id}" - image_repo_name = "${var.image_repo_name}" - image_tag = "${var.image_tag}" - github_token = "${var.github_oauth_token}" + source = "git::https://github.com/cloudposse/terraform-aws-codebuild.git?ref=tags/0.9.0" + namespace = "${var.namespace}" + name = "${var.name}" + stage = "${var.stage}" + build_image = "${var.build_image}" + build_compute_type = "${var.build_compute_type}" + buildspec = "${var.buildspec}" + delimiter = "${var.delimiter}" + attributes = "${concat(var.attributes, list("build"))}" + tags = "${var.tags}" + privileged_mode = "${var.privileged_mode}" + aws_region = "${signum(length(var.aws_region)) == 1 ? var.aws_region : data.aws_region.default.name}" + aws_account_id = "${signum(length(var.aws_account_id)) == 1 ? var.aws_account_id : data.aws_caller_identity.default.account_id}" + image_repo_name = "${var.image_repo_name}" + image_tag = "${var.image_tag}" + github_token = "${var.github_oauth_token}" + environment_variables = "${var.environment_variables}" } resource "aws_iam_role_policy_attachment" "codebuild_s3" { diff --git a/variables.tf b/variables.tf index ed082e8..7f6b345 100644 --- a/variables.tf +++ b/variables.tf @@ -115,3 +115,14 @@ variable "image_tag" { default = "latest" description = "Docker image tag in the ECR repository, e.g. 'latest'. Used as CodeBuild ENV variable when building Docker images. [For more info](http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html)" } + +variable "environment_variables" { + type = "list" + + default = [{ + "name" = "NO_ADDITIONAL_BUILD_VARS" + "value" = "TRUE" + }] + + description = "A list of maps, that contain both the key 'name' and the key 'value' to be used as additional environment variables for the build." +}