Skip to content

[FIX] Terraform provider version inconsistency within stages#2862

Closed
smokestacklightnin wants to merge 33 commits intonebari-dev:mainfrom
smokestacklightnin:opentofu/stages/sync-versions
Closed

[FIX] Terraform provider version inconsistency within stages#2862
smokestacklightnin wants to merge 33 commits intonebari-dev:mainfrom
smokestacklightnin:opentofu/stages/sync-versions

Conversation

@smokestacklightnin
Copy link
Copy Markdown
Contributor

@smokestacklightnin smokestacklightnin commented Nov 24, 2024

Reference Issues or PRs

Fixes #2614

What does this implement/fix?

Put a x in the boxes that apply

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds a feature)
  • Breaking change (fix or feature that would cause existing features not to work as expected)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • Other (please describe):

Testing

  • Did you test the pull request locally?
  • Did you add new tests?

How to test this PR?

Any other comments?

The main change in this PR is that Terraform/OpenTofu versions and required providers are removed from the stage templates and instead injected via stages.tf_objects with version data from constants.py. stages.tf_objects.NebariOpentofuRequiredVersion and stages.tf_objects.NebariOpentofuRequiredProvider were added.

Now all subclasses of NebariTerraformStage present with a tf_objects method except terraform_state will call include the result of super().tf_objects in their return value:

class FooStage(NebariTerraformStage):
    def tf_objects(self) -> List[Dict]:
        return [
            *super().tf_objects(),
            ...,
        ]    

This way we can also inject NebariOpentofuRequiredVersion into NebariTerraformStage and have subclasses inherit it.

@smokestacklightnin smokestacklightnin requested review from marcelovilla and viniciusdc and removed request for marcelovilla and viniciusdc November 24, 2024 03:13
@smokestacklightnin smokestacklightnin force-pushed the opentofu/stages/sync-versions branch from fdddddb to dd64020 Compare November 25, 2024 03:14
@smokestacklightnin smokestacklightnin force-pushed the opentofu/stages/sync-versions branch from 5c422da to 8923dda Compare November 25, 2024 03:32
@smokestacklightnin smokestacklightnin force-pushed the opentofu/stages/sync-versions branch from d8f1409 to 1c0be1e Compare December 2, 2024 02:02
@smokestacklightnin
Copy link
Copy Markdown
Contributor Author

smokestacklightnin commented Dec 3, 2024

I've executed the changes I intended to make, however, when running Nebari, submodules are not inheriting required providers from the parent module. In particular, this is happening in some of the following modules:

./kubernetes_ingress/template/modules/kubernetes/ingress/
./kubernetes_services/template/modules/kubernetes/cephfs-mount/
./kubernetes_services/template/modules/kubernetes/
./kubernetes_services/template/modules/kubernetes/nfs-mount/
./kubernetes_services/template/modules/kubernetes/forwardauth/
./kubernetes_services/template/modules/kubernetes/nfs-server/
./kubernetes_services/template/modules/kubernetes/services/jupyterhub-ssh/
./kubernetes_services/template/modules/kubernetes/services/jupyterhub/
./kubernetes_services/template/modules/kubernetes/services/keycloak-client/
./kubernetes_services/template/modules/kubernetes/services/
./kubernetes_services/template/modules/kubernetes/services/redis/
./kubernetes_services/template/modules/kubernetes/services/monitoring/
./kubernetes_services/template/modules/kubernetes/services/monitoring/loki/
./kubernetes_services/template/modules/kubernetes/services/postgresql/
./kubernetes_services/template/modules/kubernetes/services/rook-ceph/
./kubernetes_services/template/modules/kubernetes/services/dask-gateway/
./kubernetes_services/template/modules/kubernetes/services/minio/
./kubernetes_services/template/modules/kubernetes/services/argo-workflows/
./kubernetes_services/template/modules/kubernetes/services/conda-store/
./nebari_tf_extensions/template/modules/nebariextension/
./nebari_tf_extensions/template/modules/helm-extensions/
./kubernetes_initialize/template/modules/
./kubernetes_initialize/template/modules/initialization/
./kubernetes_initialize/template/modules/cluster-autoscaler/
./kubernetes_initialize/template/modules/traefik_crds/
./kubernetes_initialize/template/modules/extcr/
./kubernetes_initialize/template/modules/nvidia-installer/
./kubernetes_keycloak/template/modules/kubernetes/keycloak-helm/

Just to see if it would work, I tried adding the correct required providers to those locations. It worked, so this suggest that it might be a good option to be able to dynamically inject required providers from constants.py this would be generalizing what is currently done at the root module to submodules as well.

@viniciusdc Do you have any input?

CC: @marcelovilla

@viniciusdc
Copy link
Copy Markdown
Contributor

viniciusdc commented Jan 6, 2025

I will have a look, we need to make the issues with the double version we noticed before are not happening anymore. Thanks for all the fantastic work so far @smokestacklightnin

