0

Is it possible to deploy an app with terraform to an already existing eks cluster (one that was not created with terraform)?

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
}

# Configure the AWS Provider
provider "aws" {
  region = "us-east-2"
}

provider "kubernetes" {
  host = var.cluster_endpoint
  cluster_ca_certificate   = base64decode(var.cluster_certificate_authority)
  # cluster_ca_certificate = var.cluster_certificate_authority
  token            = var.cluster_token
  load_config_file = false
  version          = "~> 1.11"
}

resource "kubernetes_deployment" "test-app" {
  metadata {
    name = "test-app"
    labels = {
      App = "test"
    }
  }

  spec {
    replicas = 2
    selector {
      match_labels = {
        App = "test"
      }
    }
    template {
      metadata {
        labels = {
          App = "test"
        }
      }
      spec {
        container {
          image = "411037401432.dkr.ecr.us-east-2.amazonaws.com/test:latest"
          name  = "test"

          port {
            container_port = 80
          }
        }
      }
    }
  }
}

Thanks!

3
  • Yes, it's possible.. have you tried and encountered any errors? – Itai Ganot Jan 12 at 0:55
  • I'm having trouble with the ca certificate, keep getting not authorized or certificate signed by unknown authority. – Lauren Pappas Jan 12 at 18:06
  • Probably your Terraform has not permission to deploy....check the RBAC rule or export K8s vars using your credentials at shell – Weyder Ferreira Jan 12 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.