Skip to content

terraform-ibm-modules/terraform-ibm-namespace

Repository files navigation

Namespace module

Graduated (Supported) latest release pre-commit Renovate enabled semantic-release

This module supports creating multiple Kubernetes namespaces / OpenShift projects with optional annotations and labels.

Overview

terraform-ibm-namespace

Usage

##############################################################################
# Init cluster config for kubernetes providers
##############################################################################

data "ibm_container_cluster_config" "cluster_config" {
  cluster_name_id = var.cluster_id
}

##############################################################################
# Config providers
##############################################################################

provider "ibm" {
  ibmcloud_api_key = var.ibmcloud_api_key # pragma: allowlist secret
}

provider "kubernetes" {
  host                   = data.ibm_container_cluster_config.cluster_config.host
  token                  = data.ibm_container_cluster_config.cluster_config.token
  cluster_ca_certificate = data.ibm_container_cluster_config.cluster_config.ca_certificate
}

##############################################################################
# Namespace module
##############################################################################

module "namespace" {
  source            = "terraform-ibm-modules/namespace/ibm"
  version           = "X.X.X" # Replace "X.X.X" with a release version to lock into a specific
  namespaces = [
    {
      name = "my-namespace"
      metadata = {
        labels = {
          "istio-injection" = "enabled"
        }
        annotations = {
          "name" = "example-annotation"
        }
      }
    },
    {
      name = "my-namespace-2"
      metadata = {
        labels = {
          "istio-injection" = "enabled"
        }
        annotations = {
          "name" = "example-annotation"
        }
      }
    }
  ]
}

Required IAM access policies

You need the following permissions to run this module.

  • IAM Services
    • Kubernetes service
      • Viewer platform access
      • Manager service access

Requirements

Name Version
terraform >= 1.3.0, <1.7.0
kubernetes >= 2.16.1, < 3.0.0

Modules

No modules.

Resources

Name Type
kubernetes_namespace.create_namespace resource

Inputs

Name Description Type Default Required
namespaces Set of namespaces to create
list(object({
name = string
metadata = optional(object({
labels = map(string)
annotations = map(string)
}))
}))
n/a yes

Outputs

No outputs.

Contributing

You can report issues and request features for this module in GitHub issues in the module repo. See Report an issue or request a feature.

To set up your local development environment, see Local development setup in the project documentation.