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

Depends_on ignored #38

Closed
BuckinghamIO opened this issue Sep 25, 2020 · 17 comments · Fixed by #47
Closed

Depends_on ignored #38

BuckinghamIO opened this issue Sep 25, 2020 · 17 comments · Fixed by #47

Comments

@BuckinghamIO
Copy link

BuckinghamIO commented Sep 25, 2020

When using Terraform with the Helmfile provider it completely ignores any depends on requirements.

In my instance I require this as some of my hooks actually setup credentials which are only available once the cluster is created. Since the Helmfile resource always try to generate a diff output regardless of the depends on requirement it fails every time on a fresh install unless I create Terraform and Helmfile seperately.

is there anyway I can work around this?

EDIT: the main cause of this issue is terraform plan also executes helmfile diff without taking into consideration if tiller is even present let alone if the cluster is even present

@mumoshu
Copy link
Owner

mumoshu commented Sep 25, 2020

@BuckinghamIO It should generally work. How are you providing KUBECONFIG envvar or kubeconfig_path attribute to your helmfile_release_set resource? The release set resource is programmed to skip running helmfile-diff when kubeconfig_path is empty, because it is set to empty by terraform plan.

A working example is https://github.com/mumoshu/terraform-provider-eksctl/blob/master/examples/productionsetup-alb/testdata/01-bootstrap/main.tf#L155. In this example, terraform plan does work even before creating the eksctl_cluster, because the helmfile provider skips running helmfile-diff when KUBECONFIG is empty.

To be clear, even if it is declared as KUBECONFIG = eksctl_cluster.blue.kubeconfig_path, terraform plan evaluates it to KUBECONFIG = "" before creating the dependent eksctl_cluster. But the helmfile provider skips running helmfile-diff when it is empty, plan succeeds and works as expected.

@mumoshu
Copy link
Owner

mumoshu commented Sep 25, 2020

In other words and from a developer's perspective, it is Terraform that ignores depends_on on plan, not the provider. So we need to understand every real-world use-case and implenment a workaround for each so that the provider "looks" like understanding depends_on, even if Terraform doesn't support it.

@mumoshu
Copy link
Owner

mumoshu commented Oct 19, 2020

@BuckinghamIO #42 may also fix your issue if this was due to that

@danil-fomichev
Copy link

@mumoshu here is a use-case example.

We would like to generate environment.yaml file with values imported from another modules and only after that run the helmfile_release_set resource. Right now we cannot do this because the provider runs "helmfile diff" and it fails because the file doesn't exist.

@mumoshu
Copy link
Owner

mumoshu commented Nov 9, 2020

@danil-fomichev How is environment.yaml used by your helmfile_release_set? An example helmfile_release_set definition would help!

@danil-fomichev
Copy link

@mumoshu it is included from helmfile.yaml:

bases:
- environment.yaml

obviously it must be generated before we run "helmfile diff".

The name of environment is specified in helmfile_release_set definition.

@mumoshu
Copy link
Owner

mumoshu commented Nov 9, 2020

@danil-fomichev Gotcha! Thanks for clarifying. AFAIK, there's no way to make some terraform resource's "plan" operation optional depending on condition. #38 (comment)

So the only way would be to enhance the provider to support something like skip_diff_on_missing_files = ["path/to/environment.yaml"] so that the provider can skip helmfile-diff before the files are generated somehow.

WDYT?

@danil-fomichev
Copy link

danil-fomichev commented Nov 9, 2020

@mumoshu great idea! And thank you!

@mumoshu
Copy link
Owner

mumoshu commented Nov 9, 2020

@danil-fomichev Thanks for confirming! I'll give it a try

@mumoshu
Copy link
Owner

mumoshu commented Nov 9, 2020

@BuckinghamIO Does the planned feature above #38 (comment) look like to work for your use-case, too?

mumoshu added a commit that referenced this issue Nov 10, 2020
mumoshu added a commit that referenced this issue Nov 10, 2020
* Add helmfile_release_set.skip_diff_on_missing_files

Resolves #38
@mumoshu
Copy link
Owner

mumoshu commented Nov 10, 2020

@danil-fomichev @BuckinghamIO skip_diff_on_missing_files is added since v0.10.0. Would you mind giving it a try?

@danil-fomichev
Copy link

@mumoshu Thank you so much! When approximately do you plan to publish it to registry.terraform.io?

@mumoshu
Copy link
Owner

mumoshu commented Nov 10, 2020

@danil-fomichev It should be available soon :) registry.terraform.io automatically syncs github releases so there should be nothing blocking that process on my end.

@danil-fomichev
Copy link

@mumoshu unfortunately it doesn't work as expected.

resource "helmfile_release_set" "infra" {
  depends_on            = [local_file.environment_file]
  working_directory     = var.helmfile_path
  environment           = var.environment.name
  kubeconfig            = var.kubeconfg_path
  environment_variables = local.environment_variables
  skip_diff_on_missing_files = [
    local_file.environment_file
  ]
}

it still runs 'helm diff' during 'terraform plan' and fails with error.

@danil-fomichev
Copy link

danil-fomichev commented Nov 12, 2020

It works when I set absolute path to the file instead of 'local_file.environment_file'. Not very nice looking code but it works.

Thanks!

@mumoshu
Copy link
Owner

mumoshu commented Nov 12, 2020

@danil-fomichev Thanks for the feedback! I'll definitely enahnce it to work with relative paths. Stay tuned.

@mumoshu
Copy link
Owner

mumoshu commented Nov 13, 2020

@danil-fomichev Since v0.10.1, it automatically coverts relative paths to absolute paths. Would you mind trying?

If it doesn't work as expected, try running terraform with TF_LOG=TRACE terraform plan so that you can see logs added in b24131f#diff-5cd325f86c36ad7da723fd859369712f88fe899ef97a4f3b286cda8f8625c6a9R12 for debugging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants