
resource "kubernetes_namespace" "argocd" {
  metadata {
    name = "argocd"
  }
}

data "aws_secretsmanager_secret" "bitbucket_ssh_argocd_key" {
  name = "bitbucket-ssh-argocd-key"
}

data "aws_secretsmanager_secret_version" "bitbucket_ssh_argocd_key" {
  secret_id = data.aws_secretsmanager_secret.bitbucket_ssh_argocd_key.id
}

resource "kubernetes_secret" "bitbucket_ssh_argocd_key" {
  depends_on = [kubernetes_namespace.argocd]

  metadata {
    name      = "bitbucket-ssh-argocd-key"
    namespace = "argocd"
    labels = {
      "argocd.argoproj.io/secret-type" = "repository"
    }
  }

  data = {
    url           = "git@bitbucket.org:jamkazam/video-iac"
    sshPrivateKey = base64decode(jsondecode(data.aws_secretsmanager_secret_version.bitbucket_ssh_argocd_key.secret_string)["private"])
  }

}

