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

Prototype for Syncing Verisons with constants.py #1

Closed
Closed
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
19 changes: 19 additions & 0 deletions src/_nebari/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,22 @@
AZURE_DEFAULT_REGION = "Central US"
GCP_DEFAULT_REGION = "us-central1"
DO_DEFAULT_REGION = "nyc3"

# TERRAFORM REQUIRED PROVIDERS
REQUIRED_PROVIDERS = {
"null": {
"_name": "null",
"source": "hashicorp/null",
"version": "3.2.3",
},
"helm": {
"_name": "helm",
"source": "hashicorp/helm",
"version": "2.1.2",
},
"kubernetes": {
"_name": "kubernetes",
"source": "hashicorp/kubernetes",
"version": "2.20.0",
},
}
4 changes: 0 additions & 4 deletions src/_nebari/stages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def set_outputs(
def check(
self, stage_outputs: Dict[str, Dict[str, Any]], disable_prompt: bool = False
):

if self.failed_to_create:
print(
f"ERROR: After stage={self.name} "
Expand Down Expand Up @@ -143,7 +142,6 @@ def render(self) -> Dict[pathlib.Path, str]:
def deploy(
self, stage_outputs: Dict[str, Dict[str, Any]], disable_prompt: bool = False
):

print(f"Deploying kubernetes resources for {self.name}")
# get the kubernetes client
kubernetes_client = self._get_k8s_client(stage_outputs)
Expand Down Expand Up @@ -208,7 +206,6 @@ def destroy(
# destroy each manifest in the reverse order

for manifest in sorted(manifests, reverse=True):

print(f"Destroyed manifest: {manifest}")
try:
kubernetes.delete_from_yaml(kubernetes_client, manifest)
Expand All @@ -220,7 +217,6 @@ def destroy(
# destroy each crd in the reverse order

for crd in sorted(crds, reverse=True):

print(f"Destroyed CRD: {crd}")
try:
kubernetes.delete_from_yaml(kubernetes_client, crd)
Expand Down
8 changes: 6 additions & 2 deletions src/_nebari/stages/kubernetes_initialize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from _nebari.stages.tf_objects import (
NebariHelmProvider,
NebariKubernetesProvider,
NebariTerraformState,
NebariTerraformRequiredProvider,
NebariTerraformRequiredVersion,
)
from nebari import schema
from nebari.hookspecs import NebariStage, hookimpl
Expand Down Expand Up @@ -64,7 +65,10 @@ class KubernetesInitializeStage(NebariTerraformStage):

def tf_objects(self) -> List[Dict]:
return [
NebariTerraformState(self.name, self.config),
*super().tf_objects(),
NebariTerraformRequiredVersion(self.config),
NebariTerraformRequiredProvider("helm", self.config),
NebariTerraformRequiredProvider("kubernetes", self.config),
NebariKubernetesProvider(self.config),
NebariHelmProvider(self.config),
]
Expand Down
26 changes: 13 additions & 13 deletions src/_nebari/stages/kubernetes_initialize/template/versions.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
terraform {
required_providers {
helm = {
source = "hashicorp/helm"
version = "2.1.2"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.20.0"
}
}
required_version = ">= 1.0"
}
# terraform {
# required_providers {
# helm = {
# source = "hashicorp/helm"
# version = "2.1.2"
# }
# kubernetes = {
# source = "hashicorp/kubernetes"
# version = "2.20.0"
# }
# }
# required_version = ">= 1.0"
# }
12 changes: 10 additions & 2 deletions src/_nebari/stages/terraform_state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from _nebari.provider import terraform
from _nebari.provider.cloud import azure_cloud
from _nebari.stages.base import NebariTerraformStage
from _nebari.stages.tf_objects import NebariConfig
from _nebari.stages.tf_objects import (
NebariConfig,
NebariTerraformRequiredProvider,
NebariTerraformRequiredVersion,
)
from _nebari.utils import (
AZURE_TF_STATE_RESOURCE_GROUP_SUFFIX,
construct_azure_resource_group_name,
Expand Down Expand Up @@ -172,7 +176,11 @@ def state_imports(self) -> List[Tuple[str, str]]:
return []

def tf_objects(self) -> List[Dict]:
resources = [NebariConfig(self.config)]
resources = [
NebariConfig(self.config),
NebariTerraformRequiredProvider("null", self.config),
NebariTerraformRequiredVersion(self.config),
]
if self.config.provider == schema.ProviderEnum.gcp:
return resources + [
terraform.Provider(
Expand Down
18 changes: 17 additions & 1 deletion src/_nebari/stages/tf_objects.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from _nebari.provider.terraform import Data, Provider, Resource, TerraformBackend
from _nebari import constants
from _nebari.provider.terraform import (
Data,
Provider,
RequiredProvider,
Resource,
Terraform,
TerraformBackend,
)
from _nebari.utils import (
AZURE_TF_STATE_RESOURCE_GROUP_SUFFIX,
construct_azure_resource_group_name,
Expand Down Expand Up @@ -117,5 +125,13 @@ def NebariTerraformState(directory: str, nebari_config: schema.Main):
raise NotImplementedError("state not implemented")


def NebariTerraformRequiredProvider(name: str, nebari_config: schema.Main):
return RequiredProvider(**constants.REQUIRED_PROVIDERS[name])


def NebariTerraformRequiredVersion(nebari_config: schema.Main):
return Terraform(required_version=constants.TERRAFORM_VERSION)


def NebariConfig(nebari_config: schema.Main):
return Resource("terraform_data", "nebari_config", input=nebari_config.model_dump())
Loading