Documentation

esc
    Reference / Container Registry

    Container Registry with Terraform

    The pantechdynamics_container_registry_namespace, pantechdynamics_container_repository and pantechdynamics_container_registry_token resources and their data sources, with examples.

    Manage your Container Registry namespace, its repositories and registry tokens with the Terraform provider. Images themselves are pushed with docker or your CI, not Terraform.

    ResourceWhat it is
    pantechdynamics_container_registry_namespaceYour organization's namespace, and whether a first push creates a repository
    pantechdynamics_container_repositoryOne repository: visibility, immutable tags and retention rules
    pantechdynamics_container_registry_tokenA registry token for CI or a cluster. Its secret is a sensitive attribute
    Data sourceWhat it reads
    pantechdynamics_container_repositoryA repository you already have, by id or name
    pantechdynamics_container_repositoriesEvery repository in the namespace, including those a push created

    pantechdynamics_container_registry_namespace

    HCL
    resource "pantechdynamics_container_registry_namespace" "main" {
      name           = "acme"
      create_on_push = false
    }
    Argument
    nameRequired. Globally unique: 3 to 30 lower-case letters, digits and single hyphens, starting with a letter; reserved words such as library, pantech and admin are refused. Changing it renames the namespace in place, and is refused once a repository has ever been created in it
    create_on_pushOptional. Whether the first push to a new name creates the repository. Default true
    Attribute
    registry_hostregistry.pantechdynamics.com
    repository_countRepositories in the namespace
    storage_bytesStorage used
    storage_limit_bytesThe namespace's storage limit; pushes past it are refused
    repository_limitThe most repositories it may hold

    An organization has one namespace, so there is at most one of this resource. Destroying it only removes it from Terraform's state: the namespace stays, and so do its repositories.

    pantechdynamics_container_repository

    HCL
    resource "pantechdynamics_container_repository" "api" {
      name           = "api/server"
      description    = "The API server"
      visibility     = "private"
      immutable_tags = true
    
      retention = {
        keep_last           = 50
        untagged_after_days = 7
        keep_pattern        = "v*"
      }
    
      depends_on = [pantechdynamics_container_registry_namespace.main]
    }
    
    output "image" {
      value = pantechdynamics_container_repository.api.full_name
    }
    Argument
    nameRequired. Such as api/server: lower-case path parts of letters and digits, with single ., _ or - between them, up to 255 characters. Changing it replaces the repository, which deletes its images
    descriptionOptional. Up to 255 characters
    visibilityOptional. private (the default) or public, which anyone can pull without logging in
    immutable_tagsOptional. A tag, once pushed, cannot be moved or deleted. Default false
    retentionOptional. Cleanup, run daily: keep_last (1 to 1,000), untagged_after_days (1 to 365) and keep_pattern (a glob such as v*, whose tags are always kept); set at least one. Leave it out for no cleanup
    Attribute
    idcrr_…
    full_nameThe image name to tag, push and pull
    tag_countTags in the repository
    storage_bytesStorage its images use
    statusactive, deleting or suspended

    Destroying a repository deletes every image in it, and cannot be undone. It needs a key with the delete scope.

    pantechdynamics_container_registry_token

    HCL
    resource "pantechdynamics_container_registry_token" "ci" {
      name         = "github-actions"
      permission   = "push"
      repositories = [pantechdynamics_container_repository.api.name]
      expires_at   = "2027-11-10T00:00:00Z"
    }
    
    output "ci_registry_token" {
      value     = pantechdynamics_container_registry_token.ci.secret
      sensitive = true
    }
    Argument
    nameRequired
    permissionRequired. pull, or push, which can pull too
    repositoriesOptional. Repository names the token may use. Leave out for every repository
    expires_atOptional. RFC 3339

    Changing any argument replaces the token: the old one is revoked and a new secret is made.

    Attribute
    idprt_…
    secretThe token. Sensitive. Pantech shows it only when it is created, so it exists only in your Terraform state
    last_used_atThe last login with it

    Destroying the resource revokes the token. It needs a key with the delete scope. A token imported with terraform import has no secret.

    A pull secret for Kubernetes

    With the Kubernetes provider, a pull token becomes an image pull secret:

    HCL
    resource "pantechdynamics_container_registry_token" "cluster" {
      name         = "prod-cluster"
      permission   = "pull"
      repositories = [pantechdynamics_container_repository.api.name]
    }
    
    resource "kubernetes_secret" "pantech_registry" {
      metadata {
        name      = "pantech-registry"
        namespace = "default"
      }
      type = "kubernetes.io/dockerconfigjson"
      data = {
        ".dockerconfigjson" = jsonencode({
          auths = {
            "registry.pantechdynamics.com" = {
              auth = base64encode("pantech:${pantechdynamics_container_registry_token.cluster.secret}")
            }
          }
        })
      }
    }

    Data sources

    HCL
    data "pantechdynamics_container_repository" "api" {
      name = "api/server"
    }
    
    data "pantechdynamics_container_repositories" "all" {}
    
    output "repository_names" {
      value = [for r in data.pantechdynamics_container_repositories.all.repositories : r.full_name]
    }

    Import

    Terminal
    $ terraform import pantechdynamics_container_registry_namespace.main acme$ terraform import pantechdynamics_container_repository.api crr_06gk3x9tq7m2v8r4y1c5d0zp8w$ terraform import pantechdynamics_container_repository.api api/server$ terraform import pantechdynamics_container_registry_token.ci prt_06gk3x9tq7m2v8r4y1c5d0zp8w

    Was this page helpful?

    Updated