Skip to content

Commit

Permalink
Refactor code so it helps in generating docs using tfplugindocs
Browse files Browse the repository at this point in the history
Add necessory changes required before releasing provider
  • Loading branch information
nikhilsbhat committed Jan 15, 2023
1 parent 04e6ba4 commit f2e5f6c
Show file tree
Hide file tree
Showing 26 changed files with 639 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ terraform.tfstate*
*.tfplan
.terraform
*.log

/dist
64 changes: 64 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
27 changes: 25 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ GOFMT_FILES?=$$(find . -not -path "./vendor/*" -type f -name '*.go')
APP_NAME?=terraform-provider-gocd
APP_DIR?=$$(git rev-parse --show-toplevel)
SRC_PACKAGES=$(shell go list -mod=vendor ./... | grep -v "vendor" | grep -v "mocks")
VERSION?=0.0.1
#VERSION?=0.0.1
VERSION := $(shell git tag --sort=-creatordate | head -1 | sed -n 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1.\2.\3/p')
NEXT_VERSION := $(shell echo ${VERSION}| awk -F '.' '{print $$1 "." $$2 "." $$3 +1 }' )

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -54,4 +56,25 @@ create.newversion.tfregistry: local.build ## Sets up the local terraform registr

upload.newversion.provider: create.newversion.tfregistry ## Uploads the updated provider to local terraform registry.
@rm -rf ~/terraform-providers/registry.terraform.io/hashicorp/gocd/$(VERSION)/darwin_arm64/terraform-provider-gocd_v$(VERSION)
@cp terraform-provider-gocd_v$(VERSION) ~/terraform-providers/registry.terraform.io/hashicorp/gocd/$(VERSION)/darwin_arm64/
@cp terraform-provider-gocd_v$(VERSION) ~/terraform-providers/registry.terraform.io/hashicorp/gocd/$(VERSION)/darwin_arm64/

generate.document:
@tfplugindocs generate examples/

tflint:
@terraform fmt -write=false -check=true -diff=true examples/

version:
@echo $(NEXT_VERSION)

build:
GORELEASER_CURRENT_TAG=$(VERSION) goreleaser build --rm-dist --snapshot

local.build: local.check ## Generates the artifact with the help of 'go build'
GORELEASER_CURRENT_TAG=$(VERSION) BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} goreleaser build --rm-dist

publish: local.check ## Builds and publishes the app
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --rm-dist

mock.publish: local.check ## Builds and mocks app release
GOVERSION=${GOVERSION} BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} PLUGIN_PATH=${APP_DIR} goreleaser release --skip-publish --rm-dist
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# GoCD Provider for Terraform


[![Go Report Card](https://goreportcard.com/badge/github.com/nikhilsbhat/terraform-provider-gocd)](https://goreportcard.com/report/github.com/nikhilsbhat/terraform-provider-gocd)
[![shields](https://img.shields.io/badge/license-MIT-blue)](https://github.com/nikhilsbhat/terraform-provider-gocd/blob/master/LICENSE)
[![shields](https://godoc.org/github.com/nikhilsbhat/terraform-provider-gocd?status.svg)](https://godoc.org/github.com/nikhilsbhat/terraform-provider-gocd)

Terraform provider for `GoCD` that helps in performing tasks on [GoCD](https://www.gocd.org/) server.

24 changes: 24 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gocd Provider"
subcategory: ""
description: |-
---

# gocd Provider





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

### Optional

- `base_url` (String) base url of GoCD server, which this terraform provider can interact with
- `ca_file` (String) CA file contents, to be used while connecting to GoCD server when CA based auth is enabled
- `loglevel` (String) loglevel to be set for the api calls made to GoCD
- `password` (String) password to be used while connecting with GoCD
- `username` (String) username to be used while connecting with GoCD
46 changes: 46 additions & 0 deletions docs/resources/auth_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gocd_auth_config Resource - terraform-provider-gocd"
subcategory: ""
description: |-
---

# gocd_auth_config (Resource)





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

### Required

- `plugin_id` (String) The plugin identifier of the authorization plugin.
- `profile_id` (String) The identifier of the authorization configuration.
- `properties` (Block Set, Min: 1) the list of configuration properties that represent the configuration of this profile. (see [below for nested schema](#nestedblock--properties))

### Optional

- `allow_only_known_users_to_login` (Boolean) Allow only those users to login who have explicitly been added by an administrator.

### Read-Only

- `etag` (String) Etag used to track the plugin settings
- `id` (String) The ID of this resource.

<a id="nestedblock--properties"></a>
### Nested Schema for `properties`

Required:

- `key` (String) the name of the property key.

Optional:

- `encrypted_value` (String) The encrypted value of the property
- `is_secure` (Boolean) Specify whether the given property is secure or not. If true and encrypted_value is not specified, GoCD will store the value in encrypted format.
- `value` (String) The value of the property


42 changes: 42 additions & 0 deletions docs/resources/cluster_profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gocd_cluster_profile Resource - terraform-provider-gocd"
subcategory: ""
description: |-
---

# gocd_cluster_profile (Resource)





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

### Required

- `plugin_id` (String) the plugin identifier of the cluster profile.
- `profile_id` (String) the identifier of the cluster profile.
- `properties` (Block Set, Min: 1) the list of configuration properties that represent the configuration of this profile. (see [below for nested schema](#nestedblock--properties))

### Read-Only

- `etag` (String) etag used to track the plugin settings
- `id` (String) The ID of this resource.

<a id="nestedblock--properties"></a>
### Nested Schema for `properties`

Required:

- `key` (String) the name of the property key.

Optional:

- `encrypted_value` (String) The encrypted value of the property
- `is_secure` (Boolean) Specify whether the given property is secure or not. If true and encrypted_value is not specified, GoCD will store the value in encrypted format.
- `value` (String) The value of the property


93 changes: 93 additions & 0 deletions docs/resources/config_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gocd_config_repository Resource - terraform-provider-gocd"
subcategory: ""
description: |-
---

# gocd_config_repository (Resource)





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

### Required

- `configuration` (Block Set, Min: 1) the list of configuration properties that represent the configuration of this profile. (see [below for nested schema](#nestedblock--configuration))
- `material` (Block Set, Min: 1) The material to be used by the config repo. (see [below for nested schema](#nestedblock--material))
- `plugin_id` (String) The plugin identifier of the cluster profile.
- `profile_id` (String) The identifier of the elastic agent profile.

### Optional

- `rules` (List of Map of String) The list of rules, which allows restricting the entities that the config repo can refer to.

### Read-Only

- `etag` (String) Etag used to track the plugin settings
- `id` (String) The ID of this resource.

<a id="nestedblock--configuration"></a>
### Nested Schema for `configuration`

Required:

- `key` (String) the name of the property key.

Optional:

- `encrypted_value` (String) The encrypted value of the property
- `is_secure` (Boolean) Specify whether the given property is secure or not. If true and encrypted_value is not specified, GoCD will store the value in encrypted format.
- `value` (String) The value of the property


<a id="nestedblock--material"></a>
### Nested Schema for `material`

Required:

- `attributes` (Block Set, Min: 1) The attributes for each material type. (see [below for nested schema](#nestedblock--material--attributes))
- `type` (String) The type of a material. Can be one of git, svn, hg, p4, tfs.

Optional:

- `fingerprint` (String) The fingerprint of the material.

<a id="nestedblock--material--attributes"></a>
### Nested Schema for `material.attributes`

Optional:

- `auto_update` (Boolean) Whether to poll for new changes or not.
- `branch` (String) The mercurial branch to build.
- `check_externals` (Boolean) Whether the changes o the externals will trigger the pipeline automatically or not.
- `destination` (String) The directory (relative to the pipeline directory) in which source code will be checked out.
- `domain` (String) The domain name for TFS authentication credentials.
- `encrypted_password` (String) The encrypted password for the specified user.
- `filter` (Block Set) The filter specifies files in changesets that should not trigger a pipeline automatically. (see [below for nested schema](#nestedblock--material--attributes--filter))
- `ignore_for_scheduling` (Boolean) Whether the pipeline should be triggered when there are changes in this material.
- `invert_filter` (Boolean) Invert filter to enable whitelist.
- `name` (String) The name of this material.
- `password` (String) The password for the specified user.
- `pipeline` (String) The name of a pipeline that this pipeline depends on.
- `port` (String) Perforce server connection to use ([transport:]host:port).
- `project_path` (String) The project path within the TFS collection.
- `ref` (String) The unique package repository id.
- `stage` (String) The name of a stage which will trigger this pipeline once it is successful.
- `url` (String) The URL of the subversion repository.
- `use_tickets` (Boolean) Whether to work with the Perforce tickets or not.
- `username` (String) The user account for the remote repository.
- `view` (String) The Perforce view.

<a id="nestedblock--material--attributes--filter"></a>
### Nested Schema for `material.attributes.filter`

Optional:

- `ignore` (List of String) Invert filter to enable whitelist.


42 changes: 42 additions & 0 deletions docs/resources/elastic_agent_profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gocd_elastic_agent_profile Resource - terraform-provider-gocd"
subcategory: ""
description: |-
---

# gocd_elastic_agent_profile (Resource)





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

### Required

- `cluster_profile_id` (String) the plugin identifier of the cluster profile.
- `profile_id` (String) the identifier of the elastic agent profile.
- `properties` (Block Set, Min: 1) the list of configuration properties that represent the configuration of this profile. (see [below for nested schema](#nestedblock--properties))

### Read-Only

- `etag` (String) etag used to track the plugin settings
- `id` (String) The ID of this resource.

<a id="nestedblock--properties"></a>
### Nested Schema for `properties`

Required:

- `key` (String) the name of the property key.

Optional:

- `encrypted_value` (String) The encrypted value of the property
- `is_secure` (Boolean) Specify whether the given property is secure or not. If true and encrypted_value is not specified, GoCD will store the value in encrypted format.
- `value` (String) The value of the property


Loading

0 comments on commit f2e5f6c

Please sign in to comment.