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 doesn't work with provider resources #118

Closed
hila3000 opened this issue Feb 7, 2023 · 3 comments
Closed

Depends_on doesn't work with provider resources #118

hila3000 opened this issue Feb 7, 2023 · 3 comments

Comments

@hila3000
Copy link

hila3000 commented Feb 7, 2023

Hi,

I have a resource to create Jenkins jobs-

resource "jenkins_job" "load_jobs" {
  for_each = fileset("${path.module}/jobs", "*")
  name     = each.value
  template = templatefile("${path.module}/jobs/${each.value}", {
    description = " ${each.value} Jenkins Job Created by Terraform"
  })
  depends_on = [helm_release.jenkins, helm_release.externaldns]
}

As you can see, I've set depends_on, on both the Jenkins helm chart and the externaldns resource that deploys the Jenkins A record to route53.

This is the provider config-

provider "jenkins" {
  server_url = "http://jenkins.domainname.net:8080/" 
  username   = "admin"           
  password   = kubernetes_secret.jenkins-users.data.jenkins-admin-password          
  ca_cert = ""                       
}

But when I try to deploy the jobs while the Jenkins is not deployed yet, I get-
Error: Get "http://jenkins.domainname.net:8080/api/json": dial tcp: lookup jenkins.domainname.net on 10.110.111.200:53: no such host
Only after I run terraform apply on the helm_release to deploy Jenkins and make sure external-dns already deployed so the Jenkins A record will get updated, then the error goes away and the resource gets applied (and jobs gets created).
Meaning - the depends_on doesn't work.

Is this a bug or a feature? :)
I assume it's related to the provider configuration - It needs to have the domain name available before trying to execute/evaluate anything under this provider, but there's no module output I can use for the server_url to make Terraform generate a "natural" dependency.

I got to have this dependency because I need to deploy the entire code in one run (vs. modular, as it currently works).

Please advise.
Thanks!

@github-actions
Copy link

github-actions bot commented Aug 7, 2023

Stale issue message

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2023
@taiidani taiidani reopened this Aug 26, 2023
@taiidani
Copy link
Owner

This sounds like it may be related to hashicorp/terraform#2430, in which terraform itself must initiate the jenkins provider at Plan time to inspect your resources, but cannot due to the Jenkins instance not being online yet.

There are a few solutions proposed in there -- the most common suggestion is to separate the jenkins provider resources from the resources deploying Jenkins (Helm) in separate root modules. I hope this helps!

@hila3000
Copy link
Author

That's what I eventually did - separated states, so the first, dependent one, always run first. That solved it for me.

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

No branches or pull requests

2 participants