diff --git a/src/_nebari/constants.py b/src/_nebari/constants.py index 8ca5497407..482d8c6637 100644 --- a/src/_nebari/constants.py +++ b/src/_nebari/constants.py @@ -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": { @@ -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": { @@ -75,7 +75,7 @@ }, "kubernetes": { "_name": "kubernetes", - "source": "opentofu/kubernetes", + "source": "hashicorp/kubernetes", "version": ">= 2.20.0", }, } diff --git a/src/_nebari/stages/base.py b/src/_nebari/stages/base.py index 46d96cd5b5..728094e15b 100644 --- a/src/_nebari/stages/base.py +++ b/src/_nebari/stages/base.py @@ -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" @@ -244,6 +247,17 @@ 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( @@ -251,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(