Skip to content

Commit a072e2a

Browse files
committed
initial release
1 parent e6560ef commit a072e2a

File tree

19 files changed

+1914
-1
lines changed

19 files changed

+1914
-1
lines changed

.github/workflows/release.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copied from https://github.com/hashicorp/terraform-provider-scaffolding/blob/main/.github/workflows/release.yml
2+
3+
# This GitHub action can publish assets for release when a tag is created.
4+
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
5+
#
6+
# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your
7+
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
8+
# secret. If you would rather own your own GPG handling, please fork this action
9+
# or use an alternative one for key handling.
10+
#
11+
# You will need to pass the `--batch` flag to `gpg` in your signing step
12+
# in `goreleaser` to indicate this is being used in a non-interactive mode.
13+
#
14+
name: release
15+
on:
16+
push:
17+
tags:
18+
- 'v*'
19+
jobs:
20+
goreleaser:
21+
runs-on: ubuntu-latest
22+
steps:
23+
-
24+
name: Checkout
25+
uses: actions/checkout@v2
26+
-
27+
name: Unshallow
28+
run: git fetch --prune --unshallow
29+
-
30+
name: Set up Go
31+
uses: actions/setup-go@v2
32+
with:
33+
go-version: 1.14
34+
-
35+
name: Import GPG key
36+
id: import_gpg
37+
# TODO: move this to HashiCorp namespace or find alternative that is just simple gpg commands
38+
# see https://github.com/hashicorp/terraform-provider-scaffolding/issues/22
39+
uses: paultyng/ghaction-import-gpg@v2.1.0
40+
env:
41+
# These secrets will need to be configured for the repository:
42+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
43+
PASSPHRASE: ${{ secrets.PASSPHRASE }}
44+
-
45+
name: Run GoReleaser
46+
uses: goreleaser/goreleaser-action@v2
47+
with:
48+
version: latest
49+
args: release --rm-dist
50+
env:
51+
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
52+
# GitHub sets this automatically
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
# Terraform files.
18+
.terraform
19+
*.tfstate
20+
*.tfstate.*

.goreleaser.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copied from https://github.com/hashicorp/terraform-provider-scaffolding/blob/main/.goreleaser.yml
2+
3+
# Visit https://goreleaser.com for documentation on how to customize this
4+
# behavior.
5+
before:
6+
hooks:
7+
# this is just an example and not a requirement for provider building/publishing
8+
- go mod tidy
9+
builds:
10+
- env:
11+
# goreleaser does not work with CGO, it could also complicate
12+
# usage by users in CI/CD systems like Terraform Cloud where
13+
# they are unable to install libraries.
14+
- CGO_ENABLED=0
15+
mod_timestamp: '{{ .CommitTimestamp }}'
16+
flags:
17+
- -trimpath
18+
ldflags:
19+
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
20+
goos:
21+
- freebsd
22+
- windows
23+
- linux
24+
- darwin
25+
goarch:
26+
- amd64
27+
- '386'
28+
- arm
29+
- arm64
30+
ignore:
31+
- goos: darwin
32+
goarch: '386'
33+
binary: '{{ .ProjectName }}_v{{ .Version }}'
34+
archives:
35+
- format: zip
36+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
37+
checksum:
38+
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
39+
algorithm: sha256
40+
signs:
41+
- artifacts: checksum
42+
args:
43+
# if you are using this in a GitHub action or some other automated pipeline, you
44+
# need to pass the batch flag to indicate its not interactive.
45+
- "--batch"
46+
- "--local-user"
47+
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
48+
- "--output"
49+
- "${signature}"
50+
- "--detach-sign"
51+
- "${artifact}"
52+
release:
53+
# If you want to manually examine the release before its live, uncomment this line:
54+
# draft: true
55+
changelog:
56+
skip: true

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## 0.1.0 (February 9, 2021)
2+
3+
* Initial Release. Support for AWS CBS instances only.
4+
* Create/Destroy, no updates yet.

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
Apache License
23
Version 2.0, January 2004
34
http://www.apache.org/licenses/
@@ -198,4 +199,4 @@
198199
distributed under the License is distributed on an "AS IS" BASIS,
199200
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200201
See the License for the specific language governing permissions and
201-
limitations under the License.
202+
limitations under the License.

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
default: install
2+
3+
build:
4+
go build
5+
6+
install:
7+
go install
8+
9+
testacc:
10+
TF_ACC=1 go test ./cbs -v -timeout 120m

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# CBS Terraform Provider
2+
Terraform Provider for Pure Storage Cloud Block Store deployments
3+
4+
## Prerequisites
5+
6+
### Tools
7+
- Install Terraform 0.13 (or higher) from: https://terraform.io
8+
- Install Golang from: https://golang.org/dl
9+
10+
### Install Go Modules
11+
12+
```shell
13+
go mod download
14+
```
15+
16+
### Build and Install Provider
17+
18+
```shell
19+
make
20+
```
21+
Note: The provider has only been tested on Linux and may not work on other platforms
22+
23+
### AWS Credentials
24+
25+
The provider is built using AWS SDK for Go, and will require the AWS credentials configured
26+
in the sytem. for more information about setting up the SDK, refer to this page:
27+
https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html
28+
29+
## Using the Provider
30+
31+
Example terraform configuration templates can be found in the examples/ subdirectory.
32+
33+
## Testing
34+
35+
To run acceptance tests, a JSON config file must be specified to supply the input parameters to
36+
the test CBS instances. An example config file can be found at `testing/example_aws_config`.
37+
The config file is passed to the test using the `TEST_ACC_AWS_PARAMS_PATH` environment variable.
38+
39+
Acceptance tests can be run with `make testacc`:
40+
```shell
41+
export TEST_ACC_AWS_PARAMS_PATH=<path to config file>
42+
make testacc
43+
```
44+
45+
By default, test resources are created in the `us-west-2` AWS region. The `AWS_TEST_REGION`
46+
can be used to specify an alternate region.
47+
48+
**Note**: Running acceptance tests requires a valid Cloud Block Store license and will create
49+
actual CBS instances. CBS and AWS billing costs will apply.