@smokestacklightnin
Copy link
Copy Markdown
Contributor Author

I will have a look, we need to make the issues with the double version we noticed before are not happening anymore. Thanks for all the fantastic work so far @smokestacklightnin

Pinging @viniciusdc

@viniciusdc
Copy link
Copy Markdown
Contributor

viniciusdc commented Jan 14, 2025

To be included in 2025.1.2 release, for ref. check the parent issue.

@smokestacklightnin smokestacklightnin force-pushed the opentofu/stages/sync-versions branch from 991114e to 469d45e Compare February 1, 2025 00:56
@viniciusdc
Copy link
Copy Markdown
Contributor

I am reviewing this now

@viniciusdc viniciusdc added the status: in review 👀 This PR is currently being reviewed by the team label Feb 3, 2025
Copy link
Copy Markdown
Contributor

@viniciusdc viniciusdc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am encountering an error runing this localyly

[tofu]: Providers are signed by their developers.
[tofu]: If you'd like to know more about provider signing, you can read about it here:
[tofu]: https://opentofu.org/docs/cli/plugins/signing/
[tofu]: ╷
[tofu]: │ Error: Failed to query available provider packages
[tofu]: │ 
[tofu]: │ Could not retrieve the list of available versions for provider
[tofu]: │ hashicorp/keycloak: provider registry registry.opentofu.org does not have a
[tofu]: │ provider named registry.opentofu.org/hashicorp/keycloak
[tofu]: │ 
[tofu]: │ Did you intend to use mrparkers/keycloak? If so, you must specify that
[tofu]: │ source address in each module which requires that provider. To see which
[tofu]: │ modules are currently depending on hashicorp/keycloak, run the following
[tofu]: │ command:
[tofu]: │     tofu providers
[tofu]: │ 
[tofu]: │ If you believe this provider is missing from the registry, please submit a
[tofu]: │ issue on the OpenTofu Registry
[tofu]: │ https://github.com/opentofu/registry/issues/new/choose

but I remember this been addressed on another PR a while ago, so maybe the same fix needs to be moved here as well. It might be related to how versions were handled currently. Overall all constraints are there.

Also, there are no tests to make sure we are actually getting the correct versions and this code is doing what's supposed to do, so I will include then later this week -- since CI runs a local deployment with local terraform state, we can parse the state files when they exists and compare the installed version with it's expected constraints.

The following are notes to myself:

Comment on lines +268 to +283
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())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, this was included since we also wanted to render the _tf.json files for the module versions right? I've been testing this locally so far today, and even without this the actual versions have been correctly used by each stage and its underlying modules. I will follow on what we discussed back then to refresh my head around why we went this route, but we might not need ti anymore :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viniciusdc from an offline discussion we had, I understand this is probably not needed. We can remove it and retest

elif self.config.provider == schema.ProviderEnum.local:
return [
*resources,
NebariOpentofuRequiredProvider("kind", self.config),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think originally, I had in mind a *RequiredProviders class for accommodating all providers for each stage in a single sweep, but this also does the job.

@dcmcand
Copy link
Copy Markdown
Contributor

dcmcand commented Mar 3, 2025

@smokestacklightnin are you gonna have time to address @viniciusdc 's comments and fix the merge conflicts? or should someone on the maintenance team take over this PR.

@smokestacklightnin
Copy link
Copy Markdown
Contributor Author

@smokestacklightnin are you gonna have time to address @viniciusdc 's comments and fix the merge conflicts? or should someone on the maintenance team take over this PR.

@dcmcand I have been instructed to spend all my time working on a different project, so I will not be able to work on this PR for the forseeable future.

@dcmcand dcmcand moved this from In review/QA 👀 to In progress 🏗 in 🪴 Nebari Project Management Mar 6, 2025
@dcmcand dcmcand removed this from the Nebari Maintenance Team - Backlog milestone Mar 14, 2025
@viniciusdc
Copy link
Copy Markdown
Contributor

Hey @smokestacklightnin, we will be closing this for now since we can't thoroughly review this right now. I will re-open this in a new PR referencing the work.

@viniciusdc viniciusdc added needs: follow-up 📫 Someone needs to get back to this issue or PR and removed status: in review 👀 This PR is currently being reviewed by the team labels Aug 5, 2025
@smokestacklightnin
Copy link
Copy Markdown
Contributor Author

Hey @smokestacklightnin, we will be closing this for now since we can't thoroughly review this right now. I will re-open this in a new PR referencing the work.

Sounds good!

@dcmcand dcmcand closed this Nov 10, 2025
@github-project-automation github-project-automation bot moved this from In progress 🏗 to Done 💪🏾 in 🪴 Nebari Project Management Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: follow-up 📫 Someone needs to get back to this issue or PR

Projects

Status: Done 💪🏾

Development

Successfully merging this pull request may close these issues.

[BUG] - Terraform provider version inconsistency within stages

4 participants