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

[FIX] Terraform provider version inconsistency within stages #2862

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e14e835
Add terraform/opentofu version from constants.py to `terraform_state`
smokestacklightnin Nov 23, 2024
8380884
Inject required providers into `infrastructure` stage
smokestacklightnin Nov 23, 2024
3da475d
Add required providers to the `kubernetes-initialize` state
smokestacklightnin Nov 23, 2024
b8ac266
Use `NebariOpentofuRequiredVersion`
smokestacklightnin Nov 24, 2024
31ec936
Inject required opentofu and terraform provider versions into `kubern…
smokestacklightnin Nov 24, 2024
7934255
Inject required opentofu and terraform provider versions into `kubern…
smokestacklightnin Nov 24, 2024
92f4cf6
Inject opentofu required providers and version into `kubernetes_keycl…
smokestacklightnin Nov 24, 2024
2527979
Add Inject opentofu required providers and version into `kubernetes_s…
smokestacklightnin Nov 24, 2024
657014e
Add Inject opentofu required providers and version into `nebari_tf_ex…
smokestacklightnin Nov 24, 2024
66440a3
Fix typo
smokestacklightnin Nov 24, 2024
35048e6
Fix typo
smokestacklightnin Nov 24, 2024
dd64020
Add missing required provider
smokestacklightnin Nov 25, 2024
8923dda
Remove `NebariTerraformState` from `NebariTerraformStage.tf_objects()`
smokestacklightnin Nov 25, 2024
8538ec3
Add `NebariTerraformState` to `infrastructure` stage
smokestacklightnin Nov 26, 2024
f152e72
Add `NebariTerraformState` to `kubernetes_initialize` stage
smokestacklightnin Nov 26, 2024
5f0c07c
Add `NebariTerraformState` to `kubernetes-ingress` stage
smokestacklightnin Nov 26, 2024
046b21a
Add `NebariTerraformState` to `kubernetes-keycloak` stage
smokestacklightnin Nov 26, 2024
b57c61b
Specify terraform registry for providers not in opentofu registry
smokestacklightnin Nov 26, 2024
79f4e01
Change `hashicorp` to `opentofu` in `constants.py`
smokestacklightnin Nov 28, 2024
ce9832f
Add nebari state and other tf objects to `kubernetes_services`, `kube…
smokestacklightnin Dec 2, 2024
1c0be1e
Add `NebariTerraformState` to `kubernetes_services`
smokestacklightnin Dec 2, 2024
0c48e5b
Use `tehcyx/kind` from opentofu registry
smokestacklightnin Dec 3, 2024
9cc390c
Inject empty json files in terraform submodules
smokestacklightnin Dec 21, 2024
38a4b90
Inject required providers from `self.tf_objects`
smokestacklightnin Dec 22, 2024
82c85ea
Merge remote-tracking branch 'upstream/main' into opentofu/stages/syn…
smokestacklightnin Dec 22, 2024
d8b0699
Use hashicorp instead of opentofu
smokestacklightnin Dec 22, 2024
e31e7f8
Merge remote-tracking branch 'upstream/main' into opentofu/stages/syn…
smokestacklightnin Dec 22, 2024
c4d3786
Merge branch 'opentofu/stages/sync-versions-inject-from-parent' into …
smokestacklightnin Dec 22, 2024
84601d6
Merge branch 'main' into opentofu/stages/sync-versions
viniciusdc Jan 7, 2025
9293d3a
Merge remote-tracking branch 'upstream/main' into opentofu/stages/syn…
smokestacklightnin Jan 14, 2025
6e7edf8
Merge branch 'main' into opentofu/stages/sync-versions
viniciusdc Jan 15, 2025
0e82a79
Merge remote-tracking branch 'upstream/main' into opentofu/stages/syn…
smokestacklightnin Jan 21, 2025
991114e
Merge branch 'main' into opentofu/stages/sync-versions
dcmcand Jan 23, 2025
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
49 changes: 49 additions & 0 deletions src/_nebari/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,52 @@
AWS_DEFAULT_REGION = "us-east-1"
AZURE_DEFAULT_REGION = "Central US"
GCP_DEFAULT_REGION = "us-central1"

# TERRAFORM REQUIRED PROVIDERS
REQUIRED_PROVIDERS = {
"aws": {
"_name": "aws",
"source": "hashicorp/aws",
"version": "5.12.0",
},
"azurerm": {
"_name": "azurerm",
"source": "hashicorp/azurerm",
"version": "=3.97.1",
},
"docker": {
"_name": "docker",
"source": "kreuzwerker/docker",
"version": "2.16.0",
},
"google": {
"_name": "google",
"source": "hashicorp/google",
"version": "4.83.0",
},
"helm": {
"_name": "helm",
"source": "hashicorp/helm",
"version": "2.1.2",
},
"keycloak": {
"_name": "keycloak",
"source": "mrparkers/keycloak",
"version": "3.7.0",
},
"kind": {
"_name": "kind",
"source": "tehcyx/kind",
"version": "0.4.0",
},
"kubectl": {
"_name": "kubectl",
"source": "gavinbunney/kubectl",
"version": ">= 1.7.0",
},
"kubernetes": {
"_name": "kubernetes",
"source": "hashicorp/kubernetes",
"version": ">= 2.35.1",
},
}
42 changes: 35 additions & 7 deletions src/_nebari/stages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from kubernetes.client.rest import ApiException

from _nebari.provider import helm, kubernetes, kustomize, opentofu
from _nebari.stages.tf_objects import NebariTerraformState
from _nebari.stages.tf_objects import (
NebariOpentofuRequiredProvider,
NebariOpentofuRequiredVersion,
)
from nebari.hookspecs import NebariStage

KUSTOMIZATION_TEMPLATE = "kustomization.yaml.tmpl"
Expand Down Expand Up @@ -65,7 +68,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 +145,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 +209,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 +220,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 All @@ -244,7 +243,20 @@ def state_imports(self) -> List[Tuple[str, str]]:
return []

def tf_objects(self) -> List[Dict]:
return [NebariTerraformState(self.name, self.config)]
return [
NebariOpentofuRequiredVersion(self.config),
]

def _tf_objects_required_providers(self) -> List[Dict]:
contents = [NebariOpentofuRequiredVersion(self.config)]
for obj in self.tf_objects():
match obj:
case {"terraform": {"required_providers": dict(providers)}}:
contents.extend(
NebariOpentofuRequiredProvider(provider, self.config)
for provider in providers.keys()
)
return contents

def render(self) -> Dict[pathlib.Path, str]:
contents = {
Expand All @@ -253,8 +265,24 @@ def render(self) -> Dict[pathlib.Path, str]:
)
}
for root, dirs, filenames in os.walk(self.template_directory):
root_path = pathlib.Path(root)
if any(filename.endswith(".tf") for filename in filenames) and (
pathlib.PosixPath("modules")
in root_path.relative_to(self.template_directory).parents
):
contents[
pathlib.Path(
self.stage_prefix,
pathlib.Path.relative_to(
root_path,
self.template_directory,
),
)
/ "_nebari.tf.json"
] = opentofu.tf_render_objects(self._tf_objects_required_providers())

for filename in filenames:
root_filename = pathlib.Path(root) / filename
root_filename = root_path / filename
with root_filename.open("rb") as f:
contents[
pathlib.Path(
Expand Down
23 changes: 21 additions & 2 deletions src/_nebari/stages/infrastructure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
from _nebari.provider.cloud import amazon_web_services, azure_cloud, google_cloud
from _nebari.stages.base import NebariTerraformStage
from _nebari.stages.kubernetes_services import SharedFsEnum
from _nebari.stages.tf_objects import NebariTerraformState
from _nebari.stages.tf_objects import (
NebariOpentofuRequiredProvider,
NebariTerraformState,
)
from _nebari.utils import (
AZURE_NODE_RESOURCE_GROUP_SUFFIX,
construct_azure_resource_group_name,
Expand Down Expand Up @@ -732,8 +735,12 @@ def state_imports(self) -> List[Tuple[str, str]]:
]

def tf_objects(self) -> List[Dict]:
resources = super().tf_objects()

if self.config.provider == schema.ProviderEnum.gcp:
return [
*resources,
NebariOpentofuRequiredProvider("google", self.config),
opentofu.Provider(
"google",
project=self.config.google_cloud_platform.project,
Expand All @@ -743,15 +750,27 @@ def tf_objects(self) -> List[Dict]:
]
elif self.config.provider == schema.ProviderEnum.azure:
return [
*resources,
NebariOpentofuRequiredProvider("azurerm", self.config),
NebariTerraformState(self.name, self.config),
]
elif self.config.provider == schema.ProviderEnum.aws:
return [
*resources,
NebariOpentofuRequiredProvider("aws", self.config),
opentofu.Provider("aws", region=self.config.amazon_web_services.region),
NebariTerraformState(self.name, self.config),
]
elif self.config.provider == schema.ProviderEnum.local:
return [
*resources,
NebariOpentofuRequiredProvider("kind", self.config),
NebariOpentofuRequiredProvider("docker", self.config),
NebariOpentofuRequiredProvider("kubectl", self.config),
NebariOpentofuRequiredProvider("kubernetes", self.config),
]
else:
return []
return resources

def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
if self.config.provider == schema.ProviderEnum.local:
Expand Down
9 changes: 0 additions & 9 deletions src/_nebari/stages/infrastructure/template/aws/versions.tf

This file was deleted.

9 changes: 0 additions & 9 deletions src/_nebari/stages/infrastructure/template/azure/versions.tf

This file was deleted.

9 changes: 0 additions & 9 deletions src/_nebari/stages/infrastructure/template/gcp/versions.tf

This file was deleted.

17 changes: 0 additions & 17 deletions src/_nebari/stages/infrastructure/template/local/main.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
terraform {
required_providers {
kind = {
source = "registry.terraform.io/tehcyx/kind"
version = "0.4.0"
}
docker = {
source = "kreuzwerker/docker"
version = "2.16.0"
}
kubectl = {
source = "gavinbunney/kubectl"
version = ">= 1.7.0"
}
}
}

provider "kind" {

}
Expand Down
6 changes: 5 additions & 1 deletion src/_nebari/stages/kubernetes_ingress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from _nebari.stages.tf_objects import (
NebariHelmProvider,
NebariKubernetesProvider,
NebariOpentofuRequiredProvider,
NebariTerraformState,
)
from nebari import schema
Expand Down Expand Up @@ -168,9 +169,12 @@ class KubernetesIngressStage(NebariTerraformStage):

def tf_objects(self) -> List[Dict]:
return [
NebariTerraformState(self.name, self.config),
*super().tf_objects(),
NebariOpentofuRequiredProvider("kubernetes", self.config),
NebariKubernetesProvider(self.config),
NebariOpentofuRequiredProvider("helm", self.config),
NebariHelmProvider(self.config),
NebariTerraformState(self.name, self.config),
]

def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
Expand Down
13 changes: 0 additions & 13 deletions src/_nebari/stages/kubernetes_ingress/template/versions.tf

This file was deleted.

7 changes: 6 additions & 1 deletion src/_nebari/stages/kubernetes_initialize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from _nebari.stages.tf_objects import (
NebariHelmProvider,
NebariKubernetesProvider,
NebariOpentofuRequiredProvider,
NebariTerraformState,
)
from nebari import schema
Expand Down Expand Up @@ -63,10 +64,14 @@ class KubernetesInitializeStage(NebariTerraformStage):
output_schema = OutputSchema

def tf_objects(self) -> List[Dict]:
resources = super().tf_objects()
return [
NebariTerraformState(self.name, self.config),
*resources,
NebariOpentofuRequiredProvider("kubernetes", self.config),
NebariKubernetesProvider(self.config),
NebariOpentofuRequiredProvider("helm", self.config),
NebariHelmProvider(self.config),
NebariTerraformState(self.name, self.config),
]

def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
Expand Down
13 changes: 0 additions & 13 deletions src/_nebari/stages/kubernetes_initialize/template/versions.tf

This file was deleted.

7 changes: 6 additions & 1 deletion src/_nebari/stages/kubernetes_keycloak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from _nebari.stages.tf_objects import (
NebariHelmProvider,
NebariKubernetesProvider,
NebariOpentofuRequiredProvider,
NebariTerraformState,
)
from _nebari.utils import modified_environ
Expand Down Expand Up @@ -218,9 +219,13 @@ class KubernetesKeycloakStage(NebariTerraformStage):

def tf_objects(self) -> List[Dict]:
return [
NebariTerraformState(self.name, self.config),
*super().tf_objects(),
NebariOpentofuRequiredProvider("kubernetes", self.config),
NebariKubernetesProvider(self.config),
NebariOpentofuRequiredProvider("helm", self.config),
NebariHelmProvider(self.config),
NebariOpentofuRequiredProvider("keycloak", self.config),
NebariTerraformState(self.name, self.config),
]

def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
Expand Down
13 changes: 0 additions & 13 deletions src/_nebari/stages/kubernetes_keycloak/template/versions.tf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

from _nebari.stages.base import NebariTerraformStage
from _nebari.stages.kubernetes_keycloak import Authentication
from _nebari.stages.tf_objects import NebariTerraformState
from _nebari.stages.tf_objects import (
NebariOpentofuRequiredProvider,
NebariTerraformState,
)
from nebari import schema
from nebari.hookspecs import NebariStage, hookimpl

Expand All @@ -26,7 +29,11 @@ class KubernetesKeycloakConfigurationStage(NebariTerraformStage):

def tf_objects(self) -> List[Dict]:
return [
*super().tf_objects(),
NebariTerraformState(self.name, self.config),
NebariOpentofuRequiredProvider("helm", self.config),
NebariOpentofuRequiredProvider("kubernetes", self.config),
NebariOpentofuRequiredProvider("keycloak", self.config),
]

def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
Expand Down
Loading
Loading