Skip to content

Commit

Permalink
Initial provider code
Browse files Browse the repository at this point in the history
  • Loading branch information
mottetm-roche committed Aug 10, 2023
1 parent 461d398 commit 4a1cbc8
Show file tree
Hide file tree
Showing 39 changed files with 5,506 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Terraform Provider release workflow.
name: Release

# This GitHub action creates a release when a tag that matches the pattern
# "v*" (e.g. v0.1.0) is created.
on:
push:
tags:
- 'v*'

# Releases need permissions to read and write the repository contents.
# GitHub considers creating releases and uploading assets as writing contents.
permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
# Allow goreleaser to access older tag information.
fetch-depth: 0
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: 'go.mod'
cache: true
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@72b6676b71ab476b77e676928516f6982eef7a41 # v5.3.0
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
with:
args: release --clean
env:
# GitHub sets the GITHUB_TOKEN secret automatically.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
79 changes: 79 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Tests

on:
pull_request:
paths-ignore:
- 'README.md'
push:
paths-ignore:
- 'README.md'

permissions:
contents: read

jobs:
# Ensure project builds before running testing matrix
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: 'go.mod'
cache: true
- run: go mod download
- run: go build -v .
- name: Run linters
uses: golangci/golangci-lint-action@639cd343e1d3b897ff35927a75193d57cfcba299 # v3.6.0
with:
version: latest

generate:
name: Generate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: 'go.mod'
cache: true
- run: go get github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
- run: go install go.uber.org/mock/mockgen@latest
- run: go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
- run: go generate ./...
- name: git diff
run: |
git diff --compact-summary --exit-code || \
(echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1)
# Run tests in a matrix with Terraform CLI versions
test:
name: Terraform Provider Tests
needs: build
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# list whatever Terraform versions here you would like to support
terraform:
- '1.0.*'
- '1.1.*'
- '1.2.*'
- '1.3.*'
- '1.4.*'
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: 'go.mod'
cache: true
- uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
with:
terraform_version: ${{ matrix.terraform }}
terraform_wrapper: false
- run: go mod download
- run: go test -v -cover ./...
timeout-minutes: 10
31 changes: 31 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Visit https://golangci-lint.run/ for usage documentation
# and information on other useful linters
issues:
max-per-linter: 0
max-same-issues: 0

run:
skip-dirs:
- tools

linters:
disable-all: true
enable:
- durationcheck
- errcheck
- exportloopref
- forcetypeassert
- godot
- gofmt
- gosimple
- ineffassign
- makezero
- misspell
- nilerr
- predeclared
- staticcheck
- tenv
- unconvert
- unparam
- unused
- vet
60 changes: 60 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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
56 changes: 56 additions & 0 deletions docs/data-sources/incarnation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: "foxops_incarnation"
subcategory: ""
description: |-
Use this data source to get information about an incarnation.
---

Use this data source to get information about an incarnation.

## Example Usage
```terraform
data "foxops_incarnation" "example" {
id = "1234"
wait_for_mr_status = {
status = "merged"
timeout = "5m"
}
}
```

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

### Required

- `id` (String) The `id` of the incarnation.

### Optional

- `wait_for_mr_status` (Attributes) Wait for the status of the last merge request to reach a status before completing the current operation. This field only affects incarnation that have been updated as it requires a merge request to exist. (see [below for nested schema](#nestedatt--wait_for_mr_status))

### Read-Only

- `commit_sha` (String) The hash of the last commit created for the incarnation.
- `commit_url` (String) The url of the last commit created for the incarnation.
- `incarnation_repository` (String) The repository in which the incarnation will be created.
- `merge_request_id` (String) The id of the last merge request created for the incarnation. This property will be `null` after the creation of the incarnation and only populated after updates.
- `merge_request_status` (String) The status of the last merge request created for the incarnation. This property will be `null` after the creation of the incarnation and only populated after updates. It will be one of `open`, `merged`, `closed` or `unknown`.
- `merge_request_url` (String) The url of the latest merge request created for the incarnation. This property will be `null` after the creation of the incarnation and only populated after updates.
- `target_directory` (String) The folder in which the incarnation will be created. Default: `.`.
- `template_data` (Map of String) An object containing variables used to generate the incarnation. These variables should match those declared in the `fengine.yaml` file of the template
- `template_repository` (String) The repository containing the template used to create the incarnation.
- `template_repository_version` (String) A tag, commit or branch of the template repository to use for the incarnation.

<a id="nestedatt--wait_for_mr_status"></a>
### Nested Schema for `wait_for_mr_status`

Required:

- `status` (String) The expected status for the merge request. Can be one of `open`, `merge`, `closed` or `unknown`.

Optional:

- `timeout` (String) The amount of time to wait for the expected status to be reached. It should be a sequence of numbers followed by a unit suffix (`s`, `m` or `h`). Example: `1m30s`. Default: `10s`.

36 changes: 36 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "foxops Provider"
subcategory: ""
description: |-
The foxops provider allows you to configure and manage your Foxops incarnation using infrastructure as code.
---

# foxops Provider

The `foxops` provider allows you to configure and manage your Foxops incarnation using infrastructure as code.

## Example Usage

```terraform
terraform {
required_providers {
foxops = {
source = "Roche/foxops"
}
}
}
provider "foxops" {
endpoint = var.foxops_endpoint
token = var.foxops_token
}
```

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

### Optional

- `endpoint` (String) The base endpoint at which your Foxops instance can be reached.
- `token` (String) The token used to authenticate to your Foxops instance.
70 changes: 70 additions & 0 deletions docs/resources/incarnation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: "foxops_incarnation"
subcategory: ""
description: |-
Use this resource to create and manage incarnations.
---

Use this resource to create and manage incarnations.

## Example Usage
```terraform
resource "foxops_incarnation" "example" {
incarnation_repository = "my-org/my-repository"
target_directory = "./some-folder"
template_repository = "https://github.com/my-org/my-repository"
template_repository_version = "v1.2.3"
auto_merge_on_update = true
template_data = {
hello = "World!"
}
wait_for_mr_status_on_update = {
status = "merged"
timeout = "5m"
}
}
```

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

### Required

- `incarnation_repository` (String) The repository in which the incarnation will be created.
- `template_repository` (String) The repository containing the template used to create the incarnation.
- `template_repository_version` (String) A tag, commit or branch of the template repository to use for the incarnation.

### Optional

- `auto_merge_on_update` (Boolean) Whether merge request should automatically merged after update of the incarnation.
- `target_directory` (String) The folder in which the incarnation will be created. Default: `.`.
- `template_data` (Map of String) An object containing variables used to generate the incarnation. These variables should match those declared in the `fengine.yaml` file of the template
- `wait_for_mr_status_on_update` (Attributes) Wait for the status of the last merge request to reach a status before completing the current operation. This field only affects incarnation that have been updated as it requires a merge request to exist. (see [below for nested schema](#nestedatt--wait_for_mr_status_on_update))

### Read-Only

- `commit_sha` (String) The hash of the last commit created for the incarnation.
- `commit_url` (String) The url of the last commit created for the incarnation.
- `id` (String) The `id` of the incarnation.
- `merge_request_id` (String) The id of the last merge request created for the incarnation. This property will be `null` after the creation of the incarnation and only populated after updates.
- `merge_request_status` (String) The status of the last merge request created for the incarnation. This property will be `null` after the creation of the incarnation and only populated after updates. It will be one of `open`, `merged`, `closed` or `unknown`.
- `merge_request_url` (String) The url of the latest merge request created for the incarnation. This property will be `null` after the creation of the incarnation and only populated after updates.

<a id="nestedatt--wait_for_mr_status_on_update"></a>
### Nested Schema for `wait_for_mr_status_on_update`

Required:

- `status` (String) The expected status for the merge request. Can be one of `open`, `merge`, `closed` or `unknown`.

Optional:

- `timeout` (String) The amount of time to wait for the expected status to be reached. It should be a sequence of numbers followed by a unit suffix (`s`, `m` or `h`). Example: `1m30s`. Default: `10s`.

## Import
Import is supported using the following syntax:
```shell
terraform import foxops_incarnation.example "<edge_cluster_id>"
```
8 changes: 8 additions & 0 deletions examples/data-sources/foxops_incarnation/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data "foxops_incarnation" "example" {
id = "1234"

wait_for_mr_status = {
status = "merged"
timeout = "5m"
}
}
Loading

0 comments on commit 4a1cbc8

Please sign in to comment.