terraform {
required_providers {
akp = {
source = "akuity/akp"
version = "~> 0.1"
}
kubectl = {
source = "gavinbunney/kubectl"
version = "~> 1.14"
}
}
}
provider "akp" {
org_name = "<organization-name>"
}
provider "kubectl" {
# Configure the kubectl provider
# to connect to the existing kubernetes cluster
}
# Read Existing Argo CD Instance
data "akp_instance" "existing" {
name = "manualy-created"
}
# Add cluster to the existing instance
resource "akp_cluster" "test" {
name = "test-cluster"
description = "Test Cluster 1"
namespace = "akuity"
instance_id = data.akp_instance.existing.id
}
# Split and install agent manifests
data "kubectl_file_documents" "agent" {
content = akp_cluster.test.manifests
}
# Create namespace first
resource "kubectl_manifest" "agent_namespace" {
yaml_body = lookup(data.kubectl_file_documents.agent.manifests, "/api/v1/namespaces/${akp_cluster.test.namespace}/namespaces/${akp_cluster.test.namespace}")
wait = true
}
# Create everything else
resource "kubectl_manifest" "agent" {
for_each = data.kubectl_file_documents.agent.manifests
yaml_body = each.value
# Important!
wait_for_rollout = false
depends_on = [
kubectl_manifest.agent_namespace
]
}
First create the cluster using -target
terraform apply -target akp_cluster.test
This has to be done first, because terraform is unable to apply an unknown number of manifests in for_each loop, and the manifests only available after the cluster is created