cbs/provider.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
3+
Copyright 2021, Pure Storage Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
*/
18+
19+
package cbs
20+
21+
import (
22+
"context"
23+
"fmt"
24+
"os"
25+
26+
"github.com/aws/aws-sdk-go/aws"
27+
"github.com/aws/aws-sdk-go/aws/session"
28+
"github.com/aws/aws-sdk-go/service/cloudformation"
29+
30+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
31+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
32+
)
33+
34+
const (
35+
awsRegionVar = "AWS_DEFAULT_REGION"
36+
)
37+
38+
func Provider() *schema.Provider {
39+
return &schema.Provider{
40+
Schema: map[string]*schema.Schema{
41+
"aws": &schema.Schema{
42+
Type: schema.TypeList,
43+
Optional: true,
44+
MaxItems: 1,
45+
Elem: &schema.Resource{
46+
Schema: map[string]*schema.Schema{
47+
"region": &schema.Schema{
48+
Type: schema.TypeString,
49+
Optional: true,
50+
DefaultFunc: schema.EnvDefaultFunc(awsRegionVar, nil),
51+
},
52+
},
53+
},
54+
},
55+
},
56+
ResourcesMap: map[string]*schema.Resource{
57+
"cbs_array_aws": resourceArrayAWS(),
58+
},
59+
ConfigureContextFunc: configureProvider,
60+
}
61+
}
62+
63+
func configureProvider(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
64+
region, diags := awsRegion(d)
65+
66+
if diags.HasError() {
67+
return nil, diags
68+
}
69+
70+
sess, err := session.NewSession(&aws.Config{
71+
Region: aws.String(region)},
72+
)
73+
if err != nil {
74+
return nil, diag.FromErr(err)
75+
}
76+
77+
cftSvc := cloudformation.New(sess)
78+
79+
return cftSvc, diags
80+
}
81+
82+
func awsRegion(d *schema.ResourceData) (string, diag.Diagnostics) {
83+
var diags diag.Diagnostics
84+
85+
if awsL, ok := d.Get("aws").([]interface{}); ok && len(awsL) > 0 && awsL[0] != nil {
86+
awsM := awsL[0].(map[string]interface{})
87+
if region, ok := awsM["region"]; ok {
88+
return region.(string), diags
89+
}
90+
}
91+
92+
if region := os.Getenv(awsRegionVar); region != "" {
93+
return region, diags
94+
}
95+
96+
diags = append(diags, diag.Diagnostic{
97+
Severity: diag.Error,
98+
Summary: fmt.Sprintf("No AWS region specified. The AWS region must be provided either in "+
99+
"the provider configuration block or with the %s environment variable.", awsRegionVar),
100+
})
101+
return "", diags
102+
}

0 commit comments

Comments
 (0)