generated from cloudposse/terraform-example-module
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new module, documentation, and complete example (#1)
* Initial commit * Updating README * Updating README * Updating documentation * Fixing small documentation thing * Renaming k8s_namespace * Updating a few things * Some minor formatting tweaks * A few more tweaks * Updating examples * Adding first draft of service acount * A couple small tweaks * Breaking out k8s resource values into TF vars * Updating vars * Renaming fixtures in complete example * Updating variable description * Fixing a formatting thing * Fixing formatting & added missing variable * Fixing a couple more things * Update README.yaml Co-authored-by: Erik Osterman <erik@cloudposse.com> * Update README.yaml Co-authored-by: Erik Osterman <erik@cloudposse.com> * Update README.yaml Co-authored-by: Erik Osterman <erik@cloudposse.com> * Update variables.tf Co-authored-by: Erik Osterman <erik@cloudposse.com> * Update variables.tf Co-authored-by: Erik Osterman <erik@cloudposse.com> * Update README.yaml Co-authored-by: Erik Osterman <erik@cloudposse.com> * Update main.tf Co-authored-by: Erik Osterman <erik@cloudposse.com> * Making a bunch of updates * Fixing a formatting thing * Update README.md Co-authored-by: Erik Osterman <erik@cloudposse.com> * Update README.md Co-authored-by: Erik Osterman <erik@cloudposse.com> * Update README.yaml Co-authored-by: Erik Osterman <erik@cloudposse.com> * Updating README * A few more updates * Adding support for agent CLI arguments * Cleaning up namespace/service_account stuff and adding outputs * Lots of updates * Updating README * Fixing namespace output * Fixing HEREDOC Co-authored-by: Erik Osterman <erik@cloudposse.com> * Fixing HEREDOC Co-authored-by: Erik Osterman <erik@cloudposse.com> * Fixing more HEREDOC * Renaming tfc_extra_envs var to agent_envs * Fixing a few things found during testing Co-authored-by: Dan Meyers <danjbh@users.noreply.github.com> Co-authored-by: Erik Osterman <erik@cloudposse.com>
- Loading branch information
1 parent
5209623
commit 6d60cb6
Showing
13 changed files
with
411 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
examples/complete/fixtures.us-east-2.tfvars → examples/complete/fixtures.tfvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
region = "us-east-2" | ||
|
||
namespace = "eg" | ||
|
||
environment = "ue2" | ||
|
||
stage = "test" | ||
|
||
name = "example" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
module "example" { | ||
source = "../.." | ||
|
||
example = var.example | ||
provider "kubernetes" { | ||
version = "~> 1.12" | ||
} | ||
|
||
module "tfc_agent" { | ||
source = "../.." | ||
context = module.this.context | ||
|
||
tfc_agent_token = var.tfc_agent_token | ||
|
||
namespace_creation_enabled = true | ||
kubernetes_namespace = "foo" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,7 @@ | ||
output "id" { | ||
description = "ID of the created example" | ||
value = module.example.id | ||
output "service_account_name" { | ||
value = module.tfc_agent.service_account_name | ||
} | ||
|
||
output "example" { | ||
description = "Output \"example\" from example module" | ||
value = module.example.example | ||
} | ||
|
||
output "random" { | ||
description = "Output \"random\" from example module" | ||
value = module.example.random | ||
} | ||
output "namespace" { | ||
value = module.tfc_agent.namespace | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
variable "example" { | ||
variable "tfc_agent_token" { | ||
type = string | ||
description = "The value which will be passed to the example module" | ||
description = "The preconfigured Terraform Cloud Agent token" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,117 @@ | ||
resource "random_integer" "example" { | ||
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, "default") | ||
} | ||
|
||
resource "kubernetes_namespace" "namespace" { | ||
count = var.namespace_creation_enabled ? 1 : 0 | ||
metadata { | ||
name = local.namespace | ||
} | ||
} | ||
|
||
resource "kubernetes_service_account" "service_account" { | ||
count = module.this.enabled ? 1 : 0 | ||
|
||
min = 1 | ||
max = 50000 | ||
keepers = { | ||
example = var.example | ||
metadata { | ||
name = local.service_account_name | ||
namespace = local.namespace | ||
annotations = var.service_account_annotations | ||
} | ||
} | ||
|
||
locals { | ||
example = format("%v %v", var.example, join("", random_integer.example[*].result)) | ||
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 = local.deployment_name | ||
namespace = local.namespace | ||
labels = module.this.tags | ||
} | ||
spec { | ||
selector { | ||
match_labels = module.this.tags | ||
} | ||
replicas = var.replicas | ||
|
||
template { | ||
metadata { | ||
namespace = local.namespace | ||
labels = module.this.tags | ||
annotations = var.deployment_annotations | ||
} | ||
spec { | ||
service_account_name = local.service_account_name | ||
automount_service_account_token = true | ||
container { | ||
image = var.agent_image | ||
name = "tfc-agent" | ||
args = var.agent_cli_args | ||
env { | ||
name = "TFC_AGENT_TOKEN" | ||
value_from { | ||
secret_key_ref { | ||
key = "token" | ||
name = local.deployment_name | ||
} | ||
} | ||
} | ||
env { | ||
name = "TFC_AGENT_NAME" | ||
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 | ||
} | ||
dynamic "env" { | ||
for_each = var.agent_envs | ||
content { | ||
name = env.key | ||
value = env.value | ||
} | ||
} | ||
resources { | ||
limits { | ||
cpu = var.resource_limits_cpu | ||
memory = var.resource_limits_memory | ||
} | ||
requests { | ||
cpu = var.resource_requests_cpu | ||
memory = var.resource_requests_memory | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
output "id" { | ||
description = "ID of the created example" | ||
value = module.this.enabled ? module.this.id : null | ||
output "service_account_name" { | ||
value = local.service_account_name | ||
description = "Name of the Kubernetes service account" | ||
} | ||
|
||
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 | ||
output "namespace" { | ||
value = local.namespace | ||
description = "Name of the Kubernetes namespace" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.