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

Change AWS Kubenetes provider authentication to use data.eks_cluster instead of exec #1107

Merged
merged 3 commits into from
Feb 23, 2022
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
28 changes: 14 additions & 14 deletions qhub/provider/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,35 +257,35 @@ def Terraform(**kwargs):


@register
def RequiredProvider(name, **kwargs):
return {"terraform": {"required_providers": {name: kwargs}}}
def RequiredProvider(_name, **kwargs):
return {"terraform": {"required_providers": {_name: kwargs}}}


@register
def Provider(name, **kwargs):
return {"provider": {name: kwargs}}
def Provider(_name, **kwargs):
return {"provider": {_name: kwargs}}


@register
def TerraformBackend(name, **kwargs):
return {"terraform": {"backend": {name: kwargs}}}
def TerraformBackend(_name, **kwargs):
return {"terraform": {"backend": {_name: kwargs}}}


@register
def Variable(name, **kwargs):
return {"variable": {name: kwargs}}
def Variable(_name, **kwargs):
return {"variable": {_name: kwargs}}


@register
def Data(resource_type, name, **kwargs):
return {"data": {resource_type: {name: kwargs}}}
def Data(_resource_type, _name, **kwargs):
return {"data": {_resource_type: {_name: kwargs}}}


@register
def Resource(resource_type, name, **kwargs):
return {"resource": {resource_type: {name: kwargs}}}
def Resource(_resource_type, _name, **kwargs):
return {"resource": {_resource_type: {_name: kwargs}}}


@register
def Output(name, **kwargs):
return {"output": {name: kwargs}}
def Output(_name, **kwargs):
return {"output": {_name: kwargs}}
56 changes: 42 additions & 14 deletions qhub/stages/tf_objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict

from qhub.provider.terraform import tf_render_objects, TerraformBackend, Provider
from qhub.provider.terraform import tf_render_objects, TerraformBackend, Provider, Data
from qhub.utils import deep_merge


def QHubAWSProvider(qhub_config: Dict):
Expand All @@ -24,24 +25,46 @@ def QHubDigitalOceanProvider(qhub_config: Dict):


def QHubKubernetesProvider(qhub_config: Dict):
optional_kwargs = {}
if qhub_config["provider"] == "aws":
optional_kwargs["exec"] = {
"api_version": "client.authentication.k8s.io/v1alpha1",
"args": [
"eks",
"get-token",
"--cluster-name",
f"{qhub_config['project_name']}-{qhub_config['namespace']}",
],
"command": "aws",
}

cluster_name = f"{qhub_config['project_name']}-{qhub_config['namespace']}"

return deep_merge(
Data("aws_eks_cluster", "default", name=cluster_name),
Data("aws_eks_cluster_auth", "default", name=cluster_name),
Provider(
"kubernetes",
experiments={"manifest_resource": True},
host="${data.aws_eks_cluster.default.endpoint}",
cluster_ca_certificate="${base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)}",
token="${data.aws_eks_cluster_auth.default.token}",
),
)
return Provider(
"kubernetes", experiments={"manifest_resource": True}, **optional_kwargs
"kubernetes",
experiments={"manifest_resource": True},
)


def QHubHelmProvider(qhub_config: Dict):
if qhub_config["provider"] == "aws":
cluster_name = f"{qhub_config['project_name']}-{qhub_config['namespace']}"

return deep_merge(
Data("aws_eks_cluster", "default", name=cluster_name),
Data("aws_eks_cluster_auth", "default", name=cluster_name),
Provider(
"helm",
kubernetes=dict(
experiments={"manifest_resource": True},
host="${data.aws_eks_cluster.default.endpoint}",
cluster_ca_certificate="${base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)}",
token="${data.aws_eks_cluster_auth.default.token}",
),
),
)
return Provider("helm")


def QHubTerraformState(directory: str, qhub_config: Dict):
if qhub_config["terraform_state"]["type"] == "local":
return {}
Expand Down Expand Up @@ -164,6 +187,7 @@ def stage_03_kubernetes_initialize(config):
[
QHubTerraformState("03-kubernetes-initialize", config),
QHubKubernetesProvider(config),
QHubHelmProvider(config),
]
),
}
Expand All @@ -175,6 +199,7 @@ def stage_04_kubernetes_ingress(config):
[
QHubTerraformState("04-kubernetes-ingress", config),
QHubKubernetesProvider(config),
QHubHelmProvider(config),
]
),
}
Expand All @@ -186,6 +211,7 @@ def stage_05_kubernetes_keycloak(config):
[
QHubTerraformState("05-kubernetes-keycloak", config),
QHubKubernetesProvider(config),
QHubHelmProvider(config),
]
),
}
Expand All @@ -207,6 +233,7 @@ def stage_07_kubernetes_services(config):
[
QHubTerraformState("07-kubernetes-services", config),
QHubKubernetesProvider(config),
QHubHelmProvider(config),
]
),
}
Expand All @@ -218,6 +245,7 @@ def stage_08_qhub_tf_extensions(config):
[
QHubTerraformState("08-qhub-tf-extensions", config),
QHubKubernetesProvider(config),
QHubHelmProvider(config),
]
),
}
3 changes: 0 additions & 3 deletions qhub/template/stages/03-kubernetes-initialize/providers.tf

This file was deleted.

3 changes: 0 additions & 3 deletions qhub/template/stages/04-kubernetes-ingress/providers.tf

This file was deleted.

3 changes: 0 additions & 3 deletions qhub/template/stages/05-kubernetes-keycloak/providers.tf

This file was deleted.

5 changes: 0 additions & 5 deletions qhub/template/stages/07-kubernetes-services/providers.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
provider "helm" {

}


provider "keycloak" {
tls_insecure_skip_verify = true
}
4 changes: 0 additions & 4 deletions qhub/template/stages/08-qhub-tf-extensions/providers.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
provider "helm" {

}

provider "keycloak" {
tls_insecure_skip_verify = true
}