From b48359d1382812df960396968bc9aea634e39f64 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Tue, 6 Oct 2020 19:48:22 -0700 Subject: [PATCH 01/43] Initial commit --- README.md | 94 ++++++++++++++++++++++++----------------------- README.yaml | 18 ++++----- docs/terraform.md | 20 +++++----- main.tf | 53 ++++++++++++++++++++------ outputs.tf | 14 ------- variables.tf | 52 ++++++++++++++++++++++++-- versions.tf | 5 --- 7 files changed, 159 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index 40b4383..77227c8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# terraform-example-module [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-example-module.svg)](https://github.com/cloudposse/terraform-example-module/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) [![Discourse Forum](https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg)](https://ask.sweetops.com/) +# terraform-kubernetes-tfe-agent [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfe-agent.svg)](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) [![Discourse Forum](https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg)](https://ask.sweetops.com/) [![README Header][readme_header_img]][readme_header_link] @@ -25,7 +25,7 @@ --> -This is `terraform-example-module` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can +This is `terraform-kubernetes-tfe-agent` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can use when creating new repositories. @@ -64,14 +64,14 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are **IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases. -Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-example-module/releases). +Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/releases). Here's how to invoke this example module in your projects ```hcl module "example" { - source = "https://github.com/cloudposse/terraform-example-module.git?ref=master" + source = "https://github.com/cloudposse/terraform-kubernetes-tfe-agent.git?ref=master" example = "Hello world!" } ``` @@ -82,7 +82,7 @@ module "example" { ## Examples Here is an example of using this module: -- [`examples/complete`](https://github.com/cloudposse/terraform-example-module/) - complete example of using this module +- [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/) - complete example of using this module @@ -104,41 +104,43 @@ Available targets: | Name | Version | |------|---------| | terraform | >= 0.12.0, < 0.14.0 | -| local | ~> 1.2 | -| random | ~> 2.2 | ## Providers | Name | Version | |------|---------| -| random | ~> 2.2 | +| kubernetes | n/a | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | +| annotations | n/a | `map` |
{
"sidecar.istio.io/inject": "false"
}
| no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | +| deployment\_name | n/a | `string` | `"tfc-agent"` | no | | enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | -| example | Example variable | `string` | `"hello world"` | no | | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | +| k8s\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | +| labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | | namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | | regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | +| replicas | n/a | `number` | `1` | no | +| selector\_match\_labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | +| tfc\_agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | +| tfc\_agent\_name | n/a | `string` | n/a | yes | +| tfc\_agent\_token | n/a | `string` | n/a | yes | ## Outputs -| Name | Description | -|------|-------------| -| example | Example output | -| id | ID of the created example | -| random | Stable random number for this example | +No output. @@ -146,7 +148,7 @@ Available targets: ## Share the Love -Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-example-module)! (it helps us **a lot**) +Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-kubernetes-tfe-agent)! (it helps us **a lot**) Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =) @@ -174,7 +176,7 @@ For additional context, refer to some of these links. **Got a question?** We got answers. -File a GitHub [issue](https://github.com/cloudposse/terraform-example-module/issues), send us an [email][email] or join our [Slack Community][slack]. +File a GitHub [issue](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/issues), send us an [email][email] or join our [Slack Community][slack]. [![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link] @@ -222,7 +224,7 @@ Sign up for [our newsletter][newsletter] that covers everything on our technolog ### Bug Reports & Feature Requests -Please use the [issue tracker](https://github.com/cloudposse/terraform-example-module/issues) to report any bugs or file feature requests. +Please use the [issue tracker](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/issues) to report any bugs or file feature requests. ### Developing @@ -301,42 +303,42 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply ### Contributors -| [![Erik Osterman][osterman_avatar]][osterman_homepage]
[Erik Osterman][osterman_homepage] | +| [![Dan Meyers][danjbh_avatar]][danjbh_homepage]
[Dan Meyers][danjbh_homepage] | |---| - [osterman_homepage]: https://github.com/osterman - [osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png + [danjbh_homepage]: https://github.com/danjbh + [danjbh_avatar]: https://img.cloudposse.com/150x150/https://github.com/danjbh.png [![README Footer][readme_footer_img]][readme_footer_link] [![Beacon][beacon]][website] [logo]: https://cloudposse.com/logo-300x69.svg - [docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=docs - [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=website - [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=github - [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=jobs - [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=hire - [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=slack - [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=linkedin - [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=twitter - [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=testimonial - [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=office_hours - [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=newsletter - [discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=discourse - [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=email - [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&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-example-module&utm_content=we_love_open_source - [terraform_modules]: https://cpco.io/terraform-modules?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-example-module&utm_content=terraform_modules + [docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=docs + [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=website + [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=github + [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=jobs + [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=hire + [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=slack + [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=linkedin + [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=twitter + [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=testimonial + [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=office_hours + [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=newsletter + [discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=discourse + [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=email + [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&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-kubernetes-tfe-agent&utm_content=we_love_open_source + [terraform_modules]: https://cpco.io/terraform-modules?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&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-example-module&utm_content=readme_header_link + [readme_header_link]: https://cloudposse.com/readme/header/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&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-example-module&utm_content=readme_footer_link + [readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&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-example-module&utm_content=readme_commercial_support_link - [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-example-module&url=https://github.com/cloudposse/terraform-example-module - [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-example-module&url=https://github.com/cloudposse/terraform-example-module - [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-example-module - [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-example-module - [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-example-module - [share_email]: mailto:?subject=terraform-example-module&body=https://github.com/cloudposse/terraform-example-module - [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-example-module?pixel&cs=github&cm=readme&an=terraform-example-module + [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=readme_commercial_support_link + [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-kubernetes-tfe-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfe-agent + [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-kubernetes-tfe-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfe-agent + [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-kubernetes-tfe-agent + [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-kubernetes-tfe-agent + [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-kubernetes-tfe-agent + [share_email]: mailto:?subject=terraform-kubernetes-tfe-agent&body=https://github.com/cloudposse/terraform-kubernetes-tfe-agent + [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-kubernetes-tfe-agent?pixel&cs=github&cm=readme&an=terraform-kubernetes-tfe-agent diff --git a/README.yaml b/README.yaml index dfc9acb..23810b3 100644 --- a/README.yaml +++ b/README.yaml @@ -5,7 +5,7 @@ # # Name of this project -name: terraform-example-module +name: terraform-kubernetes-tfe-agent # Logo for this project #logo: docs/logo.png @@ -20,13 +20,13 @@ copyrights: year: "2020" # Canonical GitHub repo -github_repo: cloudposse/terraform-example-module +github_repo: cloudposse/terraform-kubernetes-tfe-agent # Badges to display badges: - name: "Latest Release" - image: "https://img.shields.io/github/release/cloudposse/terraform-example-module.svg" - url: "https://github.com/cloudposse/terraform-example-module/releases/latest" + image: "https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfe-agent.svg" + url: "https://github.com/cloudposse/terraform-kubernetes-tfe-agent/releases/latest" - name: "Slack Community" image: "https://slack.cloudposse.com/badge.svg" url: "https://slack.cloudposse.com" @@ -57,7 +57,7 @@ references: # Short description of this project description: |- - This is `terraform-example-module` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can + This is `terraform-kubernetes-tfe-agent` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can use when creating new repositories. # Introduction to the project @@ -70,7 +70,7 @@ usage: |- ```hcl module "example" { - source = "https://github.com/cloudposse/terraform-example-module.git?ref=master" + source = "https://github.com/cloudposse/terraform-kubernetes-tfe-agent.git?ref=master" example = "Hello world!" } ``` @@ -78,7 +78,7 @@ usage: |- # Example usage examples: |- Here is an example of using this module: - - [`examples/complete`](https://github.com/cloudposse/terraform-example-module/) - complete example of using this module + - [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/) - complete example of using this module # How to get started quickly #quickstart: |- @@ -91,5 +91,5 @@ include: # Contributors to this project contributors: - - name: "Erik Osterman" - github: "osterman" + - name: "Dan Meyers" + github: "danjbh" diff --git a/docs/terraform.md b/docs/terraform.md index 7fdf496..a250a12 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -4,40 +4,42 @@ | Name | Version | |------|---------| | terraform | >= 0.12.0, < 0.14.0 | -| local | ~> 1.2 | -| random | ~> 2.2 | ## Providers | Name | Version | |------|---------| -| random | ~> 2.2 | +| kubernetes | n/a | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | +| annotations | n/a | `map` |
{
"sidecar.istio.io/inject": "false"
}
| no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | +| deployment\_name | n/a | `string` | `"tfc-agent"` | no | | enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | -| example | Example variable | `string` | `"hello world"` | no | | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | +| k8s\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | +| labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | | namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | | regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | +| replicas | n/a | `number` | `1` | no | +| selector\_match\_labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | +| tfc\_agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | +| tfc\_agent\_name | n/a | `string` | n/a | yes | +| tfc\_agent\_token | n/a | `string` | n/a | yes | ## Outputs -| Name | Description | -|------|-------------| -| example | Example output | -| id | ID of the created example | -| random | Stable random number for this example | +No output. diff --git a/main.tf b/main.tf index 8e1225e..c2a56ca 100644 --- a/main.tf +++ b/main.tf @@ -1,13 +1,44 @@ -resource "random_integer" "example" { - count = module.this.enabled ? 1 : 0 - - min = 1 - max = 50000 - keepers = { - example = var.example +resource "kubernetes_deployment" "tfc-agent" { + metadata { + name = var.deployment_name + namespace = var.k8s_namespace + labels = var.labels } -} + spec { + selector { + match_labels = var.selector_match_labels + } + replicas = var.replicas -locals { - example = format("%v %v", var.example, join("", random_integer.example[*].result)) -} + template { + metadata { + labels = var.labels + annotations = var.annotations + } + spec { + container { + image = var.tfc_agent_image + name = "tfc-agent" + env { + name = "TFC_AGENT_TOKEN" + value = var.tfc_agent_token + } + env { + name = "TFC_AGENT_NAME" + value = var.tfc_agent_name + } + resources { + limits { + cpu = "1" + memory = "512Mi" + } + requests { + cpu = "250m" + memory = "50Mi" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/outputs.tf b/outputs.tf index 23e08b2..e69de29 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,14 +0,0 @@ -output "id" { - description = "ID of the created example" - value = module.this.enabled ? module.this.id : null -} - -output "example" { - description = "Example output" - value = module.this.enabled ? local.example : null -} - -output "random" { - description = "Stable random number for this example" - value = module.this.enabled ? join("", random_integer.example[*].result) : null -} diff --git a/variables.tf b/variables.tf index ff9b03b..875d800 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,50 @@ -variable "example" { - description = "Example variable" - default = "hello world" +variable "deployment_name" { + type = string + default = "tfc-agent" } + +variable "k8s_namespace" { + type = string + default = "default" + description = "Kubernetes namespace to deploy agent within" +} + +variable "labels" { + type = map + default = { + app = "tfc-agent" + } +} + +variable "selector_match_labels" { + type = map + default = { + app = "tfc-agent" + } +} + +variable "replicas" { + type = number + default = 1 +} + +variable "annotations" { + type = map + default = { + "sidecar.istio.io/inject" = "false" + } +} + +variable "tfc_agent_image" { + type = string + description = "Name and tag of TFC agent docker image" + default = "hashicorp/tfc-agent:latest" +} + +variable "tfc_agent_name" { + type = string +} + +variable "tfc_agent_token" { + type = string +} \ No newline at end of file diff --git a/versions.tf b/versions.tf index b108528..92a263e 100644 --- a/versions.tf +++ b/versions.tf @@ -1,8 +1,3 @@ terraform { required_version = ">= 0.12.0, < 0.14.0" - - required_providers { - local = "~> 1.2" - random = "~> 2.2" - } } From 63d50957febbace6c5dfd6ab50fc6d46c16a15b7 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Tue, 6 Oct 2020 19:49:58 -0700 Subject: [PATCH 02/43] Updating README --- README.md | 70 +++++++++++++++++++++++++++-------------------------- README.yaml | 14 +++++------ 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 77227c8..77ab29a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# terraform-kubernetes-tfe-agent [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfe-agent.svg)](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) [![Discourse Forum](https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg)](https://ask.sweetops.com/) +# terraform-kubernetes-tfe-cloud-agent + + [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfe-cloud-agent.svg)](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) [![Discourse Forum](https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg)](https://ask.sweetops.com/) [![README Header][readme_header_img]][readme_header_link] @@ -25,7 +27,7 @@ --> -This is `terraform-kubernetes-tfe-agent` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can +This is `terraform-kubernetes-tfe-cloud-agent` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can use when creating new repositories. @@ -64,14 +66,14 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are **IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases. -Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/releases). +Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/releases). Here's how to invoke this example module in your projects ```hcl module "example" { - source = "https://github.com/cloudposse/terraform-kubernetes-tfe-agent.git?ref=master" + source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" example = "Hello world!" } ``` @@ -82,7 +84,7 @@ module "example" { ## Examples Here is an example of using this module: -- [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/) - complete example of using this module +- [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/) - complete example of using this module @@ -148,7 +150,7 @@ No output. ## Share the Love -Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-kubernetes-tfe-agent)! (it helps us **a lot**) +Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent)! (it helps us **a lot**) Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =) @@ -176,7 +178,7 @@ For additional context, refer to some of these links. **Got a question?** We got answers. -File a GitHub [issue](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/issues), send us an [email][email] or join our [Slack Community][slack]. +File a GitHub [issue](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/issues), send us an [email][email] or join our [Slack Community][slack]. [![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link] @@ -224,7 +226,7 @@ Sign up for [our newsletter][newsletter] that covers everything on our technolog ### Bug Reports & Feature Requests -Please use the [issue tracker](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/issues) to report any bugs or file feature requests. +Please use the [issue tracker](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/issues) to report any bugs or file feature requests. ### Developing @@ -313,32 +315,32 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply [![Beacon][beacon]][website] [logo]: https://cloudposse.com/logo-300x69.svg - [docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=docs - [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=website - [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=github - [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=jobs - [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=hire - [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=slack - [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=linkedin - [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=twitter - [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=testimonial - [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=office_hours - [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=newsletter - [discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=discourse - [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=email - [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&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-kubernetes-tfe-agent&utm_content=we_love_open_source - [terraform_modules]: https://cpco.io/terraform-modules?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-agent&utm_content=terraform_modules + [docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=docs + [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=website + [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=github + [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=jobs + [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=hire + [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=slack + [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=linkedin + [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=twitter + [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=testimonial + [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=office_hours + [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=newsletter + [discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=discourse + [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=email + [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&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-kubernetes-tfe-cloud-agent&utm_content=we_love_open_source + [terraform_modules]: https://cpco.io/terraform-modules?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&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-kubernetes-tfe-agent&utm_content=readme_header_link + [readme_header_link]: https://cloudposse.com/readme/header/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&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-kubernetes-tfe-agent&utm_content=readme_footer_link + [readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&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-kubernetes-tfe-agent&utm_content=readme_commercial_support_link - [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-kubernetes-tfe-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfe-agent - [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-kubernetes-tfe-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfe-agent - [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-kubernetes-tfe-agent - [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-kubernetes-tfe-agent - [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-kubernetes-tfe-agent - [share_email]: mailto:?subject=terraform-kubernetes-tfe-agent&body=https://github.com/cloudposse/terraform-kubernetes-tfe-agent - [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-kubernetes-tfe-agent?pixel&cs=github&cm=readme&an=terraform-kubernetes-tfe-agent + [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=readme_commercial_support_link + [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-kubernetes-tfe-cloud-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent + [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-kubernetes-tfe-cloud-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent + [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent + [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent + [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent + [share_email]: mailto:?subject=terraform-kubernetes-tfe-cloud-agent&body=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent + [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-kubernetes-tfe-cloud-agent?pixel&cs=github&cm=readme&an=terraform-kubernetes-tfe-cloud-agent diff --git a/README.yaml b/README.yaml index 23810b3..f947822 100644 --- a/README.yaml +++ b/README.yaml @@ -5,7 +5,7 @@ # # Name of this project -name: terraform-kubernetes-tfe-agent +name: terraform-kubernetes-tfe-cloud-agent # Logo for this project #logo: docs/logo.png @@ -20,13 +20,13 @@ copyrights: year: "2020" # Canonical GitHub repo -github_repo: cloudposse/terraform-kubernetes-tfe-agent +github_repo: cloudposse/terraform-kubernetes-tfe-cloud-agent # Badges to display badges: - name: "Latest Release" - image: "https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfe-agent.svg" - url: "https://github.com/cloudposse/terraform-kubernetes-tfe-agent/releases/latest" + image: "https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfe-cloud-agent.svg" + url: "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/releases/latest" - name: "Slack Community" image: "https://slack.cloudposse.com/badge.svg" url: "https://slack.cloudposse.com" @@ -57,7 +57,7 @@ references: # Short description of this project description: |- - This is `terraform-kubernetes-tfe-agent` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can + This is `terraform-kubernetes-tfe-cloud-agent` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can use when creating new repositories. # Introduction to the project @@ -70,7 +70,7 @@ usage: |- ```hcl module "example" { - source = "https://github.com/cloudposse/terraform-kubernetes-tfe-agent.git?ref=master" + source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" example = "Hello world!" } ``` @@ -78,7 +78,7 @@ usage: |- # Example usage examples: |- Here is an example of using this module: - - [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfe-agent/) - complete example of using this module + - [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/) - complete example of using this module # How to get started quickly #quickstart: |- From 20421e5175d0e5cb9032ed6bf05b81e0c83aa808 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Tue, 6 Oct 2020 19:56:33 -0700 Subject: [PATCH 03/43] Updating README --- README.md | 4 ++-- README.yaml | 3 --- docs/terraform.md | 3 ++- versions.tf | 4 ++++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 77ab29a..92b54e3 100644 --- a/README.md +++ b/README.md @@ -106,12 +106,13 @@ Available targets: | Name | Version | |------|---------| | terraform | >= 0.12.0, < 0.14.0 | +| kubernetes | >= 1.12.0 | ## Providers | Name | Version | |------|---------| -| kubernetes | n/a | +| kubernetes | >= 1.12.0 | ## Inputs @@ -170,7 +171,6 @@ For additional context, refer to some of these links. - [Terraform Standard Module Structure](https://www.terraform.io/docs/modules/index.html#standard-module-structure) - HashiCorp's standard module structure is a file and directory layout we recommend for reusable modules distributed in separate repositories. - [Terraform Module Requirements](https://www.terraform.io/docs/registry/modules/publish.html#requirements) - HashiCorp's guidance on all the requirements for publishing a module. Meeting the requirements for publishing a module is extremely easy. -- [Terraform `random_integer` Resource](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) - The resource random_integer generates random values from a given range, described by the min and max attributes of a given resource. - [Terraform Version Pinning](https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version) - The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration diff --git a/README.yaml b/README.yaml index f947822..b37d772 100644 --- a/README.yaml +++ b/README.yaml @@ -48,9 +48,6 @@ references: - name: "Terraform Module Requirements" description: "HashiCorp's guidance on all the requirements for publishing a module. Meeting the requirements for publishing a module is extremely easy." url: "https://www.terraform.io/docs/registry/modules/publish.html#requirements" - - name: "Terraform `random_integer` Resource" - description: "The resource random_integer generates random values from a given range, described by the min and max attributes of a given resource." - url: "https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer" - name: "Terraform Version Pinning" description: "The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration" url: "https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version" diff --git a/docs/terraform.md b/docs/terraform.md index a250a12..0d81e38 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -4,12 +4,13 @@ | Name | Version | |------|---------| | terraform | >= 0.12.0, < 0.14.0 | +| kubernetes | >= 1.12.0 | ## Providers | Name | Version | |------|---------| -| kubernetes | n/a | +| kubernetes | >= 1.12.0 | ## Inputs diff --git a/versions.tf b/versions.tf index 92a263e..ba071b4 100644 --- a/versions.tf +++ b/versions.tf @@ -1,3 +1,7 @@ terraform { required_version = ">= 0.12.0, < 0.14.0" + + required_providers { + kubernetes = ">= 1.12.0" + } } From 42b9bd561969a8b8fdb7469b2381fcf40e8ca302 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Wed, 7 Oct 2020 09:53:06 -0700 Subject: [PATCH 04/43] Updating documentation --- README.md | 15 ++++++++------- README.yaml | 19 ++++++------------- docs/terraform.md | 4 ++-- variables.tf | 9 ++++----- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 92b54e3..b96ac15 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,7 @@ --> -This is `terraform-kubernetes-tfe-cloud-agent` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can -use when creating new repositories. +This project installed the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! --- @@ -69,12 +68,14 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/releases). -Here's how to invoke this example module in your projects ```hcl -module "example" { +module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" - example = "Hello world!" + + k8s_namespace = "tfc-agent" # You can specify a namespace other than "default" + tfc_agent_name = "example-tfc-agent" # Must be a DNS-compliant name + tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud } ``` @@ -119,11 +120,11 @@ Available targets: | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | -| annotations | n/a | `map` |
{
"sidecar.istio.io/inject": "false"
}
| no | +| annotations | n/a | `map` | `{}` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | -| deployment\_name | n/a | `string` | `"tfc-agent"` | no | +| deployment\_name | Name of the deployment in Kubernetes | `string` | `"tfc-agent"` | no | | enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | diff --git a/README.yaml b/README.yaml index b37d772..61d79e1 100644 --- a/README.yaml +++ b/README.yaml @@ -54,21 +54,18 @@ references: # Short description of this project description: |- - This is `terraform-kubernetes-tfe-cloud-agent` project provides all the scaffolding for a typical well-built Cloud Posse module. It's a template repository you can - use when creating new repositories. - -# Introduction to the project -#introduction: |- -# This is an introduction. + This project installed the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! # How to use this module. Should be an easy example to copy and paste. usage: |- - Here's how to invoke this example module in your projects ```hcl - module "example" { + module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" - example = "Hello world!" + + k8s_namespace = "tfc-agent" # You can specify a namespace other than "default" + tfc_agent_name = "example-tfc-agent" # Must be a DNS-compliant name + tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud } ``` @@ -77,10 +74,6 @@ examples: |- Here is an example of using this module: - [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/) - complete example of using this module -# How to get started quickly -#quickstart: |- -# Here's how to get started... - # Other files to include in this README from the project folder include: - "docs/targets.md" diff --git a/docs/terraform.md b/docs/terraform.md index 0d81e38..fc76415 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -17,11 +17,11 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | -| annotations | n/a | `map` |
{
"sidecar.istio.io/inject": "false"
}
| no | +| annotations | n/a | `map` | `{}` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | -| deployment\_name | n/a | `string` | `"tfc-agent"` | no | +| deployment\_name | Name of the deployment in Kubernetes | `string` | `"tfc-agent"` | no | | enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | diff --git a/variables.tf b/variables.tf index 875d800..c986c3b 100644 --- a/variables.tf +++ b/variables.tf @@ -1,6 +1,7 @@ variable "deployment_name" { - type = string - default = "tfc-agent" + type = string + default = "tfc-agent" + description = "Name of the deployment in Kubernetes" } variable "k8s_namespace" { @@ -30,9 +31,7 @@ variable "replicas" { variable "annotations" { type = map - default = { - "sidecar.istio.io/inject" = "false" - } + default = {} } variable "tfc_agent_image" { From c9540379b25e82ca09c41a156d291a2c2c1a1b12 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Wed, 7 Oct 2020 10:02:37 -0700 Subject: [PATCH 05/43] Fixing small documentation thing --- README.md | 2 +- README.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b96ac15..8159f9d 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ module "tfc_agent" { k8s_namespace = "tfc-agent" # You can specify a namespace other than "default" tfc_agent_name = "example-tfc-agent" # Must be a DNS-compliant name - tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud + tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud } ``` diff --git a/README.yaml b/README.yaml index 61d79e1..0f68e3c 100644 --- a/README.yaml +++ b/README.yaml @@ -65,7 +65,7 @@ usage: |- k8s_namespace = "tfc-agent" # You can specify a namespace other than "default" tfc_agent_name = "example-tfc-agent" # Must be a DNS-compliant name - tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud + tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud } ``` From 3ea9d0100755c3621e3a4755d638d34ee42cee84 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Wed, 7 Oct 2020 10:24:46 -0700 Subject: [PATCH 06/43] Renaming k8s_namespace --- README.md | 2 +- README.yaml | 6 +++--- docs/terraform.md | 2 +- variables.tf | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8159f9d..b5a0960 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ Available targets: | enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | -| k8s\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | +| kubernetes\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | | labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | diff --git a/README.yaml b/README.yaml index 0f68e3c..2b62c53 100644 --- a/README.yaml +++ b/README.yaml @@ -63,9 +63,9 @@ usage: |- module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" - k8s_namespace = "tfc-agent" # You can specify a namespace other than "default" - tfc_agent_name = "example-tfc-agent" # Must be a DNS-compliant name - tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud + kubernetes_namespace = "tfc-agent" # You can specify a namespace other than "default" + tfc_agent_name = "example-tfc-agent" # Must be a DNS-compliant name + tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud } ``` diff --git a/docs/terraform.md b/docs/terraform.md index fc76415..99919b6 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -25,7 +25,7 @@ | enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | -| k8s\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | +| kubernetes\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | | labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | diff --git a/variables.tf b/variables.tf index c986c3b..570f6dc 100644 --- a/variables.tf +++ b/variables.tf @@ -4,7 +4,7 @@ variable "deployment_name" { description = "Name of the deployment in Kubernetes" } -variable "k8s_namespace" { +variable "kubernetes_namespace" { type = string default = "default" description = "Kubernetes namespace to deploy agent within" @@ -46,4 +46,4 @@ variable "tfc_agent_name" { variable "tfc_agent_token" { type = string -} \ No newline at end of file +} From 99ebd77b16fa55783f134d4ad4dc2f49043938f7 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Wed, 7 Oct 2020 10:38:56 -0700 Subject: [PATCH 07/43] Updating a few things --- README.md | 21 +++++++++++++++------ README.yaml | 16 +++++++++++++--- docs/terraform.md | 5 ++--- main.tf | 6 ++++-- variables.tf | 12 +++++------- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b5a0960..3afbfb0 100644 --- a/README.md +++ b/README.md @@ -70,12 +70,22 @@ Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest re ```hcl +provider "kubernetes" { + #Context to choose from the config file, if needed. + config_context = "example-context" + version = "~> 1.12" +} + module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" - k8s_namespace = "tfc-agent" # You can specify a namespace other than "default" - tfc_agent_name = "example-tfc-agent" # Must be a DNS-compliant name - tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud + token = var.token # Your agent token generated in Terraform Cloud + + namespace = var.namespace + stage = var.stage + name = var.name + + kubernetes_namespace = "tfc-agent" # You can specify a namespace other than "default" } ``` @@ -120,6 +130,7 @@ Available targets: | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | +| agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | | annotations | n/a | `map` | `{}` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | @@ -138,9 +149,7 @@ Available targets: | selector\_match\_labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | -| tfc\_agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | -| tfc\_agent\_name | n/a | `string` | n/a | yes | -| tfc\_agent\_token | n/a | `string` | n/a | yes | +| token | The agent token, as configured in Terraform Cloud | `string` | `""` | no | ## Outputs diff --git a/README.yaml b/README.yaml index 2b62c53..481588f 100644 --- a/README.yaml +++ b/README.yaml @@ -60,12 +60,22 @@ description: |- usage: |- ```hcl + provider "kubernetes" { + #Context to choose from the config file, if needed. + config_context = "example-context" + version = "~> 1.12" + } + module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" - kubernetes_namespace = "tfc-agent" # You can specify a namespace other than "default" - tfc_agent_name = "example-tfc-agent" # Must be a DNS-compliant name - tfc_agent_token = "SET_ME" # Your agent token generated in Terraform Cloud + token = var.token # Your agent token generated in Terraform Cloud + + namespace = var.namespace + stage = var.stage + name = var.name + + kubernetes_namespace = "tfc-agent" # You can specify a namespace other than "default" } ``` diff --git a/docs/terraform.md b/docs/terraform.md index 99919b6..ba0ef01 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -17,6 +17,7 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | +| agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | | annotations | n/a | `map` | `{}` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | @@ -35,9 +36,7 @@ | selector\_match\_labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | -| tfc\_agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | -| tfc\_agent\_name | n/a | `string` | n/a | yes | -| tfc\_agent\_token | n/a | `string` | n/a | yes | +| token | The agent token, as configured in Terraform Cloud | `string` | `""` | no | ## Outputs diff --git a/main.tf b/main.tf index c2a56ca..f0627aa 100644 --- a/main.tf +++ b/main.tf @@ -1,7 +1,9 @@ resource "kubernetes_deployment" "tfc-agent" { + count = module.this.enabled ? 1 : 0 + metadata { name = var.deployment_name - namespace = var.k8s_namespace + namespace = var.kubernetes_namespace labels = var.labels } spec { @@ -25,7 +27,7 @@ resource "kubernetes_deployment" "tfc-agent" { } env { name = "TFC_AGENT_NAME" - value = var.tfc_agent_name + value = module.this.id } resources { limits { diff --git a/variables.tf b/variables.tf index 570f6dc..d84ee8f 100644 --- a/variables.tf +++ b/variables.tf @@ -34,16 +34,14 @@ variable "annotations" { default = {} } -variable "tfc_agent_image" { +variable "agent_image" { type = string description = "Name and tag of TFC agent docker image" default = "hashicorp/tfc-agent:latest" } -variable "tfc_agent_name" { - type = string -} - -variable "tfc_agent_token" { - type = string +variable "token" { + type = string + description = "The agent token, as configured in Terraform Cloud" + default = "" } From a66138dc149922761528dcfbcba474db4c9485a9 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Wed, 7 Oct 2020 10:42:59 -0700 Subject: [PATCH 08/43] Some minor formatting tweaks --- README.md | 8 ++++---- docs/terraform.md | 8 ++++---- variables.tf | 8 ++++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3afbfb0..f7acd4d 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ Available targets: |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | | agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | -| annotations | n/a | `map` | `{}` | no | +| annotations | Annotations to add to the Kubernetes deployment | `map` | `{}` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | @@ -141,12 +141,12 @@ Available targets: | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | | kubernetes\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | -| labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | +| labels | Labels to apply to the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | | namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | | regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | -| replicas | n/a | `number` | `1` | no | -| selector\_match\_labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | +| replicas | Number of replicas in the Kubernetes deployment | `number` | `1` | no | +| selector\_match\_labels | Selector labels to match on the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | | token | The agent token, as configured in Terraform Cloud | `string` | `""` | no | diff --git a/docs/terraform.md b/docs/terraform.md index ba0ef01..a420d85 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -18,7 +18,7 @@ |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | | agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | -| annotations | n/a | `map` | `{}` | no | +| annotations | Annotations to add to the Kubernetes deployment | `map` | `{}` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | @@ -28,12 +28,12 @@ | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | | kubernetes\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | -| labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | +| labels | Labels to apply to the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | | namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | | regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | -| replicas | n/a | `number` | `1` | no | -| selector\_match\_labels | n/a | `map` |
{
"app": "tfc-agent"
}
| no | +| replicas | Number of replicas in the Kubernetes deployment | `number` | `1` | no | +| selector\_match\_labels | Selector labels to match on the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | | token | The agent token, as configured in Terraform Cloud | `string` | `""` | no | diff --git a/variables.tf b/variables.tf index d84ee8f..5726729 100644 --- a/variables.tf +++ b/variables.tf @@ -15,6 +15,7 @@ variable "labels" { default = { app = "tfc-agent" } + description = "Labels to apply to the Kubernetes deployment" } variable "selector_match_labels" { @@ -22,26 +23,29 @@ variable "selector_match_labels" { default = { app = "tfc-agent" } + description = "Selector labels to match on the Kubernetes deployment" } variable "replicas" { type = number default = 1 + description = "Number of replicas in the Kubernetes deployment" } variable "annotations" { type = map default = {} + description = "Annotations to add to the Kubernetes deployment" } variable "agent_image" { type = string - description = "Name and tag of TFC agent docker image" default = "hashicorp/tfc-agent:latest" + description = "Name and tag of TFC agent docker image" } variable "token" { type = string - description = "The agent token, as configured in Terraform Cloud" default = "" + description = "The agent token, as configured in Terraform Cloud" } From 0edafb6ed346672e1f23a34877e523e2a543c0a7 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Wed, 7 Oct 2020 10:45:44 -0700 Subject: [PATCH 09/43] A few more tweaks --- README.md | 2 +- docs/terraform.md | 2 +- variables.tf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f7acd4d..a1f48bb 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ Available targets: | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | -| agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | +| agent\_image | Name and tag of Terraform Cloud Agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | | annotations | Annotations to add to the Kubernetes deployment | `map` | `{}` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | diff --git a/docs/terraform.md b/docs/terraform.md index a420d85..f9d4016 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -17,7 +17,7 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | -| agent\_image | Name and tag of TFC agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | +| agent\_image | Name and tag of Terraform Cloud Agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | | annotations | Annotations to add to the Kubernetes deployment | `map` | `{}` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | diff --git a/variables.tf b/variables.tf index 5726729..7e6b06d 100644 --- a/variables.tf +++ b/variables.tf @@ -41,7 +41,7 @@ variable "annotations" { variable "agent_image" { type = string default = "hashicorp/tfc-agent:latest" - description = "Name and tag of TFC agent docker image" + description = "Name and tag of Terraform Cloud Agent docker image" } variable "token" { From b8dd67660ca2a190bdcb9ee55a6d4b7819fc872f Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Wed, 7 Oct 2020 18:05:01 -0700 Subject: [PATCH 10/43] Updating examples --- README.yaml | 10 +++++----- examples/complete/fixtures.us-east-2.tfvars | 3 +-- examples/complete/main.tf | 9 ++++++--- examples/complete/outputs.tf | 14 -------------- examples/complete/variables.tf | 2 +- examples/complete/versions.tf | 2 +- main.tf | 4 ++-- 7 files changed, 16 insertions(+), 28 deletions(-) diff --git a/README.yaml b/README.yaml index 481588f..80b0b4c 100644 --- a/README.yaml +++ b/README.yaml @@ -69,11 +69,11 @@ usage: |- module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" - token = var.token # Your agent token generated in Terraform Cloud - - namespace = var.namespace - stage = var.stage - name = var.name + token = var.token # Your agent token generated in Terraform Cloud + namespace = var.namespace + stage = var.stage + environment = var.environment + name = var.name kubernetes_namespace = "tfc-agent" # You can specify a namespace other than "default" } diff --git a/examples/complete/fixtures.us-east-2.tfvars b/examples/complete/fixtures.us-east-2.tfvars index 1e0ce68..1b11090 100644 --- a/examples/complete/fixtures.us-east-2.tfvars +++ b/examples/complete/fixtures.us-east-2.tfvars @@ -1,5 +1,3 @@ -region = "us-east-2" - namespace = "eg" environment = "ue2" @@ -8,3 +6,4 @@ stage = "test" name = "example" +token = "" diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 38880b7..b989446 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -1,7 +1,10 @@ -module "example" { - source = "../.." + provider "kubernetes" { + version = "~> 1.12" + } - example = var.example +module "tfc_agent" { + source = "../.." context = module.this.context + token = var.token } diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf index 20aa3e3..e69de29 100644 --- a/examples/complete/outputs.tf +++ b/examples/complete/outputs.tf @@ -1,14 +0,0 @@ -output "id" { - description = "ID of the created example" - value = module.example.id -} - -output "example" { - description = "Output \"example\" from example module" - value = module.example.example -} - -output "random" { - description = "Output \"random\" from example module" - value = module.example.random -} diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index 9a04f21..db2f46e 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -1,4 +1,4 @@ -variable "example" { +variable "token" { type = string description = "The value which will be passed to the example module" } diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf index 572ee1f..4a34796 100644 --- a/examples/complete/versions.tf +++ b/examples/complete/versions.tf @@ -2,6 +2,6 @@ terraform { required_version = ">= 0.12.0, < 0.14" required_providers { - local = "~> 1.2" + kubernetes = "~> 1.12" } } diff --git a/main.tf b/main.tf index f0627aa..5680ed8 100644 --- a/main.tf +++ b/main.tf @@ -19,11 +19,11 @@ resource "kubernetes_deployment" "tfc-agent" { } spec { container { - image = var.tfc_agent_image + image = var.agent_image name = "tfc-agent" env { name = "TFC_AGENT_TOKEN" - value = var.tfc_agent_token + value = var.token } env { name = "TFC_AGENT_NAME" From c0126f0b44d0a0689db914bdac95a8691aa00e05 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Wed, 7 Oct 2020 18:26:19 -0700 Subject: [PATCH 11/43] Adding first draft of service acount --- main.tf | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index c2a56ca..28c5fba 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,19 @@ -resource "kubernetes_deployment" "tfc-agent" { +resource "kubernetes_service_account" "service_account" { + metadata { + name = var.deployment_name + } + secret { + name = "${kubernetes_secret.secret.metadata.0.name}" + } +} + +resource "kubernetes_secret" "secret" { + metadata { + name = var.deployment_name + } +} + +resource "kubernetes_deployment" "tfc_cloud_agent" { metadata { name = var.deployment_name namespace = var.k8s_namespace From ad193378557d1829a2fe7425517edaba97b688a2 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Wed, 7 Oct 2020 19:41:09 -0700 Subject: [PATCH 12/43] A couple small tweaks --- examples/complete/fixtures.us-east-2.tfvars | 1 - examples/complete/main.tf | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/complete/fixtures.us-east-2.tfvars b/examples/complete/fixtures.us-east-2.tfvars index 3d78dbd..48d6180 100644 --- a/examples/complete/fixtures.us-east-2.tfvars +++ b/examples/complete/fixtures.us-east-2.tfvars @@ -6,4 +6,3 @@ stage = "test" name = "example" -#token = "" diff --git a/examples/complete/main.tf b/examples/complete/main.tf index b989446..c4c8ba6 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -8,3 +8,4 @@ module "tfc_agent" { context = module.this.context token = var.token } + From 8589ee9d75ca7c4e624b4815921fe55392fbcf7a Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 10:28:24 -0700 Subject: [PATCH 13/43] Breaking out k8s resource values into TF vars --- main.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 5680ed8..175496c 100644 --- a/main.tf +++ b/main.tf @@ -31,12 +31,12 @@ resource "kubernetes_deployment" "tfc-agent" { } resources { limits { - cpu = "1" - memory = "512Mi" + cpu = var.resource_limits_cpu + memory = var.resource_limits_memory } requests { - cpu = "250m" - memory = "50Mi" + cpu = var.resource_requests_cpu + memory = var.resource_requests_memory } } } From 0ceabc8498d3309511c5c497c68d91eecf377b02 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 10:31:23 -0700 Subject: [PATCH 14/43] Updating vars --- variables.tf | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/variables.tf b/variables.tf index ee13f88..3c9dae2 100644 --- a/variables.tf +++ b/variables.tf @@ -11,15 +11,15 @@ variable "kubernetes_namespace" { } variable "labels" { - type = map + type = map default = { - app = "tfc-agent" + app = "tfc-agent" } description = "Labels to apply to the Kubernetes deployment" } variable "selector_match_labels" { - type = map + type = map default = { app = "tfc-agent" } @@ -27,23 +27,17 @@ variable "selector_match_labels" { } variable "replicas" { - type = number - default = 1 + type = number + default = 1 description = "Number of replicas in the Kubernetes deployment" } -variable "deployment_annotations" { - type = map - default = {} +variable "annotations" { + type = map + default = {} description = "Annotations to add to the Kubernetes deployment" } -variable "service_account_annotations" { - type = map - default = {} - description = "Annotations to add to the Kubernetes service account" -} - variable "agent_image" { type = string default = "hashicorp/tfc-agent:latest" @@ -55,3 +49,27 @@ variable "token" { default = "" description = "The agent token, as configured in Terraform Cloud" } + +variable "resource_limits_cpu" { + type = string + default = "1" + description = "Kubernetes deployment resource CPU limit" +} + +variable "resource_limits_memory" { + type = string + default = "512Mi" + description = "Kubernetes deployment resource memory limit" +} + +variable "resource_requests_cpu" { + type = string + default = "250m" + description = "Kubernetes deployment resource CPU requests" +} + +variable "resource_requests_memory" { + type = string + default = "50Mi" + description = "Kubernetes deployment resource memory requests" +} From cee9c76183d54e6707a675dc88ceb77dce444308 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 10:33:23 -0700 Subject: [PATCH 15/43] Renaming fixtures in complete example --- examples/complete/{fixtures.us-east-2.tfvars => fixtures.tfvars} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/complete/{fixtures.us-east-2.tfvars => fixtures.tfvars} (100%) diff --git a/examples/complete/fixtures.us-east-2.tfvars b/examples/complete/fixtures.tfvars similarity index 100% rename from examples/complete/fixtures.us-east-2.tfvars rename to examples/complete/fixtures.tfvars From e2c07d13ffd02e77123c096accb47419662c4ed4 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 10:34:27 -0700 Subject: [PATCH 16/43] Updating variable description --- examples/complete/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index db2f46e..d6fde69 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -1,4 +1,4 @@ variable "token" { type = string - description = "The value which will be passed to the example module" + description = "The preconfigured Terraform Cloud Agent token" } From ae1418128c7e931963f55e0dc102ca7f923fede9 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 11:03:29 -0700 Subject: [PATCH 17/43] Fixing a formatting thing --- examples/complete/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index c4c8ba6..9d781d3 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -1,6 +1,6 @@ - provider "kubernetes" { - version = "~> 1.12" - } +provider "kubernetes" { + version = "~> 1.12" +} module "tfc_agent" { source = "../.." From 488f709b1a1696789815f2a46af089f0cb2b247f Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 11:11:18 -0700 Subject: [PATCH 18/43] Fixing formatting & added missing variable --- main.tf | 2 +- variables.tf | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/main.tf b/main.tf index 7522ca9..ce0da6c 100644 --- a/main.tf +++ b/main.tf @@ -28,7 +28,7 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { annotations = var.deployment_annotations } spec { - service_account_name = kubernetes_service_account.service_account.0.metadata.0.name + service_account_name = kubernetes_service_account.service_account.0.metadata.0.name automount_service_account_token = true container { image = var.agent_image diff --git a/variables.tf b/variables.tf index 3c9dae2..b92f3e9 100644 --- a/variables.tf +++ b/variables.tf @@ -11,15 +11,15 @@ variable "kubernetes_namespace" { } variable "labels" { - type = map + type = map default = { - app = "tfc-agent" + app = "tfc-agent" } description = "Labels to apply to the Kubernetes deployment" } variable "selector_match_labels" { - type = map + type = map default = { app = "tfc-agent" } @@ -27,17 +27,23 @@ variable "selector_match_labels" { } variable "replicas" { - type = number - default = 1 + type = number + default = 1 description = "Number of replicas in the Kubernetes deployment" } variable "annotations" { - type = map - default = {} + type = map + default = {} description = "Annotations to add to the Kubernetes deployment" } +variable "service_annotations" { + type = map + default = {} + description = "Annotations to add to the Kubernetes service account" +} + variable "agent_image" { type = string default = "hashicorp/tfc-agent:latest" From 688b455ddf0649678342a523a1df1d852b602fc1 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 11:12:53 -0700 Subject: [PATCH 19/43] Fixing a couple more things --- variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index b92f3e9..6101dc9 100644 --- a/variables.tf +++ b/variables.tf @@ -32,13 +32,13 @@ variable "replicas" { description = "Number of replicas in the Kubernetes deployment" } -variable "annotations" { +variable "deployment_annotations" { type = map default = {} description = "Annotations to add to the Kubernetes deployment" } -variable "service_annotations" { +variable "service_account_annotations" { type = map default = {} description = "Annotations to add to the Kubernetes service account" From a50c7c222f151b6dc55025e5f2cb23442e953fd9 Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 17:53:53 -0700 Subject: [PATCH 20/43] Update README.yaml Co-authored-by: Erik Osterman --- README.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.yaml b/README.yaml index 80b0b4c..c780024 100644 --- a/README.yaml +++ b/README.yaml @@ -75,7 +75,8 @@ usage: |- environment = var.environment name = var.name - kubernetes_namespace = "tfc-agent" # You can specify a namespace other than "default" + # You can specify a namespace other than "default" + kubernetes_namespace = "tfc-agent" } ``` From 6e761c80280e5c0187eb48ba06a500393c8f1126 Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 17:54:04 -0700 Subject: [PATCH 21/43] Update README.yaml Co-authored-by: Erik Osterman --- README.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.yaml b/README.yaml index c780024..6499cb4 100644 --- a/README.yaml +++ b/README.yaml @@ -69,7 +69,8 @@ usage: |- module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" - token = var.token # Your agent token generated in Terraform Cloud + # Your agent token generated in Terraform Cloud + token = var.token namespace = var.namespace stage = var.stage environment = var.environment From 32d8e3c70bfcef551243af071ce61f9f8cb03fce Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 17:54:39 -0700 Subject: [PATCH 22/43] Update README.yaml Co-authored-by: Erik Osterman --- README.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.yaml b/README.yaml index 6499cb4..517ec4f 100644 --- a/README.yaml +++ b/README.yaml @@ -61,7 +61,7 @@ usage: |- ```hcl provider "kubernetes" { - #Context to choose from the config file, if needed. + # Context to choose from the config file, if needed. config_context = "example-context" version = "~> 1.12" } From 1b59473afbea2738a72e0cff10fbafb2b9503736 Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 17:59:09 -0700 Subject: [PATCH 23/43] Update variables.tf Co-authored-by: Erik Osterman --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 6101dc9..a8391e7 100644 --- a/variables.tf +++ b/variables.tf @@ -65,7 +65,7 @@ variable "resource_limits_cpu" { variable "resource_limits_memory" { type = string default = "512Mi" - description = "Kubernetes deployment resource memory limit" + description = "Kubernetes deployment resource hard memory limit" } variable "resource_requests_cpu" { From d1b1ec72db7c3dbc8f1901afe9df826d8ce4f09f Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 17:59:21 -0700 Subject: [PATCH 24/43] Update variables.tf Co-authored-by: Erik Osterman --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index a8391e7..8b65c3c 100644 --- a/variables.tf +++ b/variables.tf @@ -59,7 +59,7 @@ variable "token" { variable "resource_limits_cpu" { type = string default = "1" - description = "Kubernetes deployment resource CPU limit" + description = "Kubernetes deployment resource hard CPU limit" } variable "resource_limits_memory" { From e78a4d4c53204995e4b9caa09d0354b3ac5a28a1 Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 18:00:52 -0700 Subject: [PATCH 25/43] Update README.yaml Co-authored-by: Erik Osterman --- README.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.yaml b/README.yaml index 517ec4f..9e9be30 100644 --- a/README.yaml +++ b/README.yaml @@ -55,6 +55,8 @@ references: # Short description of this project description: |- This project installed the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! + + NOTE: Requires [Terraform Cloud Business or Terraform Enterprise](https://www.hashicorp.com/products/terraform/pricing) subscription. # How to use this module. Should be an easy example to copy and paste. usage: |- From b5c1be0afd06218310c73a4b7629466b20202d11 Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 18:27:29 -0700 Subject: [PATCH 26/43] Update main.tf Co-authored-by: Erik Osterman --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index ce0da6c..6fb3655 100644 --- a/main.tf +++ b/main.tf @@ -2,7 +2,7 @@ resource "kubernetes_service_account" "service_account" { count = module.this.enabled ? 1 : 0 metadata { - name = var.deployment_name + name = coalesce(var.deployment_name, module.this.id) namespace = var.kubernetes_namespace annotations = var.service_account_annotations } @@ -55,4 +55,4 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { } } } -} \ No newline at end of file +} From 5232a60b5b48affed1759856753acc0dc826e1eb Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 18:58:31 -0700 Subject: [PATCH 27/43] Making a bunch of updates --- README.md | 29 +++++++++++++---- README.yaml | 15 +++++++-- docs/terraform.md | 16 ++++++--- examples/complete/main.tf | 2 +- main.tf | 36 ++++++++++++++++----- variables.tf | 68 +++++++++++++++++++++++++++++++-------- 6 files changed, 129 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 2954e44..59e6378 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ This project installed the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! +NOTE: Requires [Terraform Cloud Business or Terraform Enterprise](https://www.hashicorp.com/products/terraform/pricing) subscription. + --- @@ -71,7 +73,7 @@ Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest re ```hcl provider "kubernetes" { - #Context to choose from the config file, if needed. + # Context to choose from the config file, if needed. config_context = "example-context" version = "~> 1.12" } @@ -79,13 +81,15 @@ provider "kubernetes" { module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" - token = var.token # Your agent token generated in Terraform Cloud + # Your agent token generated in Terraform Cloud + token = var.token namespace = var.namespace stage = var.stage environment = var.environment name = var.name - kubernetes_namespace = "tfc-agent" # You can specify a namespace other than "default" + # You can specify a namespace other than "default" + kubernetes_namespace = "tfc-agent" } ``` @@ -135,22 +139,30 @@ Available targets: | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | | deployment\_annotations | Annotations to add to the Kubernetes deployment | `map` | `{}` | no | -| deployment\_name | Name of the deployment in Kubernetes | `string` | `"tfc-agent"` | no | +| deployment\_name | Override the deployment name in Kubernetes | `string` | `null` | no | | enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | -| kubernetes\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | +| kubernetes\_namespace | Kubernetes namespace override | `string` | `null` | no | | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | -| labels | Labels to apply to the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | | namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | | regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | | replicas | Number of replicas in the Kubernetes deployment | `number` | `1` | no | +| resource\_limits\_cpu | Kubernetes deployment resource hard CPU limit | `string` | `"1"` | no | +| resource\_limits\_memory | Kubernetes deployment resource hard memory limit | `string` | `"512Mi"` | no | +| resource\_requests\_cpu | Kubernetes deployment resource CPU requests | `string` | `"250m"` | no | +| resource\_requests\_memory | Kubernetes deployment resource memory requests | `string` | `"50Mi"` | no | | selector\_match\_labels | Selector labels to match on the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | service\_account\_annotations | Annotations to add to the Kubernetes service account | `map` | `{}` | no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | -| token | The agent token, as configured in Terraform Cloud | `string` | `""` | no | +| tfc\_address | The HTTP or HTTPS address of the Terraform Cloud API. | `string` | `"https://app.terraform.io"` | no | +| tfc\_agent\_data\_dir | The path to a directory to store all agent-related data, including
Terraform configurations, cached Terraform release archives, etc. It is
important to ensure that the given directory is backed by plentiful
storage. | `string` | `"~/.tfc-agent"` | no | +| tfc\_agent\_disable\_update | Disable automatic core updates. | `bool` | `false` | no | +| tfc\_agent\_log\_level | The log verbosity expressed as a level string. Level options include
"trace", "debug", "info", "warn", and "error" | `string` | `"info"` | no | +| tfc\_agent\_single | Enable single mode. This causes the agent to handle at most one job and
immediately exit thereafter. Useful for running agents as ephemeral
containers, VMs, or other isolated contexts with a higher-level scheduler
or process supervisor. | `bool` | `false` | no | +| tfc\_agent\_token | The agent token to use when making requests to the Terraform Cloud API.
This token must be obtained from the API or UI. It is recommended to use
the environment variable whenever possible for configuring this setting due
to the sensitive nature of API tokens. | `string` | `""` | no | ## Outputs @@ -183,6 +195,9 @@ For additional context, refer to some of these links. - [Terraform Standard Module Structure](https://www.terraform.io/docs/modules/index.html#standard-module-structure) - HashiCorp's standard module structure is a file and directory layout we recommend for reusable modules distributed in separate repositories. - [Terraform Module Requirements](https://www.terraform.io/docs/registry/modules/publish.html#requirements) - HashiCorp's guidance on all the requirements for publishing a module. Meeting the requirements for publishing a module is extremely easy. - [Terraform Version Pinning](https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version) - The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration +- [Terraform Cloud Agents](https://www.terraform.io/docs/cloud/workspaces/agent.html) - Terraform Cloud Agents are a solution to allow Terraform Cloud to communicate with isolated, private, or on-premises infrastructure. +- [Announcing HashiCorp Terraform Cloud Business Tier](https://www.hashicorp.com/blog/announcing-hashicorp-terraform-cloud-business) - This new tier includes enterprise features for advanced security, compliance and governance, the ability to execute multiple runs concurrently, and flexible support options. +- [Announcing Terraform Cloud Business Tier with Armon Dadgar](https://www.hashicorp.com/resources/announcing-terraform-cloud-business-tier-with-armon-dadgar) - Watch HashiCorp co-founder and CTO Armon Dadgar announce the latest addition to Terraform Cloud: the new Business tier. ## Help diff --git a/README.yaml b/README.yaml index 9e9be30..a204601 100644 --- a/README.yaml +++ b/README.yaml @@ -51,12 +51,21 @@ references: - name: "Terraform Version Pinning" description: "The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration" url: "https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version" + - name: "Terraform Cloud Agents" + description: "Terraform Cloud Agents are a solution to allow Terraform Cloud to communicate with isolated, private, or on-premises infrastructure." + url: "https://www.terraform.io/docs/cloud/workspaces/agent.html" + - name: "Announcing HashiCorp Terraform Cloud Business Tier" + description: "This new tier includes enterprise features for advanced security, compliance and governance, the ability to execute multiple runs concurrently, and flexible support options." + url: "https://www.hashicorp.com/blog/announcing-hashicorp-terraform-cloud-business" + - name: "Announcing Terraform Cloud Business Tier with Armon Dadgar" + description: "Watch HashiCorp co-founder and CTO Armon Dadgar announce the latest addition to Terraform Cloud: the new Business tier." + url: "https://www.hashicorp.com/resources/announcing-terraform-cloud-business-tier-with-armon-dadgar" # Short description of this project description: |- This project installed the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! - NOTE: Requires [Terraform Cloud Business or Terraform Enterprise](https://www.hashicorp.com/products/terraform/pricing) subscription. + NOTE: Requires [Terraform Cloud Business or Terraform Enterprise](https://www.hashicorp.com/products/terraform/pricing) subscription. # How to use this module. Should be an easy example to copy and paste. usage: |- @@ -72,14 +81,14 @@ usage: |- source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" # Your agent token generated in Terraform Cloud - token = var.token + token = var.tcf_agent_token namespace = var.namespace stage = var.stage environment = var.environment name = var.name # You can specify a namespace other than "default" - kubernetes_namespace = "tfc-agent" + kubernetes_namespace = "tfc-agent" } ``` diff --git a/docs/terraform.md b/docs/terraform.md index 12c6b33..841d86a 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -22,22 +22,30 @@ | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | | deployment\_annotations | Annotations to add to the Kubernetes deployment | `map` | `{}` | no | -| deployment\_name | Name of the deployment in Kubernetes | `string` | `"tfc-agent"` | no | +| deployment\_name | Override the deployment name in Kubernetes | `string` | `null` | no | | enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | | id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | -| kubernetes\_namespace | Kubernetes namespace to deploy agent within | `string` | `"default"` | no | +| kubernetes\_namespace | Kubernetes namespace override | `string` | `null` | no | | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | -| labels | Labels to apply to the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | | namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | | regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | | replicas | Number of replicas in the Kubernetes deployment | `number` | `1` | no | +| resource\_limits\_cpu | Kubernetes deployment resource hard CPU limit | `string` | `"1"` | no | +| resource\_limits\_memory | Kubernetes deployment resource hard memory limit | `string` | `"512Mi"` | no | +| resource\_requests\_cpu | Kubernetes deployment resource CPU requests | `string` | `"250m"` | no | +| resource\_requests\_memory | Kubernetes deployment resource memory requests | `string` | `"50Mi"` | no | | selector\_match\_labels | Selector labels to match on the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | service\_account\_annotations | Annotations to add to the Kubernetes service account | `map` | `{}` | no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | -| token | The agent token, as configured in Terraform Cloud | `string` | `""` | no | +| tfc\_address | The HTTP or HTTPS address of the Terraform Cloud API. | `string` | `"https://app.terraform.io"` | no | +| tfc\_agent\_data\_dir | The path to a directory to store all agent-related data, including
Terraform configurations, cached Terraform release archives, etc. It is
important to ensure that the given directory is backed by plentiful
storage. | `string` | `"~/.tfc-agent"` | no | +| tfc\_agent\_disable\_update | Disable automatic core updates. | `bool` | `false` | no | +| tfc\_agent\_log\_level | The log verbosity expressed as a level string. Level options include
"trace", "debug", "info", "warn", and "error" | `string` | `"info"` | no | +| tfc\_agent\_single | Enable single mode. This causes the agent to handle at most one job and
immediately exit thereafter. Useful for running agents as ephemeral
containers, VMs, or other isolated contexts with a higher-level scheduler
or process supervisor. | `bool` | `false` | no | +| tfc\_agent\_token | The agent token to use when making requests to the Terraform Cloud API.
This token must be obtained from the API or UI. It is recommended to use
the environment variable whenever possible for configuring this setting due
to the sensitive nature of API tokens. | `string` | `""` | no | ## Outputs diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 9d781d3..a959fdd 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -6,6 +6,6 @@ module "tfc_agent" { source = "../.." context = module.this.context - token = var.token + token = var.tfc_agent_token } diff --git a/main.tf b/main.tf index ce0da6c..e996ef5 100644 --- a/main.tf +++ b/main.tf @@ -2,8 +2,8 @@ resource "kubernetes_service_account" "service_account" { count = module.this.enabled ? 1 : 0 metadata { - name = var.deployment_name - namespace = var.kubernetes_namespace + name = coalesce(var.deployment_name, module.this.id, "tfc-agent") + namespace = coalesce(var.kubernetes_namespace, var.namespace, "default") annotations = var.service_account_annotations } } @@ -12,9 +12,9 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { count = module.this.enabled ? 1 : 0 metadata { - name = var.deployment_name - namespace = var.kubernetes_namespace - labels = var.labels + name = coalesce(var.deployment_name, module.this.id, "tfc-agent") + namespace = coalesce(var.kubernetes_namespace, var.namespace, "default") + labels = module.this.tags } spec { selector { @@ -24,7 +24,7 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { template { metadata { - labels = var.labels + labels = module.this.tags annotations = var.deployment_annotations } spec { @@ -35,11 +35,31 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { name = "tfc-agent" env { name = "TFC_AGENT_TOKEN" - value = var.token + value = var.tfc_agent_token } env { name = "TFC_AGENT_NAME" - value = module.this.id + value = coalesce(module.this.id, "tfc-agent") + } + env { + name = "TFC_AGENT_LOG_LEVEL" + value = var.tfc_agent_log_level + } + env { + name = "TFC_AGENT_DATA_DIR" + value = var.tfc_agent_data_dir + } + env { + name = "TFC_AGENT_SINGLE" + value = var.tfc_agent_single + } + env { + name = "TFC_AGENT_DISABLE_UPDATE" + value = var.tfc_agent_disable_update + } + env { + name = "TFC_ADDRESS" + value = var.tfc_address } resources { limits { diff --git a/variables.tf b/variables.tf index 8b65c3c..6af3384 100644 --- a/variables.tf +++ b/variables.tf @@ -1,21 +1,13 @@ variable "deployment_name" { type = string - default = "tfc-agent" - description = "Name of the deployment in Kubernetes" + default = null + description = "Override the deployment name in Kubernetes" } variable "kubernetes_namespace" { type = string - default = "default" - description = "Kubernetes namespace to deploy agent within" -} - -variable "labels" { - type = map - default = { - app = "tfc-agent" - } - description = "Labels to apply to the Kubernetes deployment" + default = null + description = "Kubernetes namespace override" } variable "selector_match_labels" { @@ -50,10 +42,58 @@ variable "agent_image" { description = "Name and tag of Terraform Cloud Agent docker image" } -variable "token" { +variable "tfc_agent_token" { type = string default = "" - description = "The agent token, as configured in Terraform Cloud" + description = < Date: Thu, 8 Oct 2020 18:58:44 -0700 Subject: [PATCH 28/43] Fixing a formatting thing --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index e996ef5..8683f86 100644 --- a/main.tf +++ b/main.tf @@ -2,8 +2,8 @@ resource "kubernetes_service_account" "service_account" { count = module.this.enabled ? 1 : 0 metadata { - name = coalesce(var.deployment_name, module.this.id, "tfc-agent") - namespace = coalesce(var.kubernetes_namespace, var.namespace, "default") + name = coalesce(var.deployment_name, module.this.id, "tfc-agent") + namespace = coalesce(var.kubernetes_namespace, var.namespace, "default") annotations = var.service_account_annotations } } From 3a8d0f84f1248155544b0a668fc7c1fb29267868 Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 19:00:58 -0700 Subject: [PATCH 29/43] Update README.md Co-authored-by: Erik Osterman --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2954e44..0e40143 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ --> -This project installed the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! +This project installs the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! --- From 3d523d460a161209a6d2a69a37dafa1d8034ff82 Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 19:01:12 -0700 Subject: [PATCH 30/43] Update README.md Co-authored-by: Erik Osterman --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e40143..37b68aa 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest re ```hcl provider "kubernetes" { - #Context to choose from the config file, if needed. + # Context to choose from the config file, if needed. config_context = "example-context" version = "~> 1.12" } From 7253bd0fe3d02447724a340ed506f672f2131d21 Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Thu, 8 Oct 2020 19:01:21 -0700 Subject: [PATCH 31/43] Update README.yaml Co-authored-by: Erik Osterman --- README.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.yaml b/README.yaml index 9e9be30..c59da78 100644 --- a/README.yaml +++ b/README.yaml @@ -54,7 +54,7 @@ references: # Short description of this project description: |- - This project installed the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! + This project installs the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! NOTE: Requires [Terraform Cloud Business or Terraform Enterprise](https://www.hashicorp.com/products/terraform/pricing) subscription. From 51bd8e2397dd85e809a31af47b2f8b0aaab777d8 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 19:02:47 -0700 Subject: [PATCH 32/43] Updating README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 496c0c4..af1c8ce 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ This project installs the Terraform Cloud Agent on an existing Kubernetes cluster. You must provide your own Kubernetes provider configuration in your project! -NOTE: Requires [Terraform Cloud Business or Terraform Enterprise](https://www.hashicorp.com/products/terraform/pricing) subscription. +NOTE: Requires [Terraform Cloud Business or Terraform Enterprise](https://www.hashicorp.com/products/terraform/pricing) subscription. --- @@ -82,14 +82,14 @@ module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" # Your agent token generated in Terraform Cloud - token = var.token + token = var.tcf_agent_token namespace = var.namespace stage = var.stage environment = var.environment name = var.name # You can specify a namespace other than "default" - kubernetes_namespace = "tfc-agent" + kubernetes_namespace = "tfc-agent" } ``` From 20757f5a6cf054e9b5d04c5fe8a25cfc9ef1c5f7 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Thu, 8 Oct 2020 19:39:30 -0700 Subject: [PATCH 33/43] A few more updates --- examples/complete/main.tf | 6 +++--- examples/complete/variables.tf | 2 +- main.tf | 2 +- variables.tf | 8 -------- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index a959fdd..fc7aeb3 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -3,9 +3,9 @@ provider "kubernetes" { } module "tfc_agent" { - source = "../.." - + source = "../.." context = module.this.context - token = var.tfc_agent_token + + tfc_agent_token = var.tfc_agent_token } diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index d6fde69..c9aa9df 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -1,4 +1,4 @@ -variable "token" { +variable "tfc_agent_token" { type = string description = "The preconfigured Terraform Cloud Agent token" } diff --git a/main.tf b/main.tf index ac4f2c2..4858183 100644 --- a/main.tf +++ b/main.tf @@ -18,7 +18,7 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { } spec { selector { - match_labels = var.selector_match_labels + match_labels = module.this.tags } replicas = var.replicas diff --git a/variables.tf b/variables.tf index 6af3384..a40b760 100644 --- a/variables.tf +++ b/variables.tf @@ -10,14 +10,6 @@ variable "kubernetes_namespace" { description = "Kubernetes namespace override" } -variable "selector_match_labels" { - type = map - default = { - app = "tfc-agent" - } - description = "Selector labels to match on the Kubernetes deployment" -} - variable "replicas" { type = number default = 1 From c26d487f44050a22c9490925d00f00880e05a61e Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Fri, 9 Oct 2020 13:43:31 -0700 Subject: [PATCH 34/43] Adding support for agent CLI arguments --- examples/complete/fixtures.tfvars | 1 - main.tf | 1 + variables.tf | 6 ++++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/complete/fixtures.tfvars b/examples/complete/fixtures.tfvars index 48d6180..4fa9294 100644 --- a/examples/complete/fixtures.tfvars +++ b/examples/complete/fixtures.tfvars @@ -5,4 +5,3 @@ environment = "ue2" stage = "test" name = "example" - diff --git a/main.tf b/main.tf index 4858183..9ba641b 100644 --- a/main.tf +++ b/main.tf @@ -33,6 +33,7 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { container { image = var.agent_image name = "tfc-agent" + args = var.agent_cli_args env { name = "TFC_AGENT_TOKEN" value = var.tfc_agent_token diff --git a/variables.tf b/variables.tf index a40b760..cded8d5 100644 --- a/variables.tf +++ b/variables.tf @@ -34,6 +34,12 @@ variable "agent_image" { description = "Name and tag of Terraform Cloud Agent docker image" } +variable "agent_cli_args" { + type = list + default = [] + description = "Extra command line arguments to pass to tfc-agent" +} + variable "tfc_agent_token" { type = string default = "" From 8b96ccd7bcaa12f9d02cf48deef7ac86a8f644e7 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Fri, 9 Oct 2020 15:09:38 -0700 Subject: [PATCH 35/43] Cleaning up namespace/service_account stuff and adding outputs --- examples/complete/main.tf | 1 - examples/complete/outputs.tf | 7 +++++++ main.tf | 15 +++++++++++---- outputs.tf | 7 +++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index fc7aeb3..4fa2d9c 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -8,4 +8,3 @@ module "tfc_agent" { tfc_agent_token = var.tfc_agent_token } - diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf index e69de29..5120ba5 100644 --- a/examples/complete/outputs.tf +++ b/examples/complete/outputs.tf @@ -0,0 +1,7 @@ +output "service_account_name" { + value = module.tfc_agent.service_account_name +} + +output "namespace" { + value = module.tfc_agent.namespace +} \ No newline at end of file diff --git a/main.tf b/main.tf index 9ba641b..deaf371 100644 --- a/main.tf +++ b/main.tf @@ -1,9 +1,15 @@ +locals { + service_account_name = coalesce(var.deployment_name, module.this.id, "tfc-agent") + + namespace = coalesce(var.kubernetes_namespace, module.this.namespace, "default") +} + resource "kubernetes_service_account" "service_account" { count = module.this.enabled ? 1 : 0 metadata { - name = coalesce(var.deployment_name, module.this.id, "tfc-agent") - namespace = coalesce(var.kubernetes_namespace, var.namespace, "default") + name = local.service_account_name + namespace = local.namespace annotations = var.service_account_annotations } } @@ -13,7 +19,7 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { metadata { name = coalesce(var.deployment_name, module.this.id, "tfc-agent") - namespace = coalesce(var.kubernetes_namespace, var.namespace, "default") + namespace = local.namespace labels = module.this.tags } spec { @@ -24,11 +30,12 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { template { metadata { + namespace = local.namespace labels = module.this.tags annotations = var.deployment_annotations } spec { - service_account_name = kubernetes_service_account.service_account.0.metadata.0.name + service_account_name = local.service_account_name automount_service_account_token = true container { image = var.agent_image diff --git a/outputs.tf b/outputs.tf index e69de29..f91d36c 100644 --- a/outputs.tf +++ b/outputs.tf @@ -0,0 +1,7 @@ +output "service_account_name" { + value = local.service_account_name +} + +output "namespace" { + value = local.service_account_name +} From 7b4dd6765b2c9660578d7b089130d3dbb6178f2c Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Fri, 9 Oct 2020 16:06:06 -0700 Subject: [PATCH 36/43] Lots of updates --- README.md | 77 +++++++++++++++++++----------------- README.yaml | 12 +++--- docs/terraform.md | 9 ++++- examples/complete/main.tf | 5 ++- examples/complete/outputs.tf | 4 +- main.tf | 39 ++++++++++++++++-- outputs.tf | 4 +- variables.tf | 12 ++++++ 8 files changed, 109 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index af1c8ce..d2c12ec 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# terraform-kubernetes-tfe-cloud-agent +# terraform-kubernetes-tfc-cloud-agent - [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfe-cloud-agent.svg)](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) [![Discourse Forum](https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg)](https://ask.sweetops.com/) + [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfc-cloud-agent.svg)](https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) [![Discourse Forum](https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg)](https://ask.sweetops.com/) [![README Header][readme_header_img]][readme_header_link] @@ -67,7 +67,7 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are **IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases. -Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/releases). +Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent/releases). @@ -79,7 +79,7 @@ provider "kubernetes" { } module "tfc_agent" { - source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" + source = "https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent.git?ref=master" # Your agent token generated in Terraform Cloud token = var.tcf_agent_token @@ -99,7 +99,7 @@ module "tfc_agent" { ## Examples Here is an example of using this module: -- [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/) - complete example of using this module +- [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent/) - complete example of using this module @@ -134,6 +134,7 @@ Available targets: | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | +| agent\_cli\_args | Extra command line arguments to pass to tfc-agent | `list` | `[]` | no | | agent\_image | Name and tag of Terraform Cloud Agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | @@ -147,13 +148,13 @@ Available targets: | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | | namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | +| namespace\_creation\_enabled | Enable this if the Kubernetes namespace does not already exist | `bool` | `false` | no | | regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | | replicas | Number of replicas in the Kubernetes deployment | `number` | `1` | no | | resource\_limits\_cpu | Kubernetes deployment resource hard CPU limit | `string` | `"1"` | no | | resource\_limits\_memory | Kubernetes deployment resource hard memory limit | `string` | `"512Mi"` | no | | resource\_requests\_cpu | Kubernetes deployment resource CPU requests | `string` | `"250m"` | no | | resource\_requests\_memory | Kubernetes deployment resource memory requests | `string` | `"50Mi"` | no | -| selector\_match\_labels | Selector labels to match on the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | service\_account\_annotations | Annotations to add to the Kubernetes service account | `map` | `{}` | no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | @@ -163,10 +164,14 @@ Available targets: | tfc\_agent\_log\_level | The log verbosity expressed as a level string. Level options include
"trace", "debug", "info", "warn", and "error" | `string` | `"info"` | no | | tfc\_agent\_single | Enable single mode. This causes the agent to handle at most one job and
immediately exit thereafter. Useful for running agents as ephemeral
containers, VMs, or other isolated contexts with a higher-level scheduler
or process supervisor. | `bool` | `false` | no | | tfc\_agent\_token | The agent token to use when making requests to the Terraform Cloud API.
This token must be obtained from the API or UI. It is recommended to use
the environment variable whenever possible for configuring this setting due
to the sensitive nature of API tokens. | `string` | `""` | no | +| tfc\_extra\_envs | A map of any extra environment variables to pass to the TFC agent | `map` | `{}` | no | ## Outputs -No output. +| Name | Description | +|------|-------------| +| namespace | n/a | +| service\_account\_name | n/a | @@ -174,7 +179,7 @@ No output. ## Share the Love -Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent)! (it helps us **a lot**) +Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent)! (it helps us **a lot**) Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =) @@ -204,7 +209,7 @@ For additional context, refer to some of these links. **Got a question?** We got answers. -File a GitHub [issue](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/issues), send us an [email][email] or join our [Slack Community][slack]. +File a GitHub [issue](https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent/issues), send us an [email][email] or join our [Slack Community][slack]. [![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link] @@ -252,7 +257,7 @@ Sign up for [our newsletter][newsletter] that covers everything on our technolog ### Bug Reports & Feature Requests -Please use the [issue tracker](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/issues) to report any bugs or file feature requests. +Please use the [issue tracker](https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent/issues) to report any bugs or file feature requests. ### Developing @@ -341,32 +346,32 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply [![Beacon][beacon]][website] [logo]: https://cloudposse.com/logo-300x69.svg - [docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=docs - [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=website - [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=github - [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=jobs - [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=hire - [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=slack - [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=linkedin - [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=twitter - [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=testimonial - [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=office_hours - [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=newsletter - [discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=discourse - [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=email - [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&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-kubernetes-tfe-cloud-agent&utm_content=we_love_open_source - [terraform_modules]: https://cpco.io/terraform-modules?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfe-cloud-agent&utm_content=terraform_modules + [docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=docs + [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=website + [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=github + [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=jobs + [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=hire + [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=slack + [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=linkedin + [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=twitter + [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=testimonial + [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=office_hours + [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=newsletter + [discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=discourse + [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=email + [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&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-kubernetes-tfc-cloud-agent&utm_content=we_love_open_source + [terraform_modules]: https://cpco.io/terraform-modules?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&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-kubernetes-tfe-cloud-agent&utm_content=readme_header_link + [readme_header_link]: https://cloudposse.com/readme/header/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&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-kubernetes-tfe-cloud-agent&utm_content=readme_footer_link + [readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&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-kubernetes-tfe-cloud-agent&utm_content=readme_commercial_support_link - [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-kubernetes-tfe-cloud-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent - [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-kubernetes-tfe-cloud-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent - [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent - [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent - [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent - [share_email]: mailto:?subject=terraform-kubernetes-tfe-cloud-agent&body=https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent - [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-kubernetes-tfe-cloud-agent?pixel&cs=github&cm=readme&an=terraform-kubernetes-tfe-cloud-agent + [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-kubernetes-tfc-cloud-agent&utm_content=readme_commercial_support_link + [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-kubernetes-tfc-cloud-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent + [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-kubernetes-tfc-cloud-agent&url=https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent + [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent + [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent + [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent + [share_email]: mailto:?subject=terraform-kubernetes-tfc-cloud-agent&body=https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent + [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-kubernetes-tfc-cloud-agent?pixel&cs=github&cm=readme&an=terraform-kubernetes-tfc-cloud-agent diff --git a/README.yaml b/README.yaml index 09a28cc..3164fbb 100644 --- a/README.yaml +++ b/README.yaml @@ -5,7 +5,7 @@ # # Name of this project -name: terraform-kubernetes-tfe-cloud-agent +name: terraform-kubernetes-tfc-cloud-agent # Logo for this project #logo: docs/logo.png @@ -20,13 +20,13 @@ copyrights: year: "2020" # Canonical GitHub repo -github_repo: cloudposse/terraform-kubernetes-tfe-cloud-agent +github_repo: cloudposse/terraform-kubernetes-tfc-cloud-agent # Badges to display badges: - name: "Latest Release" - image: "https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfe-cloud-agent.svg" - url: "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/releases/latest" + image: "https://img.shields.io/github/release/cloudposse/terraform-kubernetes-tfc-cloud-agent.svg" + url: "https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent/releases/latest" - name: "Slack Community" image: "https://slack.cloudposse.com/badge.svg" url: "https://slack.cloudposse.com" @@ -78,7 +78,7 @@ usage: |- } module "tfc_agent" { - source = "https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent.git?ref=master" + source = "https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent.git?ref=master" # Your agent token generated in Terraform Cloud token = var.tcf_agent_token @@ -95,7 +95,7 @@ usage: |- # Example usage examples: |- Here is an example of using this module: - - [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfe-cloud-agent/) - complete example of using this module + - [`examples/complete`](https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent/) - complete example of using this module # Other files to include in this README from the project folder include: diff --git a/docs/terraform.md b/docs/terraform.md index 841d86a..084d947 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -17,6 +17,7 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | +| agent\_cli\_args | Extra command line arguments to pass to tfc-agent | `list` | `[]` | no | | agent\_image | Name and tag of Terraform Cloud Agent docker image | `string` | `"hashicorp/tfc-agent:latest"` | no | | attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | @@ -30,13 +31,13 @@ | label\_order | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | | name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | | namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | +| namespace\_creation\_enabled | Enable this if the Kubernetes namespace does not already exist | `bool` | `false` | no | | regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | | replicas | Number of replicas in the Kubernetes deployment | `number` | `1` | no | | resource\_limits\_cpu | Kubernetes deployment resource hard CPU limit | `string` | `"1"` | no | | resource\_limits\_memory | Kubernetes deployment resource hard memory limit | `string` | `"512Mi"` | no | | resource\_requests\_cpu | Kubernetes deployment resource CPU requests | `string` | `"250m"` | no | | resource\_requests\_memory | Kubernetes deployment resource memory requests | `string` | `"50Mi"` | no | -| selector\_match\_labels | Selector labels to match on the Kubernetes deployment | `map` |
{
"app": "tfc-agent"
}
| no | | service\_account\_annotations | Annotations to add to the Kubernetes service account | `map` | `{}` | no | | stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | @@ -46,9 +47,13 @@ | tfc\_agent\_log\_level | The log verbosity expressed as a level string. Level options include
"trace", "debug", "info", "warn", and "error" | `string` | `"info"` | no | | tfc\_agent\_single | Enable single mode. This causes the agent to handle at most one job and
immediately exit thereafter. Useful for running agents as ephemeral
containers, VMs, or other isolated contexts with a higher-level scheduler
or process supervisor. | `bool` | `false` | no | | tfc\_agent\_token | The agent token to use when making requests to the Terraform Cloud API.
This token must be obtained from the API or UI. It is recommended to use
the environment variable whenever possible for configuring this setting due
to the sensitive nature of API tokens. | `string` | `""` | no | +| tfc\_extra\_envs | A map of any extra environment variables to pass to the TFC agent | `map` | `{}` | no | ## Outputs -No output. +| Name | Description | +|------|-------------| +| namespace | n/a | +| service\_account\_name | n/a | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 4fa2d9c..995da42 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -1,5 +1,5 @@ provider "kubernetes" { - version = "~> 1.12" + version = "~> 1.12" } module "tfc_agent" { @@ -7,4 +7,7 @@ module "tfc_agent" { context = module.this.context tfc_agent_token = var.tfc_agent_token + + namespace_creation_enabled = true + kubernetes_namespace = "foo" } diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf index 5120ba5..744c3ca 100644 --- a/examples/complete/outputs.tf +++ b/examples/complete/outputs.tf @@ -1,7 +1,7 @@ output "service_account_name" { - value = module.tfc_agent.service_account_name + value = module.tfc_agent.service_account_name } output "namespace" { - value = module.tfc_agent.namespace + value = module.tfc_agent.namespace } \ No newline at end of file diff --git a/main.tf b/main.tf index deaf371..8ac870d 100644 --- a/main.tf +++ b/main.tf @@ -1,7 +1,15 @@ locals { service_account_name = coalesce(var.deployment_name, module.this.id, "tfc-agent") + deployment_name = coalesce(var.deployment_name, module.this.id, "tfc-agent") - namespace = coalesce(var.kubernetes_namespace, module.this.namespace, "default") + namespace = coalesce(var.kubernetes_namespace, "default") +} + +resource "kubernetes_namespace" "namespace" { + count = var.namespace_creation_enabled ? 1 : 0 + metadata { + name = local.namespace + } } resource "kubernetes_service_account" "service_account" { @@ -14,11 +22,22 @@ resource "kubernetes_service_account" "service_account" { } } +resource "kubernetes_secret" "secret" { + metadata { + name = local.deployment_name + namespace = local.namespace + } + + data = { + token = var.tfc_agent_token + } +} + resource "kubernetes_deployment" "tfc_cloud_agent" { count = module.this.enabled ? 1 : 0 metadata { - name = coalesce(var.deployment_name, module.this.id, "tfc-agent") + name = local.deployment_name namespace = local.namespace labels = module.this.tags } @@ -42,8 +61,13 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { name = "tfc-agent" args = var.agent_cli_args env { - name = "TFC_AGENT_TOKEN" - value = var.tfc_agent_token + name = "TFC_AGENT_TOKEN" + value_from { + secret_key_ref { + key = "token" + name = local.deployment_name + } + } } env { name = "TFC_AGENT_NAME" @@ -69,6 +93,13 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { name = "TFC_ADDRESS" value = var.tfc_address } + dynamic "env" { + for_each = var.tfc_extra_envs + content { + name = env.key + value = env.value + } + } resources { limits { cpu = var.resource_limits_cpu diff --git a/outputs.tf b/outputs.tf index f91d36c..ea576f7 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1,7 @@ output "service_account_name" { - value = local.service_account_name + value = local.service_account_name } output "namespace" { - value = local.service_account_name + value = local.service_account_name } diff --git a/variables.tf b/variables.tf index cded8d5..bc76610 100644 --- a/variables.tf +++ b/variables.tf @@ -10,6 +10,12 @@ variable "kubernetes_namespace" { description = "Kubernetes namespace override" } +variable "namespace_creation_enabled" { + type = bool + default = false + description = "Enable this if the Kubernetes namespace does not already exist" +} + variable "replicas" { type = number default = 1 @@ -94,6 +100,12 @@ variable "tfc_address" { description = "The HTTP or HTTPS address of the Terraform Cloud API." } +variable "tfc_extra_envs" { + type = map + default = {} + description = "A map of any extra environment variables to pass to the TFC agent" +} + variable "resource_limits_cpu" { type = string default = "1" From d075d0b64b4d4a48da6b2eb0466795a7d7b8aec7 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Tue, 13 Oct 2020 08:12:55 -0700 Subject: [PATCH 37/43] Updating README --- README.md | 2 +- README.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2c12ec..40e138a 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ module "tfc_agent" { source = "https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent.git?ref=master" # Your agent token generated in Terraform Cloud - token = var.tcf_agent_token + token = var.tfc_agent_token namespace = var.namespace stage = var.stage environment = var.environment diff --git a/README.yaml b/README.yaml index 3164fbb..daa3c15 100644 --- a/README.yaml +++ b/README.yaml @@ -81,7 +81,7 @@ usage: |- source = "https://github.com/cloudposse/terraform-kubernetes-tfc-cloud-agent.git?ref=master" # Your agent token generated in Terraform Cloud - token = var.tcf_agent_token + token = var.tfc_agent_token namespace = var.namespace stage = var.stage environment = var.environment From ea894089d288552da5a414ada688182db9299627 Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Tue, 13 Oct 2020 08:27:52 -0700 Subject: [PATCH 38/43] Fixing namespace output --- outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outputs.tf b/outputs.tf index ea576f7..bdd3611 100644 --- a/outputs.tf +++ b/outputs.tf @@ -3,5 +3,5 @@ output "service_account_name" { } output "namespace" { - value = local.service_account_name + value = local.namespace } From 476be3b61a6bdeaf23be2b5ab8d11e23d888b875 Mon Sep 17 00:00:00 2001 From: Dan Meyers <20687081+danjbh@users.noreply.github.com> Date: Tue, 13 Oct 2020 12:04:06 -0700 Subject: [PATCH 39/43] Fixing HEREDOC Co-authored-by: Erik Osterman --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index bc76610..fdc5326 100644 --- a/variables.tf +++ b/variables.tf @@ -69,7 +69,7 @@ variable "tfc_agent_log_level" { variable "tfc_agent_data_dir" { type = string default = "~/.tfc-agent" - description = < Date: Tue, 13 Oct 2020 12:04:31 -0700 Subject: [PATCH 40/43] Fixing HEREDOC Co-authored-by: Erik Osterman --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index fdc5326..df0678f 100644 --- a/variables.tf +++ b/variables.tf @@ -80,7 +80,7 @@ variable "tfc_agent_data_dir" { variable "tfc_agent_single" { type = bool default = false - description = < Date: Tue, 13 Oct 2020 12:05:49 -0700 Subject: [PATCH 41/43] Fixing more HEREDOC --- variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index df0678f..7945a58 100644 --- a/variables.tf +++ b/variables.tf @@ -49,7 +49,7 @@ variable "agent_cli_args" { variable "tfc_agent_token" { type = string default = "" - description = < Date: Tue, 13 Oct 2020 12:08:32 -0700 Subject: [PATCH 42/43] Renaming tfc_extra_envs var to agent_envs --- main.tf | 2 +- variables.tf | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index 8ac870d..dd4b4a7 100644 --- a/main.tf +++ b/main.tf @@ -94,7 +94,7 @@ resource "kubernetes_deployment" "tfc_cloud_agent" { value = var.tfc_address } dynamic "env" { - for_each = var.tfc_extra_envs + for_each = var.agent_envs content { name = env.key value = env.value diff --git a/variables.tf b/variables.tf index 7945a58..0912b49 100644 --- a/variables.tf +++ b/variables.tf @@ -46,6 +46,12 @@ variable "agent_cli_args" { description = "Extra command line arguments to pass to tfc-agent" } +variable "agent_envs" { + type = map + default = {} + description = "A map of any extra environment variables to pass to the TFC agent" +} + variable "tfc_agent_token" { type = string default = "" @@ -100,12 +106,6 @@ variable "tfc_address" { description = "The HTTP or HTTPS address of the Terraform Cloud API." } -variable "tfc_extra_envs" { - type = map - default = {} - description = "A map of any extra environment variables to pass to the TFC agent" -} - variable "resource_limits_cpu" { type = string default = "1" From 4d3d45cdb6599c6512f7fac8172a78c896155bef Mon Sep 17 00:00:00 2001 From: Dan Meyers Date: Tue, 13 Oct 2020 12:28:17 -0700 Subject: [PATCH 43/43] Fixing a few things found during testing --- examples/complete/main.tf | 2 +- outputs.tf | 6 ++++-- test/src/examples_complete_test.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 995da42..136f805 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -9,5 +9,5 @@ module "tfc_agent" { tfc_agent_token = var.tfc_agent_token namespace_creation_enabled = true - kubernetes_namespace = "foo" + kubernetes_namespace = "foo" } diff --git a/outputs.tf b/outputs.tf index bdd3611..9eac91f 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1,9 @@ output "service_account_name" { - value = local.service_account_name + value = local.service_account_name + description = "Name of the Kubernetes service account" } output "namespace" { - value = local.namespace + value = local.namespace + description = "Name of the Kubernetes namespace" } diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index d14510d..7805e88 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -23,7 +23,7 @@ func TestExamplesComplete(t *testing.T) { TerraformDir: "../../examples/complete", Upgrade: true, // Variables to pass to our Terraform code using -var-file options - VarFiles: []string{"fixtures.us-east-2.tfvars"}, + VarFiles: []string{"fixtures.tfvars"}, // We always include a random attribute so that parallel tests // and AWS resources do not interfere with each other Vars: map[string]interface{}{