Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the README setup instructions and Make commands #405

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,48 @@ before:
# 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'
- goos: windows
goarch: arm64
binary: '{{ .ProjectName }}_v{{ .Version }}'
hooks:
post:
- cmd: "sh ./scripts/local-release.sh {{ .Version }} {{ .Path }} {{.Os}} {{.Arch}}"
- 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'
- goos: windows
goarch: arm64
binary: '{{ .ProjectName }}_v{{ .Version }}'
hooks:
post:
- cmd: "go install ."

archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'

checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256

signs:
- artifacts: checksum
args:
# if you are using this is a GitHub action or some other automated pipeline, you
# if you are using this is a GitHub action or some other automated pipeline, you
# need to pass the batch flag to indicate its not interactive.
- "--batch"
- "--local-user"
Expand All @@ -52,8 +55,9 @@ signs:
- "${signature}"
- "--detach-sign"
- "${artifact}"
release:
# Visit your project's GitHub Releases page to publish this release.

release: # Visit your project's GitHub Releases page to publish this release.
draft: true

changelog:
skip: true
13 changes: 11 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ PKG_NAME=opsgenie
default: build

build: fmtcheck
goreleaser build --skip-validate --rm-dist
goreleaser build --skip-validate --clean

dev: fmt
go install .

setup:
@sh -c "'$(CURDIR)/scripts/setup.sh'"

clean:
rm $(HOME)/.terraformrc

test: fmtcheck
go test -i $(TEST) || exit 1
Expand Down Expand Up @@ -56,5 +65,5 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test
.PHONY: build dev setup clean test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test

168 changes: 101 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,100 +1,134 @@

Terraform Provider
==================
# Terraform Provider

- Website: https://www.terraform.io
- [![Gitter chat](https://badges.gitter.im/hashicorp-terraform/Lobby.png)](https://gitter.im/hashicorp-terraform/Lobby)
- Mailing list: [Google Groups](http://groups.google.com/group/terraform-tool)

<img src="https://www.datocms-assets.com/2885/1629941242-logo-terraform-main.svg" width="600px">

Requirements
------------

- [Terraform](https://www.terraform.io/downloads.html) 0.12.x
- [Go](https://golang.org/doc/install) 1.14.2 (to build the provider plugin)
## Development

Building The Provider
---------------------
Everything needed to start local development and testing of the Provider plugin

Clone repository to: `$GOPATH/src/github.com/opsgenie/terraform-provider-opsgenie`
### 1. Requirements

```sh
$ mkdir -p $GOPATH/src/github.com/opsgenie; cd $GOPATH/src/github.com/opsgenie
$ git clone [email protected]:opsgenie/terraform-provider-opsgenie
```
- [Go](https://golang.org/doc/install) 1.18 (or higher, to build the provider plugin)
- [Terraform](https://www.terraform.io/downloads.html) 0.12.x (To test the plugin)

Enter the provider directory and build the provider

```sh
$ cd $GOPATH/src/github.com/opsgenie/terraform-provider-opsgenie
$ make build
```
### 2. Development Setup

Using the provider
----------------------
## Fill in for each provider
#### Cloning the project

Developing the Provider
---------------------------
```bash
export GOPATH="${GOPATH:=$HOME/go}"

If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.8+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
mkdir -p "$GOPATH/src/github.com/opsgenie"

To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
cd "$GOPATH/src/github.com/opsgenie"

```sh
$ make build
...
$ $GOPATH/bin/terraform-provider-opsgenie
...
git clone [email protected]:opsgenie/terraform-provider-opsgenie
```

In order to test the provider, you can simply run `make test`.

### 3. Compiling The Provider

```sh
$ make test
export GOPATH="${GOPATH:=$HOME/go}"
cd "$GOPATH/src/github.com/opsgenie"

# Compile all versions of the provider and install it in GOPATH.
make build

# Only compile the local executable version (Faster)
make dev
```

In order to run the full suite of Acceptance tests, run `make testacc`.

*Note:* Acceptance tests create real resources, and often cost money to run.
#### Running tests on the Provider

Run all local unit tests.

```sh
$ make testacc
make test
```

Testing the Provider from Local Registry Version
------------------------------------------------
* Create a `.terraformrc` file on your in your home folder using `vi ~/.terraformrc`
* Add the local provider registry conf in `.terraformrc`
```
provider_installation {
filesystem_mirror {
path = "~/terraform/providers"
include = ["test.local/*/*"]
}
direct {
exclude = ["test.local/*/*"]
}
}
```
* Run `make build` on local (it will internally trigger a hook to write to `test.local` registry located in your `~/terraform/providers` folder)
* You can create a terraform basic project of your own locally with `main.tf` file

### 4. Using the Compiled Provider

#### Configure Terraform to use the compiled provider.

This configuration makes use of the [`dev_overrides`](https://developer.hashicorp.com/terraform/cli/config/config-file#development-overrides-for-provider-developers).

See the [Manual Setup][Manual Setup] for more details.

```bash
# Creates $HOME/.terraformrc
make setup
```
terraform {
required_providers {
opsgenie = {
source = "test.local/opsgenie/opsgenie"
version = "<local_version>"

#### Manual setup

<details>
<summary>Click to expand</summary>

1. Create the `.terraformrc` file on your in your home folder using `touch ~/.terraformrc`
2. Configure [`dev_overrides`](https://developer.hashicorp.com/terraform/cli/config/config-file#development-overrides-for-provider-developers) in your `~/.terraformrc` as show below:
```hcl
provider_installation {
dev_overrides {
# Remember to replace <home dir> with your username
"opsgenie/opsgenie" = "/home/<home dir>/go/bin"
}
direct {}
}
}
}

# Configure the Opsgenie Provider
provider "opsgenie" {
api_key = <api_key>
api_url = "api.opsgenie.com" # can be a stage instance url for devs
}
```
3. Run `make build`

</details>


#### New OpsGenie Terraform project

1. Create a basic terraform project locally with a `main.tf` file:
```hcl
terraform {
required_providers {
opsgenie = {
source = "opsgenie/opsgenie"
version = ">=0.6.0" # version can be omitted
}
}
}

# Configure the Opsgenie Provider
provider "opsgenie" {
api_key = "<insert api_key>" # https://support.atlassian.com/opsgenie/docs/api-key-management/
api_url = "api.opsgenie.com" # can be a stage instance url for devs
}

resource "opsgenie_team" {
name = "Dev-Provider test team"
description = "New team made using in-development OpsGenie provider"
}
```

2. And, Add respective terraform change files which you want to apply on your OG instance

3. Run respective terraform commands to test the provider as per your convenience
Install the currently available provider with `tf init`
`terraform plan` and `terraform init` will use providers from the configured paths in `$HOME/.terraformrc`
`terraform` will output an error if no provider is found in the `dev_overrides` path. (`make build`)


#### Removing the 'dev_override' again

This allows you to use the normal release versions of the `opsgenie/opsgenie` provider.

*Note* Removes `$HOME/.terraformrc`

```bash
make clean
```
* And, Add respective terraform change files which you want to apply on your OG instance
* Run respective terraform commands to test the provider as per your convenience
9 changes: 0 additions & 9 deletions scripts/local-release.sh

This file was deleted.

18 changes: 18 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

if [ -z "$GOPATH" ]; then
GOPATH="${GOPATH:-$HOME/go}"
fi

if [ ! -d "$GOPATH" ]; then
mkdir -p "$GOPATH/bin"
fi

cat >~/.terraformrc <<EOF
provider_installation {
dev_overrides {
"opsgenie/opsgenie" = "$GOPATH/bin"
}
direct {}
}
EOF
Loading