Skip to content

Commit

Permalink
build: Add docs, goreleaser, and GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
SignalRichard authored May 8, 2023
2 parents a77ef7c + f107f0b commit 9e5ecf0
Show file tree
Hide file tree
Showing 29 changed files with 642 additions and 141 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# defaults
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{yaml,yml}]
indent_style = space
indent_size = 2

# Go
# https://golang.org/cmd/gofmt/
[{go.mod,*.go}]
indent_style = tab
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
#
# This uses an action (crazy-max/ghaction-import-gpg) that assumes you set your
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
# secret. If you would rather own your own GPG handling, please fork this action
# or use an alternative one for key handling.
#
# You will need to pass the `--batch` flag to `gpg` in your signing step
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#
name: release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
with:
go-version-file: 'go.mod'
cache: true
-
name: Import GPG key
uses: crazy-max/ghaction-import-gpg@111c56156bcc6918c056dbef52164cfa583dc549 # v5.2.0
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
with:
version: latest
args: release --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
# GitHub sets this automatically
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63 changes: 63 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
- go mod tidy
builds:
- env:
# goreleaser does not work with CGO, it could also complicate
# usage by users in CI/CD systems like Terraform Cloud where
# they are unable to install libraries.
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- freebsd
- windows
- linux
- darwin
goarch:
- amd64
- '386'
- arm
- arm64
ignore:
- goos: darwin
goarch: '386'
binary: '{{ .ProjectName }}_v{{ .Version }}'
archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
checksum:
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256
signs:
- artifacts: checksum
args:
# if you are using this in a GitHub action or some other automated pipeline, you
# need to pass the batch flag to indicate its not interactive.
- "--batch"
- "--local-user"
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"
release:
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
changelog:
skip: true
27 changes: 0 additions & 27 deletions Initialize-TerraformDocumentation.ps1

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Stack Overflow

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
37 changes: 0 additions & 37 deletions Makefile

This file was deleted.

66 changes: 31 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
# Terraform Provider Stack Overflow
# Terraform Provider for Stack Overflow

Run the following command to build the provider
The Terraform Provider for Stack Overflow is a Terraform plugin provider that allows you to manage questions, answers, and articles for your Stack Overflow for Teams.

```powershell
# Windows
go build -o terraform-provider-stackoverflow.exe
cp terraform-provider-stackoverflow.exe ~/go/bin
```
## Using the Provider
---------------------

Create a `terraform.rc` file in the %APPDATA% directory.
To use a released version of the Terraform provider in your environment, run `terraform init` and Terraform will automatically install the provider from the Terraform Registry. To specify a particular provider version when installing released providers, see the [Terraform documentation on provider versioning](https://www.terraform.io/docs/configuration/providers.html#version-provider-versions).

```powershell
cd $env:APPDATA
mk terraform.rc
```
## Example
----------

Add the following content to the `terraform.rc` file:
```terraform
provider "stackoverflow" {
team_name = "my-team-name"
access_token = "xxxx"
default_tags = ["terraform"]
}
```
provider_installation {
dev_overrides {
"registry.terraform.io/hashicorp/stackoverflow" = "C:/Users/rbolhofer/go/bin"
}
direct {}
resource "stackoverflow_filter" "filter" {
}
```
## Test sample configuration
resource "stackoverflow_article" "article" {
article_type = "announcement"
title = "Terraform Provider for Stack Overflow is available!"
body_markdown = "Look for the Stack Overflow provider in the Terraform registry"
tags = ["example"]
filter = stackoverflow_filter.filter.id
}
In a new directory, create a file named `main.tf` and add the following content:
resource "stackoverflow_question" "question" {
title = "Stack Overflow Terraform Provider"
body_markdown = "What is the Terraform Provider for Stack Overflow?"
tags = ["example"]
filter = stackoverflow_filter.filter.id
}
```
resource "stackoverflow_article" "test_article" {
article_type = "knowledge-article"
title = "Test Article"
body_markdown = "# Hello World"
tags = ["test"]
resource "stackoverflow_answer" "answer" {
question_id = stackoverflow_question.question.id
body_markdown = "It is a Terraform plugin provider to manage resources in Stack Overflow for Teams"
filter = stackoverflow_filter.filter.id
}
```

Then initialize and run Terraform:

```powershell
terraform init
terraform plan -out terraform.tfplan
```
34 changes: 34 additions & 0 deletions docs/data-sources/answer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackoverflow_answer Data Source - terraform-provider-stackoverflow"
subcategory: ""
description: |-
---

# stackoverflow_answer (Data Source)

The `answer` data source allows for referencing an existing answer in Stack Overflow.

## Example

```
data "stackoverflow_answer" "answer" {
answer_id = 1
filter = "XXXX"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `answer_id` (Number) The identifier for the answer
- `filter` (String) The API filter to use

### Read-Only

- `id` (String) The ID of this resource.


32 changes: 32 additions & 0 deletions docs/data-sources/article.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackoverflow_article Data Source - terraform-provider-stackoverflow"
subcategory: ""
description: |-
---

# stackoverflow_article (Data Source)

The `article` data source allows for referencing an existing article in Stack Overflow.

```
data "stackoverflow_article" "article" {
article_id = 1
filter = "XXXX"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `article_id` (Number) The identifier for the article
- `filter` (String) The API filter to use

### Read-Only

- `id` (String) The ID of this resource.


Loading

0 comments on commit 9e5ecf0

Please sign in to comment.