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:
examples/complete
- complete example of using this module
Variables
Required Variables
Optional Variables
agent_cli_args
(list(any)
) optionalExtra command line arguments to pass to tfc-agent
Default value:
[ ]
agent_envs
(map(any)
) optionalA map of any extra environment variables to pass to the TFC agent
Default value:
{ }
agent_image
(string
) optionalName and tag of Terraform Cloud Agent docker image
Default value:
"hashicorp/tfc-agent:latest"
deployment_annotations
(map(any)
) optionalAnnotations to add to the Kubernetes deployment
Default value:
{ }
deployment_name
(string
) optionalOverride the deployment name in Kubernetes
Default value:
null
kubernetes_namespace
(string
) optionalKubernetes namespace override
Default value:
null
namespace_creation_enabled
(bool
) optionalEnable this if the Kubernetes namespace does not already exist
Default value:
false
replicas
(number
) optionalNumber of replicas in the Kubernetes deployment
Default value:
1
resource_limits_cpu
(string
) optionalKubernetes deployment resource hard CPU limit
Default value:
"1"
resource_limits_memory
(string
) optionalKubernetes deployment resource hard memory limit
Default value:
"512Mi"
resource_requests_cpu
(string
) optionalKubernetes deployment resource CPU requests
Default value:
"250m"
resource_requests_memory
(string
) optionalKubernetes deployment resource memory requests
Default value:
"50Mi"
service_account_annotations
(map(any)
) optionalAnnotations to add to the Kubernetes service account
Default value:
{ }
tfc_address
(string
) optionalThe HTTP or HTTPS address of the Terraform Cloud API.
Default value:
"https://app.terraform.io"
tfc_agent_data_dir
(string
) optionalThe 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
) optionalDisable automatic core updates.
Default value:
false
tfc_agent_log_level
(string
) optionalThe log verbosity expressed as a level string. Level options include
"trace", "debug", "info", "warn", and "error"Default value:
"info"
tfc_agent_single
(bool
) optionalEnable 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
) optionalThe 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.
context.tf
file of this module and part of the terraform-null-label pattern.additional_tag_map
(map(string)
) optionalAdditional tags for appending to tags_as_list_of_maps. Not added to
tags
.
Required: NoDefault value:
{ }
attributes
(list(string)
) optionalAdditional attributes (e.g.
1
)
Required: NoDefault value:
[ ]
context
optionalSingle object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables asnull
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
) optionalDelimiter to be used between
namespace
,environment
,stage
,name
andattributes
.
Defaults to-
(hyphen). Set to""
to use no delimiter at all.Required: No
Default value:
null
enabled
(bool
) optionalSet to false to prevent the module from creating any resources
Required: NoDefault value:
null
environment
(string
) optionalEnvironment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'
Required: NoDefault value:
null
id_length_limit
(number
) optionalLimit
id
to this many characters.
Set to0
for unlimited length.
Set tonull
for default, which is0
.
Does not affectid_full
.Required: No
Default value:
null
label_order
(list(string)
) optionalThe 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
) optionalSolution name, e.g. 'app' or 'jenkins'
Required: NoDefault value:
null
namespace
(string
) optionalNamespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'
Required: NoDefault value:
null
regex_replace_chars
(string
) optionalRegex to replace chars with empty string in
namespace
,environment
,stage
andname
.
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
) optionalStage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'
Required: NoDefault value:
null
tags
(map(string)
) optionalAdditional tags (e.g.
map('BusinessUnit','XYZ')
Required: NoDefault 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
Name | Version | Source | Description |
---|---|---|---|
this | tags/0.19.2 | git::https://github.com/cloudposse/terraform-null-label.git | n/a |
Resources
The following resources are used by this module:
kubernetes_deployment.tfc_cloud_agent
(resource)kubernetes_namespace.namespace
(resource)kubernetes_secret.secret
(resource)kubernetes_service_account.service_account
(resource)
Data Sources
The following data sources are used by this module: