Skip to content

Commit 1d31451

Browse files
BravoDeltaBDBoris van der Donck
authored andcommitted
Update examples and test pipeline to fix build. Add additional documentation. Update terraform docs. (#112)
PR to fix the build again before proposing changes to enable https://gitea.com/gitea/terraform-provider-gitea/issues/111. This is my first time contributing to a Terraform Provider, any thoughts or feedback will be greatly appreciated! No functionality is changed, only the examples, test pipelines and docs, so I did not increment the version of the provider. I am still a bit unsure about the lifecycle management of Terraform Providers. Should it be incremented anyway? Co-authored-by: Boris van der Donck <[email protected]> Reviewed-on: https://gitea.com/gitea/terraform-provider-gitea/pulls/112 Reviewed-by: techknowlogick <[email protected]> Co-authored-by: BravoDeltaBD <[email protected]> Co-committed-by: BravoDeltaBD <[email protected]>
1 parent 52fbca4 commit 1d31451

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+442
-330
lines changed

.gitea/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ jobs:
1616

1717
- name: Terraform fmt
1818
id: fmt
19-
run: terraform fmt -check
19+
run: terraform fmt -check -diff -recursive
2020
continue-on-error: true
21+
working-directory: examples
2122

2223
- name: Terraform Init
2324
id: init

CONTRIBUTING.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Contributing to the Gitea Terraform Provider
2+
3+
Thank you for your interest in contributing to the Gitea Terraform Provider! This document outlines the basic process to contribute effectively.
4+
5+
## Getting Started
6+
7+
1. **Fork the repository** on Gitea.
8+
2. **Clone your fork** locally.
9+
3. **Create a branch** for your changes.
10+
11+
12+
See also [Hashicorp's Terraform Provider tutorial](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-provider)
13+
14+
## Testing your changes
15+
16+
### Running a local Gitea instance
17+
18+
```bash
19+
docker run -p 3000:3000 gitea/gitea:latest-rootless
20+
```
21+
22+
Visit http://localhost:3000 and go through the setup:
23+
1. Url: http://localhost:3000
24+
2. Username: gitea_admin
25+
3. Password: gitea_admin
26+
27+
28+
### Using the local version of the Provider
29+
This involves 2 main steps:
30+
- `go install .` to install the provider binary.
31+
- Use .terraformrc file to point to that binary instead of the terraform registry.
32+
33+
See Terraform docs on [development overrides for provider developers](https://developer.hashicorp.com/terraform/cli/config/config-file#development-overrides-for-provider-developers)
34+
35+
Also see [this tutorial section](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-provider#prepare-terraform-for-local-provider-install) for a bit more context.
36+
37+
Example linux `~/.terraformrc` file:
38+
```
39+
provider_installation {
40+
41+
dev_overrides {
42+
"go-gitea/gitea" = "/home/<username>/go/bin"
43+
}
44+
45+
# For all other providers, install them directly from their origin provider
46+
# registries as normal. If you omit this, Terraform will _only_ use
47+
# the dev_overrides block, and so no other providers will be available.
48+
direct {}
49+
}
50+
```
51+
52+
### Applying the example module
53+
54+
With the local provider and the local Gitea instance set up properly as per above chapters, the example module can be applied:
55+
56+
- navigate into `examples/`
57+
- run terraform commands
58+
59+
60+

docs/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ description: |-
1616
terraform {
1717
required_providers {
1818
gitea = {
19-
source = "go-gitea/gitea"
19+
source = "go-gitea/gitea"
2020
version = "0.6.0"
2121
}
2222
}
2323
}
2424
2525
provider "gitea" {
26-
base_url = var.gitea_url # optionally use GITEA_BASE_URL env var
26+
base_url = var.gitea_url # optionally use GITEA_BASE_URL env var
2727
token = var.gitea_token # optionally use GITEA_TOKEN env var
2828
2929
# Username/Password authentication is mutally exclusive with token authentication
3030
# username = var.username # optionally use GITEA_USERNAME env var
3131
# password = var.password # optionally use GITEA_PASSWORD env var
3232
3333
# A file containing the ca certificate to use in case ssl certificate is not from a standard chain
34-
cacert_file = var.cacert_file
35-
34+
cacert_file = var.cacert_file
35+
3636
# If you are running a gitea instance with self signed TLS certificates
3737
# and you want to disable certificate validation you can deactivate it with this flag
38-
insecure = false
38+
insecure = false
3939
}
4040
```
4141

docs/resources/git_hook.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ if you want to procede, you need to enable server side hooks as stated [here](ht
2121
## Example Usage
2222

2323
```terraform
24-
resource "gitea_org" "test_org" {
25-
name = "test-org"
24+
resource "gitea_org" "example" {
25+
name = "git-hook-example-org"
2626
}
2727
28-
resource "gitea_repository" "org_repo" {
29-
username = gitea_org.test_org.name
30-
name = "org-test-repo"
28+
resource "gitea_repository" "example" {
29+
username = gitea_org.example.name
30+
name = "git-hook-example-repo"
3131
}
3232
3333
resource "gitea_git_hook" "org_repo_post_receive" {
3434
name = "post-receive"
35-
user = gitea_org.test_org.name
36-
repo = gitea_repository.org_repo.name
35+
user = gitea_org.example.name
36+
repo = gitea_repository.example.name
3737
content = file("${path.module}/post-receive.sh")
3838
}
3939
```

docs/resources/org.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Organisations are a way to group repositories and abstract permission management
1616
## Example Usage
1717

1818
```terraform
19-
resource "gitea_org" "test_org" {
20-
name = "test-org"
19+
resource "gitea_org" "example" {
20+
name = "org-example-org"
2121
}
2222
23-
resource "gitea_repository" "org_repo" {
24-
username = gitea_org.test_org.name
25-
name = "org-test-repo"
23+
resource "gitea_repository" "example" {
24+
username = gitea_org.example.name
25+
name = "org-example-repo"
2626
}
2727
```
2828

docs/resources/public_key.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@ description: |-
1414

1515
```terraform
1616
resource "gitea_user" "test" {
17-
username = "test"
18-
login_name = "test"
17+
username = "public-key-test"
18+
login_name = "public-key-test"
1919
password = "Geheim1!"
20-
20+
email = "public-key-[email protected]"
2121
must_change_password = false
2222
}
2323
24-
2524
resource "gitea_public_key" "test_user_key" {
26-
title = "test"
27-
key = file("${path.module}/id_ed25519.pub")
28-
username = gitea_user.test.username
25+
title = "public-key-test"
26+
key = file("${path.module}/id_ed25519.pub")
27+
username = gitea_user.test.username
2928
}
3029
```
3130

docs/resources/repository.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,52 @@ Repository migrations have some properties that are not available to regular rep
2121
## Example Usage
2222

2323
```terraform
24+
resource "gitea_user" "example" {
25+
username = "repo_example_user"
26+
login_name = "repo_example_user"
27+
password = "Geheim1!"
28+
29+
}
30+
2431
resource "gitea_repository" "test" {
25-
username = "lerentis"
26-
name = "test"
32+
username = gitea_user.example.username
33+
name = "repository-test"
2734
private = true
2835
issue_labels = "Default"
2936
license = "MIT"
3037
gitignores = "Go"
3138
}
3239
3340
resource "gitea_repository" "mirror" {
34-
username = "lerentis"
41+
username = gitea_user.example.username
3542
name = "terraform-provider-gitea-mirror"
3643
description = "Mirror of Terraform Provider"
3744
mirror = true
3845
migration_clone_addresse = "https://git.uploadfilter24.eu/lerentis/terraform-provider-gitea.git"
3946
migration_service = "gitea"
4047
migration_service_auth_token = var.gitea_mirror_token
48+
49+
depends_on = [gitea_user.example]
4150
}
4251
4352
resource "gitea_repository" "clone" {
44-
username = "lerentis"
53+
username = gitea_user.example.username
4554
name = "terraform-provider-gitea-clone"
4655
description = "Clone of Terraform Provider"
4756
mirror = false
4857
migration_clone_address = "https://git.uploadfilter24.eu/lerentis/terraform-provider-gitea.git"
4958
migration_service = "gitea"
5059
migration_service_auth_token = var.gitea_clone_token
60+
61+
depends_on = [gitea_user.example]
62+
}
63+
64+
variable "gitea_mirror_token" {
65+
default = "dummy-token"
66+
}
67+
68+
variable "gitea_clone_token" {
69+
default = "dummy-token"
5170
}
5271
```
5372

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitea_repository_actions_secret Resource - terraform-provider-gitea"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# gitea_repository_actions_secret (Resource)
10+
11+
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `repository` (String) Name of the repository.
21+
- `repository_owner` (String) Owner of the repository.
22+
- `secret_name` (String) Name of the secret.
23+
- `secret_value` (String, Sensitive) Value of the secret.
24+
25+
### Read-Only
26+
27+
- `created_at` (String) Date of 'actions_secret' creation.
28+
- `id` (String) The ID of this resource.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitea_repository_actions_variable Resource - terraform-provider-gitea"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# gitea_repository_actions_variable (Resource)
10+
11+
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `repository` (String) Name of the repository.
21+
- `repository_owner` (String) Owner of the repository.
22+
- `value` (String) Value of the variable.
23+
- `variable_name` (String) Name of the variable.
24+
25+
### Read-Only
26+
27+
- `id` (String) The ID of this resource.

docs/resources/repository_key.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,29 @@ Every key needs a unique name and unique key, i.e. no key can be added twice to
1616
## Example Usage
1717

1818
```terraform
19-
terraform {
20-
required_providers {
21-
tls = {
22-
source = "hashicorp/tls"
23-
version = "4.0.4"
24-
}
25-
}
19+
resource "tls_private_key" "example" {
20+
algorithm = "RSA"
21+
rsa_bits = 4096
2622
}
2723
28-
resource "tls_private_key" "example" {
29-
type = "RSA"
30-
rsa_bits = 4096
24+
resource "gitea_user" "example" {
25+
username = "repo_key_example_user"
26+
login_name = "repo_key_example_user"
27+
password = "Geheim1!"
28+
3129
}
3230
3331
resource "gitea_repository" "example" {
34-
name = "example"
35-
private = true
32+
name = "example"
33+
username = gitea_user.example.username
34+
private = true
3635
}
3736
3837
resource "gitea_repository_key" "example" {
3938
repository = gitea_repository.example.id
40-
title = "Example Deploy Key"
41-
read_only = true
42-
key = tls_private_key.example.public_key_openssh
39+
title = "Example Deploy Key"
40+
read_only = true
41+
key = tls_private_key.example.public_key_openssh
4342
}
4443
```
4544

0 commit comments

Comments
 (0)