Skip to content

Commit b56e7da

Browse files
committed
v0.10.0 release
Added support for tagging by resource type, refer to the documentation Added support for specifying version plan tag when deploying array (e.g. `6.6.4` or `6.6.x`)
1 parent 06d54a3 commit b56e7da

37 files changed

+855
-1457
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
uses: goreleaser/goreleaser-action@v2
4747
with:
4848
version: latest
49-
args: release --rm-dist
49+
args: release --clean
5050
env:
5151
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
5252
# GitHub sets this automatically

.goreleaser.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Visit https://goreleaser.com for documentation on how to customize this
44
# behavior.
55

6+
version: 2
7+
68
dist: .build/goreleaser-dist
79

810
before:
@@ -58,4 +60,4 @@ release:
5860
# If you want to manually examine the release before its live, uncomment this line:
5961
# draft: true
6062
changelog:
61-
skip: true
63+
disable: true

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.10.0 (July 9, 2024)
2+
3+
* Added support for tagging by resource type, refer to the [documentation](docs/resources/array_azure.md#nested-schema-for-resource_tags)
4+
* Added support for specifying version plan tag when deploying array (e.g. `6.6.4` or `6.6.x`)
5+
16
## 0.9.0 (July 3, 2023)
27

38
* Added support for PremiumV2 SSD with V20MP2R2 SKU, refer to the [documentation](docs/resources/array_azure.md)
@@ -46,4 +51,4 @@
4651
## 0.1.0 (February 9, 2021)
4752

4853
* Initial Release. Support for AWS CBS instances only.
49-
* Create/Destroy, no updates yet.
54+
* Create/Destroy, no updates yet.

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,4 @@ tidy:
9191
@go fix ./cbs
9292
@go clean ./cbs
9393
@go clean --tags mock ./cbs
94+

cbs/acceptance/environment.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ const (
4040
// parameters file in json format
4141
EnvTfAccAzureParamsPath = "TEST_ACC_AZURE_PARAMS_PATH"
4242

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-
4743
// Environment variable with path to the AWS acceptance tests
4844
// parameters file in json format
4945
EnvTfAccAwsParamsPath = "TEST_ACC_AWS_PARAMS_PATH"

cbs/acceptance/test_params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type AccTestCbsAzureParams struct {
3434
VirtualNetworkId string `json:"virtual_network_id"`
3535
JitGroup string `json:"jit_group"`
3636
JitGroupID string `json:"jit_group_id"`
37-
FusionSECIdentity string `json:"fusion_sec_identity"`
3837
UserAssignedIdentity string `json:"user_assigned_identity"`
38+
ResourceTags string `json:"resource_tags"`
3939
}
4040

4141
type AccTestCbsFusionSECAzureParams struct {

cbs/common.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ func validateAzureManagedApplicationName(v interface{}, k string) (warnings []st
139139
return warnings, errors
140140
}
141141

142+
func validateVersionPrefixTag(v interface{}, k string) (warnings []string, errors []error) {
143+
value := v.(string)
144+
145+
pattern := `^\d+\.\d+(?:\.\d+|\.x)?$`
146+
regexpPattern := regexp.MustCompile(pattern)
147+
148+
if !regexpPattern.MatchString(value) {
149+
errors = append(errors, fmt.Errorf("version prefix tag format not correct"))
150+
}
151+
152+
return warnings, errors
153+
}
154+
142155
func validateAzureResourceGroupName(v interface{}, k string) (warnings []string, errors []error) {
143156
value := v.(string)
144157

cbs/data_azure_plans.go

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"strings"
3030
"time"
3131

32-
"github.com/PureStorage-OpenConnect/terraform-provider-cbs/cbs/internal/appcatalog"
3332
"github.com/hashicorp/go-version"
3433
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
3534
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -67,6 +66,39 @@ func dataSourceAzurePlans() *schema.Resource {
6766
}
6867
}
6968

69+
func dataSourceCbsPlanAzure() *schema.Resource {
70+
return &schema.Resource{
71+
ReadContext: dataSourceCbsPlanAzureRead,
72+
Schema: map[string]*schema.Schema{
73+
"plan_version": {
74+
Type: schema.TypeString,
75+
Required: true,
76+
ValidateFunc: validateVersionPrefixTag,
77+
},
78+
"name": {
79+
Type: schema.TypeString,
80+
Computed: true,
81+
Elem: schema.TypeString,
82+
},
83+
"version": {
84+
Type: schema.TypeString,
85+
Computed: true,
86+
Elem: schema.TypeString,
87+
},
88+
"publisher": {
89+
Type: schema.TypeString,
90+
Computed: true,
91+
Elem: schema.TypeString,
92+
},
93+
"product": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
Elem: schema.TypeString,
97+
},
98+
},
99+
}
100+
}
101+
70102
type Plan struct {
71103
Name string
72104
Product string
@@ -96,7 +128,7 @@ func (a PlanByVersion) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
96128
var plan_name_regexp = regexp.MustCompile(`^[\w]+_([\d]+)_([\d]+)_([\d]+)$`)
97129

98130
// Retrieve a plan information from Azure DefaultTemplate artifact
99-
func getPlanFromTemplateJson(data []byte) (*Plan, error) {
131+
func GetPlanFromTemplateJson(data []byte) (*Plan, error) {
100132
// Parse the default template
101133
var unmarshalled_data JSONDefaultTemplate
102134
err := json.Unmarshal(data, &unmarshalled_data)
@@ -131,16 +163,14 @@ func versionPlans(plans []Plan) ([]VersionedPlan, error) {
131163
return versioned_plans, nil
132164
}
133165

134-
func queryMarketplaceForPlans(ctx context.Context) ([]VersionedPlan, error) {
135-
136-
search_client := appcatalog.NewSearchClient()
137-
response, err := search_client.Get(ctx, "en", "US", "terraform-cbs-provider", []appcatalog.SearchV2FieldName{"All"}, []string{"purestoragemarketplaceadmin"})
166+
func QueryMarketplaceForPlans(ctx context.Context) ([]VersionedPlan, error) {
167+
productSummary, err := GetProductSummary(ctx)
138168
if err != nil {
139169
return nil, err
140170
}
141171

142172
var template_plans []Plan
143-
for _, response_result := range response.Results {
173+
for _, response_result := range productSummary.Results {
144174
for _, response_plan := range response_result.Plans {
145175
if !strings.HasPrefix(*response_plan.PlanID, "cbs_azure") {
146176
// Exclude any plans which aren't the Pure Cloud Block Store on Azure offering.
@@ -158,7 +188,7 @@ func queryMarketplaceForPlans(ctx context.Context) ([]VersionedPlan, error) {
158188
continue
159189
}
160190

161-
template_plan, err := getPlanFromTemplateJson(template_data)
191+
template_plan, err := GetPlanFromTemplateJson(template_data)
162192
if err != nil {
163193
continue
164194
}
@@ -174,7 +204,7 @@ func queryMarketplaceForPlans(ctx context.Context) ([]VersionedPlan, error) {
174204
func dataSourceAzurePlansRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
175205
var diags diag.Diagnostics
176206

177-
versioned_plans, err := queryMarketplaceForPlans(ctx)
207+
versioned_plans, err := QueryMarketplaceForPlans(ctx)
178208
if err != nil {
179209
return diag.FromErr(err)
180210
}
@@ -201,3 +231,50 @@ func dataSourceAzurePlansRead(ctx context.Context, d *schema.ResourceData, m int
201231

202232
return diags
203233
}
234+
235+
func dataSourceCbsPlanAzureRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
236+
var diags diag.Diagnostics
237+
238+
versioned_plans, err := QueryMarketplaceForPlans(ctx)
239+
if err != nil {
240+
return diag.FromErr(err)
241+
}
242+
243+
version_prefix_tag := d.Get("plan_version").(string)
244+
if version_prefix_tag[len(version_prefix_tag)-1] == 'x' {
245+
version_prefix_tag = version_prefix_tag[0 : len(version_prefix_tag)-1]
246+
}
247+
248+
set := false
249+
for _, versioned_plan := range versioned_plans {
250+
match := plan_name_regexp.FindStringSubmatch(versioned_plan.Plan.Name)
251+
version_tag := fmt.Sprintf("%s.%s.%s", match[1], match[2], match[3])
252+
if strings.HasPrefix(version_tag, version_prefix_tag) {
253+
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
254+
err = d.Set("name", versioned_plan.Plan.Name)
255+
if err != nil {
256+
return diag.FromErr(err)
257+
}
258+
err = d.Set("product", versioned_plan.Plan.Product)
259+
if err != nil {
260+
return diag.FromErr(err)
261+
}
262+
err = d.Set("publisher", versioned_plan.Plan.Publisher)
263+
if err != nil {
264+
return diag.FromErr(err)
265+
}
266+
err = d.Set("version", versioned_plan.Plan.Version)
267+
if err != nil {
268+
return diag.FromErr(err)
269+
}
270+
set = true
271+
break
272+
}
273+
}
274+
275+
if !set {
276+
return diag.FromErr(errors.New("Specific plan for provided version tag not found"))
277+
}
278+
279+
return diags
280+
}

cbs/data_azure_plans_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package cbs
2121
import (
2222
"fmt"
2323
"os"
24+
"regexp"
2425
"strconv"
2526
"testing"
2627

@@ -49,10 +50,35 @@ func TestAccDataAzurePlans(t *testing.T) {
4950
})
5051
}
5152

53+
func TestAccDataCbsPlanAzure(t *testing.T) {
54+
55+
if os.Getenv(acceptance.EnvTfAccAzureSkipMarketplace) != "" {
56+
t.Skipf("Skipping acc test due to env variable '%s'", acceptance.EnvTfAccAzureSkipMarketplace)
57+
}
58+
59+
resource.ParallelTest(t, resource.TestCase{
60+
ProviderFactories: testAccProvidersFactory,
61+
Steps: []resource.TestStep{
62+
{
63+
Config: testAccAzureDataCbsPlanAzure(),
64+
Check: resource.ComposeTestCheckFunc(
65+
testAccDataCbsPlanAzure(),
66+
),
67+
},
68+
},
69+
})
70+
}
71+
5272
func testAccAzureDataPlansConfig() string {
5373
return `data "cbs_azure_plans" "azure_plans" {}`
5474
}
5575

76+
func testAccAzureDataCbsPlanAzure() string {
77+
return `data "cbs_plan_azure" "version_plan" {
78+
plan_version = "6.6.x"
79+
}`
80+
}
81+
5682
func testAccDataAzurePlans() resource.TestCheckFunc {
5783
return func(s *terraform.State) error {
5884
data_resource := s.RootModule().Resources["data.cbs_azure_plans.azure_plans"]
@@ -62,9 +88,11 @@ func testAccDataAzurePlans() resource.TestCheckFunc {
6288
if err != nil {
6389
return err
6490
}
91+
6592
if plans_size < 2 {
6693
return fmt.Errorf("Unexpected plans size: %d", plans_size)
6794
}
95+
6896
for i := 0; i < plans_size; i++ {
6997
// Check product version derivation from plan name makes sense.
7098
plan_name := data_resource.Primary.Attributes["plans."+strconv.Itoa(i)+".name"]
@@ -101,3 +129,34 @@ func testAccDataAzurePlans() resource.TestCheckFunc {
101129
return nil
102130
}
103131
}
132+
133+
func testAccDataCbsPlanAzure() resource.TestCheckFunc {
134+
return func(s *terraform.State) error {
135+
pattern := `^\d+\.\d+\.\d+$`
136+
re := regexp.MustCompile(pattern)
137+
data_resource := s.RootModule().Resources["data.cbs_plan_azure.version_plan"]
138+
139+
plan_name := data_resource.Primary.Attributes["name"]
140+
match := plan_name_regexp.FindStringSubmatch(plan_name)
141+
version_tag := fmt.Sprintf("%s.%s.%s", match[1], match[2], match[3])
142+
if len(match) != 4 || !re.MatchString(version_tag) {
143+
return fmt.Errorf("Incorrect plan name: %s", plan_name)
144+
}
145+
146+
plan_product := data_resource.Primary.Attributes["product"]
147+
if plan_product != "pure_storage_cloud_block_store_deployment" {
148+
return fmt.Errorf("Incorrect plan product : %s", plan_product)
149+
}
150+
151+
plan_publisher := data_resource.Primary.Attributes["publisher"]
152+
if plan_publisher != "purestoragemarketplaceadmin" {
153+
return fmt.Errorf("Incorrect plan publisher : %s", plan_publisher)
154+
}
155+
156+
plan_version := data_resource.Primary.Attributes["version"]
157+
if !re.MatchString(plan_version) {
158+
return fmt.Errorf("Incorrect plan version : %s", plan_version)
159+
}
160+
return nil
161+
}
162+
}

0 commit comments

Comments
 (0)