Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Ability to apply/patch existing Kubernetes Resources without import or error #66

Open
WilliamABradley opened this issue Jun 16, 2020 · 1 comment
Labels
acknowledged enhancement New feature or request

Comments

@WilliamABradley
Copy link

Description

I know this isn't an ideal situation, but isn't unheard of, but can sometimes be necessary.

Essentially, there are some Kubernetes Resources that we might want to update, without creating, e.g. Updating the Default Service Account for a Namespace to modify the default pull credentials, adding a TCP Service to Nginx TCP Services for the Nginx Ingress.

Therefore, there might be 2 scenarios, which could be configured 2 ways.

  • Inherit control of the Kubernetes Resource.

    As seen with default resources in the AWS Provider: https://www.terraform.io/docs/providers/aws/r/default_vpc.html

    With this approach, we bring this resource into Terraform management as if it was created by Terraform, and will be updated from there onwards, whenever anything changes in the configuration, and will be deleted (if possible), when you delete the resource.

  • Modify the Kubernetes Resource, with no future tracking.
    With this approach, it is essentially performed like kubectl patch, or kubectl apply, it will update the resource, with no attempts to synchronise the resource, and if you delete the resource, it won't attempt to delete it from the Kubernetes Cluster.

This could be represented by a property called something like if_exists, which could be the values:

  • fail
  • attach
  • patch

The reason for these, without doing a manual import, is that it allows for dynamic creation, without having to break up the apply step into multiple parts.

Potential Terraform Configuration

provider "kubernetes-alpha" {}

resource "kubernetes_manifest" "test-configmap" {
  provider = kubernetes-alpha

  manifest = {
    "apiVersion" = "v1"
    "kind" = "ConfigMap"
    "metadata" = {
      "name" = "test-config"
      "namespace" = "default"
    }
    "data" = {
      "foo" = "bar"
    }
  }

  if_exists = "attach"
}

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@WilliamABradley WilliamABradley added the enhancement New feature or request label Jun 16, 2020
@blacksd
Copy link

blacksd commented Feb 11, 2021

Slightly related to hashicorp/terraform-provider-kubernetes#723

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
acknowledged enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants