Skip to content

Commit

Permalink
Merge branch 'opentofu/stages/sync-versions-inject-from-parent' into …
Browse files Browse the repository at this point in the history
…opentofu/stages/sync-versions
  • Loading branch information
smokestacklightnin committed Dec 22, 2024
2 parents e31e7f8 + d8b0699 commit c4d3786
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/_nebari/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
REQUIRED_PROVIDERS = {
"aws": {
"_name": "aws",
"source": "opentofu/aws",
"source": "hashicorp/aws",
"version": "5.12.0",
},
"azurerm": {
"_name": "azurerm",
"source": "opentofu/azurerm",
"source": "hashicorp/azurerm",
"version": "=3.97.1",
},
"docker": {
Expand All @@ -50,12 +50,12 @@
},
"google": {
"_name": "google",
"source": "opentofu/google",
"source": "hashicorp/google",
"version": "4.83.0",
},
"helm": {
"_name": "helm",
"source": "opentofu/helm",
"source": "hashicorp/helm",
"version": "2.1.2",
},
"keycloak": {
Expand All @@ -75,7 +75,7 @@
},
"kubernetes": {
"_name": "kubernetes",
"source": "opentofu/kubernetes",
"source": "hashicorp/kubernetes",
"version": ">= 2.20.0",
},
}
34 changes: 32 additions & 2 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 NebariOpentofuRequiredVersion
from _nebari.stages.tf_objects import (
NebariOpentofuRequiredProvider,
NebariOpentofuRequiredVersion,
)
from nebari.hookspecs import NebariStage

KUSTOMIZATION_TEMPLATE = "kustomization.yaml.tmpl"
Expand Down Expand Up @@ -244,15 +247,42 @@ def tf_objects(self) -> List[Dict]:
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 = {
(self.stage_prefix / "_nebari.tf.json"): opentofu.tf_render_objects(
self.tf_objects()
)
}
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

0 comments on commit c4d3786

Please sign in to comment.