<p>You don't need these blocks:</p>
<pre><code>provider &quot;flux&quot; {
...
}
</code></pre>
<p>and</p>
<pre><code>resource &quot;flux_bootstrap_git&quot; &quot;this&quot; {
...
}
</code></pre>
<p>Azure does it for you with <code>azurerm_kubernetes_flux_configuration</code></p>
<p>btw check your var.aks_cluster_id</p>

CC BY-SA 4.0
2024-05-21T07:17:28.683Z
Thanks! That was indeed the Problem. I used both possible ways to set it up because i was misleaded a blog post.
What do you meand with checking my cluster id?
Andresch Serj
CC BY-SA 4.0
2024-05-18T20:02:41.497Z
2024-05-18T20:02:41.497Z
Bobby Donchev
<p>I use terraform to set up a cluster and install fluxcd on it.
The cluster is set up correctly (i see both in azure portal).</p>
<p>In the bootstrap step however, i get an error showing that flux tries to access a cluster that i do not know and do not have access to (can't find it in azure portal).</p>
<pre><code> Error: Bootstrap run error
│ 
│   with module.flux.flux_bootstrap_git.this,
│   on modules/flux/main.tf line 58, in resource &quot;flux_bootstrap_git&quot; &quot;this&quot;:
│   58: resource &quot;flux_bootstrap_git&quot; &quot;this&quot; {
│ 
│ CustomResourceDefinition/alerts.notification.toolkit.fluxcd.io dry-run failed: Get
│ &quot;https://****-*****.westeurope.azmk8s.io:443/api?timeout=32s&quot;: dial tcp: lookup
│ ****-*****.westeurope.azmk8s.io on ***.***.***.53:53: no such host
</code></pre>
<p>Here is how i setup/install flux on the cluster:</p>
<pre><code>provider &quot;flux&quot; {
  kubernetes = {
    config_path = &quot;~/.kube/config&quot;
  }
  git = {
    author_email = &quot;*******@*******.com&quot;
    url = &quot;https://dev.azure.com/*******/*******/_git/flux&quot;
    http = {
      username = &quot;*******@*******.com&quot;
      password = &quot;*******&quot;
    }
  }
}

resource &quot;azurerm_kubernetes_cluster_extension&quot; &quot;flux&quot; {
  name           = &quot;flux&quot;
  cluster_id     = var.aks_cluster_id
  extension_type = &quot;microsoft.flux&quot;
}

resource &quot;azurerm_kubernetes_flux_configuration&quot; &quot;k8s_flux&quot; {
  name       = &quot;flux-system&quot;
  cluster_id = var.aks_cluster_id
  namespace  = &quot;flux-system&quot;

  git_repository {
    url             = &quot;https://*******@dev.azure.com/*******/*******/_git/flux&quot;
    reference_type  = &quot;branch&quot;
    reference_value = &quot;main&quot;
  }

  kustomizations {
    name                      = &quot;kustomization&quot;
    path                      = &quot;./clusters/test/00&quot;
    sync_interval_in_seconds  = 120
    retry_interval_in_seconds = 120
  }

  scope = &quot;cluster&quot;

  depends_on = [
    azurerm_kubernetes_cluster_extension.flux
  ]
}

resource &quot;flux_bootstrap_git&quot; &quot;this&quot; {
  path = &quot;clusters/test/&quot;
  components = [
    &quot;source-controller&quot;,
    &quot;kustomize-controller&quot;,
    &quot;helm-controller&quot;,
    &quot;notification-controller&quot;
  ]
  log_level = &quot;debug&quot;
  depends_on = [
    azurerm_kubernetes_cluster_extension.flux
  ]
}

</code></pre>
<p>Here is how i export the k8s config to use in the flux setup:</p>
<pre><code>resource &quot;local_file&quot; &quot;kubeconfig&quot; {
  depends_on   = [azurerm_kubernetes_cluster.aks]
  filename     = &quot;~/.kube/config&quot;
  content      = azurerm_kubernetes_cluster.aks.kube_config_raw
}
</code></pre>
<p>Here is how i set up the aks cluster: <a href="https://pastebin.com/aC7E7n9W" rel="nofollow noreferrer">https://pastebin.com/aC7E7n9W</a></p>

<kubernetes><terraform><azure><fluxcd>
Flux somehow tries to bootstrap on random cluster
Andresch Serj
# Flux somehow tries to bootstrap on random cluster

(Asked by: username_0 on 2024-05-06)

I use terraform to set up a cluster and install fluxcd on it.
The cluster is set up correctly (i see both in azure portal).
In the bootstrap step however, i get an error showing that flux tries to access a cluster that i do not know and do not have access to (can't find it in azure portal).
 Error: Bootstrap run error
│ 
│   with module.flux.flux_bootstrap_git.this,
│   on modules/flux/main.tf line 58, in resource "flux_bootstrap_git" "this":
│   58: resource "flux_bootstrap_git" "this" {
│ 
│ CustomResourceDefinition/alerts.notification.toolkit.fluxcd.io dry-run failed: Get
│ "https://****-*****.westeurope.azmk8s.io:443/api?timeout=32s": dial tcp: lookup
│ ****-*****.westeurope.azmk8s.io on ***.***.***.53:53: no such host

Here is how i setup/install flux on the cluster:
provider "flux" {
  kubernetes = {
    config_path = "~/.kube/config"
  }
  git = {
    author_email = "*******@*******.com"
    url = "https://dev.azure.com/*******/*******/_git/flux"
    http = {
      username = "*******@*******.com"
      password = "*******"
    }
  }
}

resource "azurerm_kubernetes_cluster_extension" "flux" {
  name           = "flux"
  cluster_id     = var.aks_cluster_id
  extension_type = "microsoft.flux"
}

resource "azurerm_kubernetes_flux_configuration" "k8s_flux" {
  name       = "flux-system"
  cluster_id = var.aks_cluster_id
  namespace  = "flux-system"

  git_repository {
    url             = "https://*******@dev.azure.com/*******/*******/_git/flux"
    reference_type  = "branch"
    reference_value = "main"
  }

  kustomizations {
    name                      = "kustomization"
    path                      = "./clusters/test/00"
    sync_interval_in_seconds  = 120
    retry_interval_in_seconds = 120
  }

  scope = "cluster"

  depends_on = [
    azurerm_kubernetes_cluster_extension.flux
  ]
}

resource "flux_bootstrap_git" "this" {
  path = "clusters/test/"
  components = [
    "source-controller",
    "kustomize-controller",
    "helm-controller",
    "notification-controller"
  ]
  log_level = "debug"
  depends_on = [
    azurerm_kubernetes_cluster_extension.flux
  ]
}


Here is how i export the k8s config to use in the flux setup:
resource "local_file" "kubeconfig" {
  depends_on   = [azurerm_kubernetes_cluster.aks]
  filename     = "~/.kube/config"
  content      = azurerm_kubernetes_cluster.aks.kube_config_raw
}

Here is how i set up the aks cluster: https://pastebin.com/aC7E7n9W

**Tags:** kubernetes, terraform, azure, fluxcd


---

## 1 answers

### Answer by username_1 on 2024-05-18. Score: 1 | Accepted answer

You don't need these blocks:
provider "flux" {
...
}

and
resource "flux_bootstrap_git" "this" {
...
}

Azure does it for you with azurerm_kubernetes_flux_configuration
btw check your var.aks_cluster_id

> **Comments:**
> **username_0**: Thanks! That was indeed the Problem. I used both possible ways to set it up because i was misleaded a blog post. What do you meand with checking my cluster id?  

---

