Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove null_resouce for associate_provider and add as terraform resource #1372

Merged
merged 3 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 10 additions & 29 deletions terraform/aws-accounts/cloud-platform-aws/vpc/eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -122,34 +122,15 @@ module "auth0" {
extra_callbacks = lookup(local.auth0_extra_callbacks, terraform.workspace, [""])
}

resource "null_resource" "associate_identity_provider" {
depends_on = [module.eks.cluster_id]
provisioner "local-exec" {
command = "aws eks --region 'eu-west-2' describe-identity-provider-config --cluster-name '${terraform.workspace}' --identity-provider-config type='oidc',name='Auth0' --output json --query 'identityProviderConfig.oidc.status' || aws eks --region 'eu-west-2' associate-identity-provider-config --cluster-name '${terraform.workspace}' --oidc identityProviderConfigName='Auth0',issuerUrl='${var.auth0_issuerUrl}',clientId='${module.auth0.oidc_kubernetes_client_id}',usernameClaim=email,groupsClaim='${var.auth0_groupsClaim}',requiredClaims={}"
resource "aws_eks_identity_provider_config" "oidc_associate" {
cluster_name = terraform.workspace

oidc {
client_id = module.auth0.oidc_kubernetes_client_id
identity_provider_config_name = "Auth0"
issuer_url = var.auth0_issuerUrl
username_claim = "email"
groups_claim = var.auth0_groupsClaim
required_claims = {}
}

}

resource "null_resource" "wait_for_active_associate" {
count = var.check_associate == "true" ? 1 : 0
depends_on = [null_resource.associate_identity_provider]
provisioner "local-exec" {
command = var.wait_for_active_associate_cmd
interpreter = var.wait_for_active_associate_interpreter
environment = {
CLUSTER = terraform.workspace
}
}
}

variable "wait_for_active_associate_cmd" {
description = "Custom local-exec command to execute for determining if the associate identity provider is active. Cluster name will be available as an environment variable called CLUSTER"
type = string
default = "for i in `seq 1 60`; do if [[ `aws eks --region 'eu-west-2' describe-identity-provider-config --cluster-name $CLUSTER --identity-provider-config type='oidc',name='Auth0' --output json --query 'identityProviderConfig.oidc.status'` == '\"ACTIVE\"' ]]; then exit 0;else echo 'Checking again for active Auth0 association'; sleep 30;fi; done; echo 'TIMEOUT due to maximum retries to check for active Auth0 association'; exit 1"
}

variable "wait_for_active_associate_interpreter" {
description = "Custom local-exec command line interpreter for the command to determining if the Auth0 association to eks cluster is active."
type = list(string)
default = ["/bin/sh", "-c"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ variable "auth0_groupsClaim" {
default = "https://k8s.integration.dsd.io/groups"
}

variable "check_associate" {
type = string
default = "true"
description = "Check for active association during cluster creation. This is required for kuberos to authenticate to the cluster."
}

variable "cluster_enabled_log_types" {
default = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
description = "A list of the desired control plane logging to enable."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ terraform {
source = "hashicorp/kubernetes"
version = "~> 1.11"
}
null = {
source = "hashicorp/null"
}
}
required_version = ">= 0.14"
}