Skip to content

Commit 9375a67

Browse files
tsimacekTomas Simacek
and
Tomas Simacek
authored
v0.8.0 release (#7)
Added support for Cloud Block Store on Azure deployment for Pure Fusion, cbs_fusion_sec_azure resource, cbs_azure_plans data source and updated purity version Co-authored-by: Tomas Simacek <tsimacek@pruestorage.com>
1 parent 56ff448 commit 9375a67

File tree

445 files changed

+5201
-1389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

445 files changed

+5201
-1389
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.dll
55
*.so
66
*.dylib
7+
terraform-provider-cbs
78

89
# Test binary, built with `go test -c`
910
*.test
@@ -22,4 +23,5 @@
2223

2324
/.build/
2425
/.build-logs/
26+
/.build-products/
2527
**/.vscode/

.goreleaser.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ builds:
1919
flags:
2020
- -trimpath
2121
ldflags:
22-
- '-s -w -X github.dev.purestorage.com/FlashArray/terraform-provider-cbs/version.ProviderVersion={{.Version}}'
22+
- "-s -w"
23+
- "-X github.com/PureStorage-OpenConnect/terraform-provider-cbs/version.ProviderVersion={{.Version}}"
24+
- "-X github.com/PureStorage-OpenConnect/terraform-provider-cbs/version.ProviderCommit={{.ShortCommit}}"
2325
goos:
2426
- freebsd
2527
- windows

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.8.0 (May 15, 2023)
2+
3+
* Added support for Cloud Block Store on Azure deployment for Pure Fusion using the `fusion_sec_identity` parameter, refer to the [documentation](docs/resources/array_azure.md)
4+
* Added cbs_azure_plans datasource, refer to the [documentation](docs/data-sources/azure_plans.md)
5+
* Added cbs_fusion_sec_azure resource, refer to the [documentation](docs/resources/fusion_sec_azure.md)
6+
* Update Purity version of cbs_array_azure to fetch the latest azure release using cbs_azure_plans
7+
* Update Purity version of cbs_array_aws to 6.4.0
8+
19
## 0.7.0 (Oct 19, 2022)
210

311
* Update Purity version of cbs_array_azure to 6.3.5

Makefile

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DEV_PKGDIR := $(HOME)/.terraform.d/plugins/terraform.purestorage.com/flasharray/cbs/
1+
DEV_PKGDIR := $(HOME)/.terraform.d/plugins/registry.terraform.io/PureStorage-OpenConnect/cbs
22
DEV_GOBIN := $(DEV_PKGDIR)/99.99/linux_amd64/
33
export SRC_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
44
SHELL=/bin/bash -eEuo pipefail # Set sane shell options
@@ -9,14 +9,19 @@ export GNUPGHOME := /tmp/gnupg
99
export PATH := $(TMPBIN):$(PATH)
1010
export PS_HTTP_TRACE_LOGGING := 1
1111

12-
-include */Makefile.mk
12+
PKG_LIST := $(shell go list ./... )
13+
# List of packages that are part of the generated SDK
14+
GENERATED_PKG_LIST := $(shell go list ./... | grep 2.4)
15+
FILTERED_PKG_LIST := $(filter-out $(GENERATED_PKG_LIST), $(PKG_LIST))
16+
LDFLAGS := -X 'github.com/PureStorage-OpenConnect/terraform-provider-cbs/version.ProviderCommit=$(shell git rev-parse --short HEAD)'
1317

14-
default: build
18+
include */Makefile.mk
19+
20+
.DEFAULT_GOAL := build
1521

1622
setup-basic:
1723
@mkdir -p .build-logs/
1824

19-
2025
setup-goreleaser:
2126
@curl -sfLO https://github.com/goreleaser/goreleaser/releases/download/v1.9.2/goreleaser_Linux_x86_64.tar.gz
2227
@mkdir -p $(TMPBIN)
@@ -37,16 +42,16 @@ test-goreleaser-check: setup-goreleaser setup-basic
3742
@CI="" goreleaser check >> .build-logs/goreleaser-check 2>&1
3843

3944
build:
40-
go build
45+
go build -ldflags="$(LDFLAGS)"
4146

4247
testacc:
43-
TF_ACC=1 go test ./cbs -v -timeout 120m
48+
TF_ACC=1 go test -ldflags="$(LDFLAGS)" ./cbs -v -timeout 120m
4449

4550
install-dev-mock:
46-
GOBIN=$(DEV_GOBIN) go install --tags mock
51+
GOBIN=$(DEV_GOBIN) go install -ldflags="$(LDFLAGS)" --tags mock
4752

4853
install-dev:
49-
GOBIN=$(DEV_GOBIN) go install
54+
GOBIN=$(DEV_GOBIN) go install -ldflags="$(LDFLAGS)"
5055

5156
install-dev-clean:
5257
@rm -rvf $(DEV_PKGDIR)
@@ -55,9 +60,29 @@ install-dev-clean:
5560
# The redirections and tee/grep stuff above is to help reduce console noise, we filter out all of the nominal messages, so its easier to see any errors
5661
# the full unfiltered log is in .build-logs/acc-mock
5762

58-
test-vet:
59-
@go vet ./cbs
60-
@go vet -tags mock ./cbs
63+
vet:
64+
@echo "Running go vet..."
65+
@go vet $(FILTERED_PKG_LIST)
66+
@go vet --tags mock $(FILTERED_PKG_LIST)
67+
68+
fmt:
69+
@echo "Fixing sources with gofmt..."
70+
@go fmt $(PKG_LIST)
71+
@git diff --exit-code || \
72+
(echo; echo "Unexpected difference in source files after running 'go fmt'. Review the changes and commit them."; exit 1)
73+
74+
depscheck:
75+
@echo "Checking source code with go mod tidy..."
76+
@go mod tidy
77+
@git diff --exit-code go.mod go.sum || \
78+
(echo; echo "Unexpected difference in go.mod/go.sum files. Run 'go mod tidy' command or revert any go.mod/go.sum changes and commit."; exit 1)
79+
80+
# For local development, CI does not run this
81+
golangci-lint:
82+
@golangci-lint run
83+
84+
pkglist:
85+
@echo "$(PKG_LIST)" | tr ' ' '\n'
6186

6287
tidy:
6388
@go get -u

auth/bootstrap_impl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func (b *bootstrapService) GenerateSecretPayload(ctx context.Context, host strin
2626
return generateSecretPayloadReal(ctx, host, pureuserPrivateKey)
2727
}
2828

29+
func (b *bootstrapService) OptOutDefaultProtectionPolicy(ctx context.Context, host string, pureuserPrivateKey []byte) error {
30+
return optOutDefaultProtectionPolicyReal(ctx, host, pureuserPrivateKey)
31+
}
32+
2933
type bootstrapService struct{}
3034

3135
func NewBootstrapService() Bootstrapper {

auth/bootstrap_interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import "context"
2222

2323
type Bootstrapper interface {
2424
GenerateSecretPayload(ctx context.Context, host string, pureuserPrivateKey []byte) ([]byte, error)
25+
OptOutDefaultProtectionPolicy(ctx context.Context, host string, pureuserPrivateKey []byte) error
2526
}
2627

2728
type SecretPayload struct {

auth/bootstrap_mock.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ func (b *mockBootstrapService) GenerateSecretPayload(ctx context.Context, host s
4747

4848
return credentials, nil
4949
}
50+
51+
func (b *mockBootstrapService) OptOutDefaultProtectionPolicy(ctx context.Context, host string, pureuserPrivateKey []byte) error {
52+
return nil
53+
}

auth/bootstrap_service.go

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"encoding/pem"
3030
"fmt"
3131
"io"
32+
"log"
3233
"math"
3334
"net"
3435
"strings"
@@ -39,6 +40,8 @@ import (
3940
"golang.org/x/crypto/ssh"
4041
)
4142

43+
const rootPgroupName = "pgroup-auto"
44+
4245
func sshSetup(ctx context.Context, host string, pureuserPrivateKey []byte) (*ssh.Client, error) {
4346
authMethod, err := pureuserPublicKeyAuth(pureuserPrivateKey)
4447
if err != nil {
@@ -97,6 +100,9 @@ func newClientConnWithRetries(
97100
retry.OnRetry(func(n uint, err error) {
98101
tflog.Trace(ctx, fmt.Sprintf("NewClientConn retry %d: %s", n, err))
99102
}),
103+
retry.RetryIf(func(err error) bool {
104+
return strings.Contains(err.Error(), "ssh: unable to authenticate")
105+
}),
100106
)
101107

102108
return
@@ -147,6 +153,40 @@ func generateSecretPayloadReal(ctx context.Context, host string, pureuserPrivate
147153
return credentials, nil
148154
}
149155

156+
func optOutDefaultProtectionPolicyReal(
157+
ctx context.Context,
158+
host string, pureuserPrivateKey []byte,
159+
) error {
160+
client, err := sshSetup(ctx, host, pureuserPrivateKey)
161+
if err != nil {
162+
return fmt.Errorf("SSH Client setup failed: %w", err)
163+
}
164+
165+
if out, err := executeSSHPureArrayRemovePgroupsFromDefaultProtections(ctx, client); err != nil {
166+
if strings.Contains(out, "invalid choice: 'default-protection'") {
167+
log.Println("OptOutDefaultProtectionPolicy: RemoveDefaultProtections: missing CLI subcommand")
168+
return nil
169+
}
170+
171+
return fmt.Errorf("OptOutDefaultProtectionPolicy: RemoveDefaultProtections: out=%s err=%w", out, err)
172+
}
173+
174+
if out, err := executeSSHPurePgroupDestroy(ctx, client, rootPgroupName); err != nil {
175+
if strings.Contains(out, "Protection group does not exist") {
176+
log.Printf("OptOutDefaultProtectionPolicy: PgroupDestroy: pgroup %q does not exist\n", rootPgroupName)
177+
return nil
178+
}
179+
180+
return fmt.Errorf("OptOutDefaultProtectionPolicy: PgroupDestroy: out=%s err=%w", out, err)
181+
}
182+
183+
if out, err := executeSSHPurePgroupEradicate(ctx, client, rootPgroupName); err != nil {
184+
return fmt.Errorf("OptOutDefaultProtectionPolicy: PgroupEradicate: out=%s err=%w", out, err)
185+
}
186+
187+
return nil
188+
}
189+
150190
func generateKeyPair() ([]byte, []byte, error) {
151191
// generate private keys
152192
privateRSAKey, err := rsa.GenerateKey(rand.Reader, 2048)
@@ -216,6 +256,7 @@ func processPasswordPrompt(ctx context.Context, password string) sshIOProcessor
216256
waitFor("Name")
217257
}
218258
}
259+
219260
func executeSSHPureAdminCreate(ctx context.Context, client *ssh.Client, username, password string) error {
220261
tflog.Trace(ctx, "ExecuteSSHPureAdminCreate running pureadmin create")
221262
return executeSSHCommandWithInputProcessing(ctx, client, "pureadmin create --role array_admin "+username, processPasswordPrompt(ctx, password))
@@ -259,6 +300,18 @@ func executeSSHPureAPIClientSetup(ctx context.Context, client *ssh.Client, apiCl
259300

260301
}
261302

303+
func executeSSHPureArrayRemovePgroupsFromDefaultProtections(ctx context.Context, client *ssh.Client) (string, error) {
304+
return executeSSHCommandAndReturnCombinedOutput(client, "purearray default-protection set \"\" --pgroup \"\"")
305+
}
306+
307+
func executeSSHPurePgroupDestroy(ctx context.Context, client *ssh.Client, pgroupName string) (string, error) {
308+
return executeSSHCommandAndReturnCombinedOutput(client, "purepgroup destroy "+pgroupName)
309+
}
310+
311+
func executeSSHPurePgroupEradicate(ctx context.Context, client *ssh.Client, pgroupName string) (string, error) {
312+
return executeSSHCommandAndReturnCombinedOutput(client, "purepgroup eradicate "+pgroupName)
313+
}
314+
262315
// Use this to ensure that something is closed (which usually does the actually
263316
// work for aborting) when a context is cancelled
264317
func closeOnCancel(ctx context.Context, closer io.Closer) {
@@ -274,7 +327,7 @@ func closeOnCancel(ctx context.Context, closer io.Closer) {
274327

275328
// This is a helper, it consumes outBufferred one rune at a time, waiting until we see a match or hit an error
276329
func waitForLineContainingText(ctx context.Context, expectedString string, errHad *error, processOutputTail *string, outBuffered *bufio.Reader) {
277-
ctx = tflog.With(ctx, "expectedString", expectedString)
330+
ctx = tflog.SetField(ctx, "expectedString", expectedString)
278331
tflog.Trace(ctx, "waiting for line containing text")
279332
for {
280333
newRune, _, err := outBuffered.ReadRune()
@@ -348,6 +401,18 @@ func executeSSHCommandAndReturnOutput(client *ssh.Client, cmd string) ([]string,
348401
return lines, nil
349402
}
350403

404+
func executeSSHCommandAndReturnCombinedOutput(client *ssh.Client, cmd string) (string, error) {
405+
session, err := client.NewSession()
406+
if err != nil {
407+
return "", fmt.Errorf("failed to start a new session: %+v", err)
408+
}
409+
defer session.Close()
410+
411+
out, err := session.CombinedOutput(cmd)
412+
413+
return string(out), err
414+
}
415+
351416
func executeSSHCommandWithInputProcessing(ctx context.Context, client *ssh.Client, cmd string, processor sshIOProcessor) error {
352417
session, err := client.NewSession()
353418
if err != nil {

auth/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.dev.purestorage.com/FlashArray/terraform-provider-cbs/auth"
7+
"github.com/PureStorage-OpenConnect/terraform-provider-cbs/auth"
88
"golang.org/x/crypto/ssh"
99
)
1010

cbs/acceptance/environment.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
3+
Copyright 2022, 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 acceptance
20+
21+
const (
22+
// Environment variable for controlling the Azure acceptance tests
23+
// related to deploying an app from the Azure Marketplace
24+
EnvTfAccAzureSkipMarketplace = "TC_ACC_SKIP_AZURE_MARKETPLACE"
25+
26+
// Environment variable controlling if the Azure acceptance tests
27+
// for user az cli login should be run. This testing is not available
28+
// when using Service Principal auth.
29+
EnvTfAccSkipUserPrincipalAuth = "TF_ACC_SKIP_USER_PRINCIPAL_AUTH"
30+
31+
// Environment variable for controlling the Azure acceptance tests
32+
// related to deploying an CBS Fusion app from an App Definition
33+
EnvTfAccAzureSkipFusionAppId = "TC_ACC_SKIP_AZURE_FUSION_APP_ID"
34+
35+
// Environment variable controlling if the Fusion Storage Endpoint
36+
// Collection Azure acceptance tests should be run.
37+
EnvTfAccSkipFusionSECAzure = "TF_ACC_SKIP_FUSION_SEC_AZURE"
38+
39+
// Enviromment variable with path to the Azure acceptance tests
40+
// parameters file in json format
41+
EnvTfAccAzureParamsPath = "TEST_ACC_AZURE_PARAMS_PATH"
42+
43+
// Enviromment variable with path to the Fusion Storage Endpoint
44+
// Collection Azure acceptance tests parameters file in json format
45+
EnvTfAccFusionSECAzureParamsPath = "TEST_ACC_FUSION_SEC_AZURE_PARAMS_PATH"
46+
47+
// Environment variable with path to the AWS acceptance tests
48+
// parameters file in json format
49+
EnvTfAccAwsParamsPath = "TEST_ACC_AWS_PARAMS_PATH"
50+
)

cbs/acceptance/test_params.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package acceptance
2+
3+
type AccTestCbsAwsParams struct {
4+
ArrayName string `json:"array_name"`
5+
ArrayModel string `json:"array_model"`
6+
DeploymentTemplateUrl string `json:"deployment_template_url"`
7+
DeploymentRoleArn string `json:"deployment_role_arn"`
8+
LicenseKey string `json:"license_key"`
9+
PureuserKeyPairName string `json:"pureuser_key_pair_name"`
10+
PureuserPrivateKeyPath string `json:"pureuser_private_key_path"`
11+
PureuserPrivateKey string `json:"pureuser_private_key"`
12+
Subnet string `json:"subnet"`
13+
SecurityGroup string `json:"security_group"`
14+
}
15+
16+
type AccTestCbsAzureParams struct {
17+
ArrayName string `json:"array_name"`
18+
ArrayModel string `json:"array_model"`
19+
AppDefinitionId string `json:"app_definition_id"`
20+
PlanName string `json:"plan_name"`
21+
PlanProduct string `json:"plan_product"`
22+
PlanPublisher string `json:"plan_publisher"`
23+
PlanVersion string `json:"plan_version"`
24+
ResourceGroupName string `json:"resource_group_name"`
25+
Location string `json:"location"`
26+
LicenseKey string `json:"license_key"`
27+
PureuserPrivateKeyPath string `json:"pureuser_private_key_path"`
28+
PureuserPrivateKey string `json:"pureuser_private_key"`
29+
KeyvaultId string `json:"keyvault_id"`
30+
ManagementSubnet string `json:"management_subnet"`
31+
ISCSISubnet string `json:"iscsi_subnet"`
32+
ReplicationSubnet string `json:"replication_subnet"`
33+
SystemSubnet string `json:"system_subnet"`
34+
VirtualNetworkId string `json:"virtual_network_id"`
35+
JitGroup string `json:"jit_group"`
36+
JitGroupID string `json:"jit_group_id"`
37+
FusionSECIdentity string `json:"fusion_sec_identity"`
38+
}
39+
40+
type AccTestCbsFusionSECAzureParams struct {
41+
FusionSECName string `json:"fusion_sec_name"`
42+
PlanName string `json:"plan_name"`
43+
PlanProduct string `json:"plan_product"`
44+
PlanPublisher string `json:"plan_publisher"`
45+
PlanVersion string `json:"plan_version"`
46+
ResourceGroupName string `json:"resource_group_name"`
47+
Location string `json:"location"`
48+
LoadBalancerNetworkRg string `json:"load_balancer_network_rg"`
49+
LoadBalancerNetworkName string `json:"load_balancer_network_name"`
50+
LoadBalancerSubnet string `json:"load_balancer_subnet"`
51+
JitGroupID string `json:"jit_group_id"`
52+
}

cbs/cbs_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"context"
2323
"fmt"
2424

25+
"github.com/PureStorage-OpenConnect/terraform-provider-cbs/cbs/internal/cloud"
2526
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
26-
"github.dev.purestorage.com/FlashArray/terraform-provider-cbs/cbs/internal/cloud"
2727
)
2828

2929
type CbsService struct {

0 commit comments

Comments
 (0)