Skip to content

Commit 89da6a3

Browse files
authored
Merge pull request #26 from fluxcd/example
Add example to readme
2 parents 4e735cd + 185f272 commit 89da6a3

File tree

1 file changed

+57
-10
lines changed

1 file changed

+57
-10
lines changed

README.md

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,75 @@
11
# terraform-provider-flux
22

3-
This is a Terraform provider for Flux v2, it enables bootstrap a Kubernetes custer with Flux v2 using terraform.
3+
This is the Terraform provider for Flux v2.
4+
The provider allows you to install Flux on Kubernetes
5+
and configure it to reconcile the cluster state from a Git repository.
46

57
## Example Usage
68

7-
The provider is consists of two data sources `flux_install` and `flux_sync` the data sources are corresponding to [fluxv2 manifests](https://pkg.go.dev/github.com/fluxcd/[email protected]/pkg/manifestgen)
9+
The provider consists of two data sources `flux_install` and `flux_sync`,
10+
the data sources are corresponding to [fluxv2 manifests](https://pkg.go.dev/github.com/fluxcd/[email protected]/pkg/manifestgen).
811

9-
The data sources are returing `YAML` manifest so a second provider is needed to apply the manifest into the Kubernetes cluster. See example folder.
10-
11-
The `flux_install` generates manifests to install the `fluxv2` components.
12+
The `flux_install` data source generates a multi-doc YAML with Kubernetes manifests that can be used to install or upgrade Flux:
1213

1314
```hcl
14-
# Flux
15+
# Generate manifests
1516
data "flux_install" "main" {
16-
target_path = "staging-cluster"
17+
target_path = "production"
18+
arch = "amd64"
19+
network_policy = false
20+
version = "latest"
21+
}
22+
23+
# Split multi-doc YAML with
24+
# https://registry.terraform.io/providers/gavinbunney/kubectl/latest
25+
data "kubectl_file_documents" "apply" {
26+
content = data.flux_install.main.content
27+
}
28+
29+
# Apply manifests on the cluster
30+
resource "kubectl_manifest" "apply" {
31+
for_each = { for v in data.kubectl_file_documents.apply.documents : sha1(v) => v }
32+
yaml_body = each.value
1733
}
1834
```
1935

20-
`flux_sync` the initial source manifest.
36+
The `flux_sync` data source generates a multi-doc YAML containing the `GitRepository` and `Kustomization`
37+
manifests that configure Flux to sync the cluster with the specified repository:
2138

2239
```hcl
40+
# Generate manifests
2341
data "flux_sync" "main" {
24-
target_path = "staging-cluster"
25-
url = "ssh://[email protected]/${var.github_owner}/${var.repository_name}.git"
42+
target_path = "production"
43+
url = "https://github.com/${var.github_owner}/${var.repository_name}"
44+
}
45+
46+
# Split multi-doc YAML with
47+
# https://registry.terraform.io/providers/gavinbunney/kubectl/latest
48+
data "kubectl_file_documents" "sync" {
49+
content = data.flux_sync.main.content
50+
}
51+
52+
# Apply manifests on the cluster
53+
resource "kubectl_manifest" "sync" {
54+
depends_on = [kubectl_manifest.apply]
55+
56+
for_each = { for v in data.kubectl_file_documents.sync.documents : sha1(v) => v }
57+
yaml_body = each.value
58+
}
59+
60+
# Generate a Kubernetes secret with the Git credentials
61+
resource "kubernetes_secret" "main" {
62+
depends_on = [kubectl_manifest.apply]
63+
64+
metadata {
65+
name = data.flux_sync.main.name
66+
namespace = data.flux_sync.main.namespace
67+
}
68+
69+
data = {
70+
username = "git"
71+
password = var.flux_token
72+
}
2673
}
2774
```
2875

0 commit comments

Comments
 (0)