Skip to main content

Module: tfc-cloud-agent

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 subscription.

Usage

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-tfc-cloud-agent.git?ref=master"

# Your agent token generated in Terraform Cloud
token = var.tfc_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"
}

Examples

Here is an example of using this module:

Variables

Required Variables

Optional Variables

agent_cli_args (list(any)) optional

Extra command line arguments to pass to tfc-agent


Default value: [ ]

agent_envs (map(any)) optional

A map of any extra environment variables to pass to the TFC agent


Default value: { }

agent_image (string) optional

Name and tag of Terraform Cloud Agent docker image


Default value: "hashicorp/tfc-agent:latest"

deployment_annotations (map(any)) optional

Annotations to add to the Kubernetes deployment


Default value: { }

deployment_name (string) optional

Override the deployment name in Kubernetes


Default value: null

kubernetes_namespace (string) optional

Kubernetes namespace override


Default value: null

namespace_creation_enabled (bool) optional

Enable this if the Kubernetes namespace does not already exist


Default value: false

replicas (number) optional

Number of replicas in the Kubernetes deployment


Default value: 1

resource_limits_cpu (string) optional

Kubernetes deployment resource hard CPU limit


Default value: "1"

resource_limits_memory (string) optional

Kubernetes deployment resource hard memory limit


Default value: "512Mi"

resource_requests_cpu (string) optional

Kubernetes deployment resource CPU requests


Default value: "250m"

resource_requests_memory (string) optional

Kubernetes deployment resource memory requests


Default value: "50Mi"

service_account_annotations (map(any)) optional

Annotations to add to the Kubernetes service account


Default value: { }

tfc_address (string) optional

The HTTP or HTTPS address of the Terraform Cloud API.


Default value: "https://app.terraform.io"

tfc_agent_data_dir (string) optional

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.



Default value: null

tfc_agent_disable_update (bool) optional

Disable automatic core updates.


Default value: false

tfc_agent_log_level (string) optional

The log verbosity expressed as a level string. Level options include
"trace", "debug", "info", "warn", and "error"



Default value: "info"

tfc_agent_single (bool) optional

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.



Default value: false

tfc_agent_token (string) optional

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.



Default value: ""

Context Variables

The following variables are defined in the context.tf file of this module and part of the terraform-null-label pattern.

additional_tag_map (map(string)) optional

Additional tags for appending to tags_as_list_of_maps. Not added to tags.
Required: No

Default value: { }

attributes (list(string)) optional

Additional attributes (e.g. 1)
Required: No

Default value: [ ]

context optional

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.


Required: No

Type:

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
})

Default value:

{
"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": {}
}
delimiter (string) optional

Delimiter to be used between namespace, environment, stage, name and attributes.
Defaults to - (hyphen). Set to "" to use no delimiter at all.


Required: No

Default value: null

enabled (bool) optional

Set to false to prevent the module from creating any resources
Required: No

Default value: null

environment (string) optional

Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'
Required: No

Default value: null

id_length_limit (number) optional

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.


Required: No

Default value: null

label_order (list(string)) optional

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.


Required: No

Default value: null

name (string) optional

Solution name, e.g. 'app' or 'jenkins'
Required: No

Default value: null

namespace (string) optional

Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'
Required: No

Default value: null

regex_replace_chars (string) optional

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.


Required: No

Default value: null

stage (string) optional

Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'
Required: No

Default value: null

tags (map(string)) optional

Additional tags (e.g. map('BusinessUnit','XYZ')
Required: No

Default value: { }

Outputs

namespace

Name of the Kubernetes namespace

service_account_name

Name of the Kubernetes service account

Dependencies

Requirements

  • terraform, version: >= 0.12.0, < 0.14.0
  • kubernetes, version: >= 1.12.0

Providers

  • kubernetes, version: >= 1.12.0

Modules

NameVersionSourceDescription
thistags/0.19.2git::https://github.com/cloudposse/terraform-null-label.gitn/a

Resources

The following resources are used by this module:

Data Sources

The following data sources are used by this module: