Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Commit

Permalink
feat: Initial plugin commit
Browse files Browse the repository at this point in the history
  • Loading branch information
saitho committed Aug 3, 2020
1 parent 56871a7 commit 15f62c2
Show file tree
Hide file tree
Showing 17 changed files with 4,312 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Test and build

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Test
working-directory: src
run: go clean -testcache && go test -v ./...

build:
needs: test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
working-directory: src
run: go build -o ../dist/terraform-provider-caddy .

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: terraform-provider-caddy
path: dist/terraform-provider-caddy

release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: terraform-provider-caddy
path: dist/terraform-provider-caddy
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 12
- name: PNPM install
run: npm i -g pnpm && pnpm i -P
- run: pnpm install
- name: Semantic Release Action
uses: saitho/semantic-release-action-pnpm@master
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
env:
GIT_AUTHOR_EMAIL: [email protected]
GIT_AUTHOR_NAME: stackhead-bot
GIT_COMMITTER_EMAIL: [email protected]
GIT_COMMITTER_NAME: stackhead-bot
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
dist

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

.idea
17 changes: 17 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/github",
{
"assets": [
{"path": "dist/terraform-provider-nginx", "label": "Provider binary"}
]
}
]
],
"branches": [
"master"
]
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Terraform Caddy provider

This provider can be used to manage Caddy configurations.

## [Documentation](docs/index.md)

## Development

### Build Go binary file

```yaml
go build -o dist/terraform-provider-caddy ./src
```
38 changes: 38 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Caddy Provider

This provider can be used to manage Caddy configurations.

## Installation

1. Download a binary from the [release section](https://github.com/getstackhead/terraform-caddy/releases).
2. Install it into the user plugins directory.
* Windows: `%APPDATA%\terraform.d\plugins`
* other OS: `~/.terraform.d/plugins`

## Example Usage

```hcl
resource "caddy_server_block" "my-server" {
filename = "test.conf"
content = <<EOF
my-server.com {
respond "Hello, world!"
}
sub.my-server.com {
respond "Hello, world!"
}
EOF
}
```

The file will be stored inside the configured folder.

## Argument Reference

In addition to [generic `provider` arguments](https://www.terraform.io/docs/configuration/providers.html) (e.g. `alias` and `version`), the following arguments are supported in the Nginx provider block:

* `config_folder` - (Optional) Folder where all configurations are stored. Default: `/etc/caddy/conf.d`

## Resources

### [server_block](./resources/server_block.md)
31 changes: 31 additions & 0 deletions docs/resources/server_block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Server Block Resource

This resource represents a [Caddyfile](https://caddyserver.com/docs/caddyfile) in Caddy configuration directories.

## Example Usage

```hcl
# This will create file //etc/caddy/conf.d/test.conf
resource "caddy_server_block" "my-server" {
filename = "test.conf"
markers = {
docker_port = docker_container.web.ports.external
docker_ports = "${docker_container.web.ports.external},${docker_container.web2.ports.external}"
}
markers_split = {
docker_ports = ","
}
content = <<EOF
# content of file here
# external docker port is: {# docker_port #}
# access web port in array: {# docker_ports[0] #}
# access web2 port in array: {# docker_ports[1] #}
EOF
}
```

## Argument Reference

* `filename` - (Required) Name of the configuration file
* `content` - (Required) Content of the configuration file
* `markers`- (Optional) Key-Value map. Keys specified as marker (e.g. `{# key #}`, `{~ key ~}`, `{* key *}`) will be replaced by the assigned value.
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module stackhead.io/terraform-caddy-provider

go 1.13

require (
github.com/hashicorp/terraform-plugin-sdk v1.12.0
github.com/stretchr/testify v1.3.0
)
Loading

0 comments on commit 15f62c2

Please sign in to comment.