Skip to content

Commit 9d2f760

Browse files
authored
Support for terraform registry (#27)
* chore: init terraform registry docs * chore: release with goreleaser
1 parent 0486a2e commit 9d2f760

File tree

6 files changed

+262
-103
lines changed

6 files changed

+262
-103
lines changed

.github/workflows/release.yml

Lines changed: 25 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -6,104 +6,30 @@ on:
66
tags: ["v*"]
77

88
jobs:
9-
draft_release:
10-
name: Draft release
9+
goreleaser:
1110
runs-on: ubuntu-latest
12-
outputs:
13-
tag: ${{ steps.get_tag.outputs.tag }}
14-
release_id: ${{ steps.create_draft_release.outputs.release_id }}
15-
upload_url: ${{ steps.create_draft_release.outputs.upload_url }}
1611
steps:
17-
- name: Get tag
18-
id: get_tag
19-
shell: bash
20-
# Github actions does not make getting the tag name easy...
21-
run: echo "::set-output name=tag::${GITHUB_REF#refs\/tags\/}"
22-
23-
# actions/create_release official action returns 'untagged-XXX' as release tag (bug).
24-
- name: Create draft Release
25-
id: create_draft_release
26-
shell: bash
27-
env:
28-
tag: ${{ steps.get_tag.outputs.tag }}
29-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30-
run: |
31-
RESULT=$(curl -sfL -H "Authorization: token ${GITHUB_TOKEN}" -XPOST --data '{"tag_name":"${{ env.tag }}","name":"${{ env.tag }}","draft":true}' https://api.github.com/repos/${{ github.repository }}/releases)
32-
33-
RELEASE_ID=$(echo $RESULT | jq -r .id)
34-
UPLOAD_URL=$(echo $RESULT | jq -r .upload_url)
35-
36-
echo "::set-output name=release_id::${RELEASE_ID}"
37-
echo "::set-output name=upload_url::${UPLOAD_URL}"
38-
39-
assets:
40-
name: Assets
41-
needs: draft_release
42-
strategy:
43-
fail-fast: true
44-
matrix:
45-
arch: [amd64, 386, arm]
46-
os: [linux, darwin, windows]
47-
exclude:
48-
- os: darwin
49-
arch: 386
50-
- os: darwin
51-
arch: arm
52-
- os: windows
53-
arch: arm
54-
runs-on: ubuntu-latest
55-
env:
56-
asset: terraform-provider-argocd_${{ needs.draft_release.outputs.tag }}_${{ matrix.os }}_${{ matrix.arch }}.gz
57-
asset_build: terraform-provider-argocd_${{ needs.draft_release.outputs.tag }}
58-
asset_gzip_suffix: _${{ matrix.os }}_${{ matrix.arch }}.gz
59-
upload_url: ${{ needs.draft_release.outputs.upload_url }}
60-
steps:
61-
- name: Checkout code
62-
uses: actions/checkout@v2
63-
64-
- uses: actions/setup-go@v1
65-
with:
66-
go-version: 1.14
67-
68-
- name: Restore Go cache
69-
uses: actions/cache@v1
70-
with:
71-
path: ~/go/pkg/mod
72-
key: ${{ matrix.os }}-${{ matrix.arch }}-go-${{ hashFiles('**/go.sum') }}
73-
restore-keys: |
74-
${{ matrix.os }}-${{ matrix.arch }}-go-
75-
76-
- name: Build ${{ matrix.os }}-${{ matrix.arch }}
77-
env:
78-
GOARCH: ${{ matrix.arch }}
79-
GOOS: ${{ matrix.os }}
80-
run: |
81-
CGO_ENABLED=0 go build --ldflags '-s -w -extldflags "-static"' --tags netgo -a -o ${{ env.asset_build }}
82-
gzip --name --suffix ${{ env.asset_gzip_suffix }} ${{ env.asset_build }}
83-
84-
- name: Upload Release Asset
85-
uses: actions/upload-release-asset@v1
86-
env:
87-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88-
with:
89-
upload_url: ${{ env.upload_url }}
90-
asset_path: ./${{ env.asset }}
91-
asset_name: ${{ env.asset }}
92-
asset_content_type: application/gzip
93-
94-
publish_release:
95-
name: Publish release
96-
runs-on: ubuntu-latest
97-
needs:
98-
- assets
99-
- draft_release
100-
env:
101-
release_id: ${{ needs.draft_release.outputs.release_id }}
102-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103-
steps:
104-
- name: Publish release
105-
shell: bash
106-
env:
107-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108-
run: |
109-
curl -sfL -H "Authorization: token ${GITHUB_TOKEN}" -XPATCH --data '{"draft":false}' https://api.github.com/repos/${{ github.repository }}/releases/${{ env.release_id }}
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v2
19+
with:
20+
go-version: 1.14
21+
22+
- name: Import GPG key
23+
id: import_gpg
24+
uses: crazy-max/ghaction-import-gpg@v2
25+
env:
26+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
27+
28+
- name: Run GoReleaser
29+
uses: goreleaser/goreleaser-action@v2
30+
with:
31+
version: latest
32+
args: release --rm-dist
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}

.goreleaser.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
builds:
3+
- env:
4+
- CGO_ENABLED=0
5+
mod_timestamp: '{{ .CommitTimestamp }}'
6+
flags:
7+
- -trimpath
8+
ldflags:
9+
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
10+
goos:
11+
- windows
12+
- linux
13+
- darwin
14+
goarch:
15+
- amd64
16+
- arm
17+
- arm64
18+
binary: '{{ .ProjectName }}_v{{ .Version }}'
19+
archives:
20+
- format: zip
21+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
22+
checksum:
23+
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
24+
algorithm: sha256
25+
signs:
26+
- artifacts: checksum
27+
args:
28+
- "--batch"
29+
- "--local-user"
30+
- "{{ .Env.GPG_FINGERPRINT }}"
31+
- "--output"
32+
- "${signature}"
33+
- "--detach-sign"
34+
- "${artifact}"
35+
release:
36+
draft: true
37+
disable: false
38+
github:
39+
owner: oboukili
40+
name: terraform-provider-argocd
41+
changelog:
42+
skip: false
43+
filters:
44+
exclude:
45+
- '^docs:'
46+
- '^chore'

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ resource "argocd_project" "myproject" {
125125
role {
126126
name = "testrole"
127127
policies = [
128-
"p, proj:%s:testrole, applications, override, %s/*, allow",
129-
"p, proj:%s:testrole, applications, sync, %s/*, allow",
128+
"p, proj:myproject:testrole, applications, override, myproject/*, allow",
129+
"p, proj:myproject:testrole, applications, sync, myproject/*, allow",
130130
]
131131
}
132132
role {
133133
name = "anotherrole"
134134
policies = [
135-
"p, proj:%s:testrole, applications, get, %s/*, allow",
136-
"p, proj:%s:testrole, applications, sync, %s/*, deny",
135+
"p, proj:myproject:testrole, applications, get, myproject/*, allow",
136+
"p, proj:myproject:testrole, applications, sync, myproject/*, deny",
137137
]
138138
}
139139
sync_window {

docs/index.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ArgoCD Provider
2+
3+
A Terraform provider for [ArgoCD](https://argoproj.github.io/argo-cd/).
4+
5+
## Example Usage
6+
7+
```hcl
8+
provider "argocd" {
9+
server_addr = "argocd.local:443"
10+
auth_token = "1234..."
11+
}
12+
```
13+
14+
## Argument Reference
15+
16+
* `server_addr` - (Required) ArgoCD server address with port.
17+
* `auth_token` - (Optional) ArgoCD authentication token, taked precedence over `username`/`password`. Can be set through the `ARGOCD_AUTH_TOKEN` environment variable.
18+
* `username` - (Optional) authentication username. Can be set through the `ARGOCD_AUTH_USERNAME` environment variable.
19+
* `password` - (Optional) authentication password. Can be set through the `ARGOCD_AUTH_PASSWORD` environment variable.
20+
* `cert_file` - (Optional) Additional root CA certificates file to add to the client TLS connection pool.
21+
* `plain_text` - (Optional) Boolean, whether to initiate an unencrypted connection to ArgoCD server.
22+
* `context` - (Optional) Kubernetes context to load from an existing `.kube/config` file. Can be set through `ARGOCD_CONTEXT` environment variable.
23+
* `user_agent` - (Optional)
24+
* `grpc_web` - (Optional) Whether to use gRPC web proxy client.
25+
* `port_forward` - (Optional)
26+
* `port_forward_with_namespace` - (Optional)
27+
* `headers` - (Optional) Additional headers to add to each request to the ArgoCD server.
28+
* `insecure` - (Optional) Whether to skip TLS server certificate. Can be set through the `ARGOCD_INSECURE` environment variable.

docs/resources/project.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# argocd_project
2+
3+
Creates an ArgoCD project.
4+
5+
## Example Usage
6+
7+
```hcl
8+
resource "argocd_project" "myproject" {
9+
metadata {
10+
name = "myproject"
11+
namespace = "argocd"
12+
labels = {
13+
acceptance = "true"
14+
}
15+
annotations = {
16+
"this.is.a.really.long.nested.key" = "yes, really!"
17+
}
18+
}
19+
20+
spec {
21+
description = "simple project"
22+
source_repos = ["*"]
23+
24+
destination {
25+
server = "https://kubernetes.default.svc"
26+
namespace = "default"
27+
}
28+
destination {
29+
server = "https://kubernetes.default.svc"
30+
namespace = "foo"
31+
}
32+
cluster_resource_whitelist {
33+
group = "rbac.authorization.k8s.io"
34+
kind = "ClusterRoleBinding"
35+
}
36+
cluster_resource_whitelist {
37+
group = "rbac.authorization.k8s.io"
38+
kind = "ClusterRole"
39+
}
40+
namespace_resource_blacklist {
41+
group = "networking.k8s.io"
42+
kind = "Ingress"
43+
}
44+
orphaned_resources = {
45+
warn = true
46+
}
47+
role {
48+
name = "testrole"
49+
policies = [
50+
"p, proj:myproject:testrole, applications, override, myproject/*, allow",
51+
"p, proj:myproject:testrole, applications, sync, myproject/*, allow",
52+
]
53+
}
54+
role {
55+
name = "anotherrole"
56+
policies = [
57+
"p, proj:myproject:testrole, applications, get, myproject/*, allow",
58+
"p, proj:myproject:testrole, applications, sync, myproject/*, deny",
59+
]
60+
}
61+
sync_window {
62+
kind = "allow"
63+
applications = ["api-*"]
64+
clusters = ["*"]
65+
namespaces = ["*"]
66+
duration = "3600s"
67+
schedule = "10 1 * * *"
68+
manual_sync = true
69+
}
70+
sync_window {
71+
kind = "deny"
72+
applications = ["foo"]
73+
clusters = ["in-cluster"]
74+
namespaces = ["default"]
75+
duration = "12h"
76+
schedule = "22 1 5 * *"
77+
manual_sync = false
78+
}
79+
}
80+
}
81+
82+
```
83+
84+
## Argument Reference
85+
86+
* `metadata` - (Required) Standard Kubernetes API service's metadata. For more info see the [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata).
87+
* `spec` - (Required) The project specification, the nested attributes are documented below.
88+
89+
The `metadata` block can have the following attributes:
90+
91+
* `name` - (Required) The project name, must be unique, cannot be updated.
92+
* `annotations` - (Optional) An unstructured key value map stored with the config map that may be used to store arbitrary metadata. **By default, the provider ignores any annotations whose key names end with kubernetes.io. This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem)**. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/).
93+
* `labels` - (Optional) Map of string keys and values that can be used to organize and categorize (scope and select) the config map. May match selectors of replication controllers and services. **By default, the provider ignores any labels whose key names end with kubernetes.io. This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem).** For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/).
94+
95+
The `spec` block can have the following attributes:
96+
97+
* `destination` - (Required) The allowed cluster/namespace project destination, can be repeated multiple times.
98+
* `source_repos` - (Required) List of strings containing allowed application repositories URLs for the project. Can be set to `["*"]` to allow all configured repositories configured in ArgoCD.
99+
* `cluster_resource_whitelist` - (Optional) Cluster-scoped resource allowed to be managed by the project applications, can be repeated multiple times.
100+
* `description` - (Optional)
101+
* `orphaned_resources` - (Optional) A key value map to control orphaned resources monitoring,
102+
* `namespace_resource_blacklist` - (Optional) Namespaced-scoped resources allowed to be managed by the project applications, can be repeated multiple times.
103+
* `role` - (Optional) can be repeated multiple times.
104+
* `sync_window` - (Optional) can be repeated multiple times.
105+
106+
Each `cluster_resource_whitelist` block can have the following attributes:
107+
* `group` - (Optional) The Kubernetes resource Group to match for.
108+
* `kind` - (Optional) The Kubernetes resource Kind to match for.
109+
110+
The `orphaned_resources` map can have the following attributes:
111+
* `warn` - Boolean, defaults to `false`.
112+
113+
Each `namespace_resource_blacklist` block can have the following attributes:
114+
* `group` - (Optional) The Kubernetes resource Group to match for.
115+
* `kind` - (Optional) The Kubernetes resource Kind to match for.
116+
117+
Each `role` block can have the following attributes:
118+
* `name` - (Required) Name of the role.
119+
* `policies` - (Required) list of Casbin formated strings that define access policies for the role in the project, For more information, read the [ArgoCD RBAC reference](https://argoproj.github.io/argo-cd/operator-manual/rbac/#rbac-permission-structure).
120+
* `description` - (Optional)
121+
* `groups` - (Optional) List of OIDC group claims bound to this role.
122+
123+
Each `sync_window` block can have the following attributes:
124+
* `applications` - (Optional) List of applications the window will apply to.
125+
* `clusters` - (Optional) List of clusters the window will apply to.
126+
* `duration` - (Optional) amount of time the sync window will be open.
127+
* `kind` - (Optional) Defines if the window allows or blocks syncs, allowed values are `allow` or `deny`.
128+
* `manual_sync` - (Optional) Boolean, enables manual syncs when they would otherwise be blocked.
129+
* `namespaces` - (Optional) List of namespaces that the window will apply to.
130+
* `schedule` - (Optional) Time the window will begin, specified in cron format.

docs/resources/token.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# argocd_project_token
2+
3+
Creates an ArgoCD role project JSON Web Token.
4+
5+
## Example Usage
6+
7+
```hcl
8+
resource "argocd_project_token" "secret" {
9+
project = "someproject"
10+
role = "foobar"
11+
description = "short lived token"
12+
expires_in = "1h"
13+
renew_before = "30m"
14+
}
15+
```
16+
17+
## Argument Reference
18+
19+
* `project` - (Required) The project name associated with the token.
20+
* `role` - (Required) The project role associated with the token, the role must exist beforehand.
21+
* `description` - (Optional)
22+
* `expires_in` - (Optional) An expiration duration, valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
23+
* `renew_before` - (Optional) duration to control token silent regeneration, valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". If `expires_in` is set, Terraform will regenerate the token if `expires_in - renew_before < currentDate`.
24+
25+
## Attribute Reference
26+
27+
* `jwt` - The raw JWT as a string.
28+
* `issued_at` - Unix timestamp upon which the token was issued at, as a string.
29+
* `expires_at` - If `expires_in` is set, Unix timestamp upon which the token will expire, as a string.

0 commit comments

Comments
 (0)