From fcbfcdb44943bda887311fe53e8076bf3eba2faf Mon Sep 17 00:00:00 2001 From: Wojciech Zagrajczuk Date: Wed, 9 Oct 2024 10:14:13 +0000 Subject: [PATCH] DXE-4287 Disable fetching property versions as part of akamai_properties datasource and deprecate problematic fields Merge in DEVEXP/terraform-provider-akamai from bugfix/DXE-4287-rollback to release/v6.5.0 --- CHANGELOG.md | 6 +- .../property/data_akamai_properties.go | 64 +++++++++++++------ .../property/data_akamai_properties_test.go | 42 +----------- 3 files changed, 54 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 719f47713..5b0c09b9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,7 +57,6 @@ * PAPI * Added a new optional param to the import id of the `akamai_edge_hostname` resource. It allows to specify the product ID of the imported hostname and save it in the state. - * Modified the `akamai_properties` resource to properly populate the `product_id`, `rule_format` and `note` fields. #### BUG FIXES: @@ -67,6 +66,11 @@ difference between this header and the `Date` header. * Fixed an issue with the `akamai_property_activation` resource where updating it with an active or previously active property version for a configuration without a state file didn’t trigger a new property activation. +#### DEPRECATIONS: + +* PAPI + * Deprecated fields `product_id` and `rule_format` from `akamai_properties` datasource. Please use `akamai_property` to fetch this data. + ## 6.4.0 (Sep 04, 2024) #### FEATURES/ENHANCEMENTS: diff --git a/pkg/providers/property/data_akamai_properties.go b/pkg/providers/property/data_akamai_properties.go index e4b3d0402..3ebbc1082 100644 --- a/pkg/providers/property/data_akamai_properties.go +++ b/pkg/providers/property/data_akamai_properties.go @@ -33,16 +33,48 @@ func dataSourceProperties() *schema.Resource { Description: "List of properties", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "contract_id": {Type: schema.TypeString, Computed: true}, - "group_id": {Type: schema.TypeString, Computed: true}, - "latest_version": {Type: schema.TypeInt, Computed: true}, - "note": {Type: schema.TypeString, Computed: true}, - "product_id": {Type: schema.TypeString, Computed: true}, - "production_version": {Type: schema.TypeInt, Computed: true}, - "property_id": {Type: schema.TypeString, Computed: true}, - "property_name": {Type: schema.TypeString, Computed: true}, - "rule_format": {Type: schema.TypeString, Computed: true}, - "staging_version": {Type: schema.TypeInt, Computed: true}, + "contract_id": { + Type: schema.TypeString, + Computed: true, + }, + "group_id": { + Type: schema.TypeString, + Computed: true, + }, + "latest_version": { + Type: schema.TypeInt, + Computed: true, + }, + "note": { + Type: schema.TypeString, + Computed: true, + }, + "product_id": { + Type: schema.TypeString, + Computed: true, + Deprecated: "This field is deprecated. Please use `akamai_property` to get this data", + }, + "production_version": { + Type: schema.TypeInt, + Computed: true, + }, + "property_id": { + Type: schema.TypeString, + Computed: true, + }, + "property_name": { + Type: schema.TypeString, + Computed: true, + }, + "rule_format": { + Type: schema.TypeString, + Computed: true, + Deprecated: "This field is deprecated. Please use `akamai_property` to get this data", + }, + "staging_version": { + Type: schema.TypeInt, + Computed: true, + }, }, }, }, @@ -81,7 +113,7 @@ func dataPropertiesRead(ctx context.Context, d *schema.ResourceData, m interface // setting concatenated id to uniquely identify data d.SetId(groupID + contractID) - properties, err := sliceResponseProperties(ctx, meta, propertiesResponse) + properties, err := sliceResponseProperties(propertiesResponse) if err != nil { return diag.FromErr(err) } @@ -93,24 +125,20 @@ func dataPropertiesRead(ctx context.Context, d *schema.ResourceData, m interface return nil } -func sliceResponseProperties(ctx context.Context, meta meta.Meta, propertiesResponse *papi.GetPropertiesResponse) ([]map[string]interface{}, error) { +func sliceResponseProperties(propertiesResponse *papi.GetPropertiesResponse) ([]map[string]interface{}, error) { var properties []map[string]interface{} for _, item := range propertiesResponse.Properties.Items { - propVersion, err := getPropertyVersion(ctx, meta, item) - if err != nil { - return nil, err - } property := map[string]interface{}{ "contract_id": item.ContractID, "group_id": item.GroupID, "latest_version": item.LatestVersion, "note": item.Note, - "product_id": propVersion.Version.ProductID, + "product_id": nil, "production_version": decodeVersion(item.ProductionVersion), "property_id": item.PropertyID, "property_name": item.PropertyName, - "rule_format": propVersion.Version.RuleFormat, + "rule_format": nil, "staging_version": decodeVersion(item.StagingVersion), } properties = append(properties, property) diff --git a/pkg/providers/property/data_akamai_properties_test.go b/pkg/providers/property/data_akamai_properties_test.go index 469ea7da6..c83e4e102 100644 --- a/pkg/providers/property/data_akamai_properties_test.go +++ b/pkg/providers/property/data_akamai_properties_test.go @@ -14,25 +14,13 @@ func TestDataProperties(t *testing.T) { t.Run("list properties", func(t *testing.T) { client := &papi.Mock{} props := papi.PropertiesItems{Items: buildPapiProperties()} - properties := decodePropertyItems(props.Items, "rule_format", "prd_1") + properties := decodePropertyItems(props.Items, "", "") client.On("GetProperties", mock.Anything, papi.GetPropertiesRequest{GroupID: "grp_test", ContractID: "ctr_test"}, ).Return(&papi.GetPropertiesResponse{Properties: props}, nil) - res := &papi.GetPropertyVersionsResponse{ - Version: papi.PropertyVersionGetItem{ - ProductID: "prd_1", - RuleFormat: "rule_format", - }, - } - - client.On("GetPropertyVersion", - mock.Anything, - mock.Anything, - ).Return(res, nil) - useClient(client, nil, func() { resource.UnitTest(t, resource.TestCase{ ProtoV6ProviderFactories: testutils.NewProtoV6ProviderFactory(NewSubprovider()), @@ -49,25 +37,13 @@ func TestDataProperties(t *testing.T) { t.Run("list properties without group prefix", func(t *testing.T) { client := &papi.Mock{} props := papi.PropertiesItems{Items: buildPapiProperties()} - properties := decodePropertyItems(props.Items, "rule_format", "prd_1") + properties := decodePropertyItems(props.Items, "", "") client.On("GetProperties", mock.Anything, papi.GetPropertiesRequest{GroupID: "grp_test", ContractID: "ctr_test"}, ).Return(&papi.GetPropertiesResponse{Properties: props}, nil) - res := &papi.GetPropertyVersionsResponse{ - Version: papi.PropertyVersionGetItem{ - ProductID: "prd_1", - RuleFormat: "rule_format", - }, - } - - client.On("GetPropertyVersion", - mock.Anything, - mock.Anything, - ).Return(res, nil) - useClient(client, nil, func() { resource.UnitTest(t, resource.TestCase{ ProtoV6ProviderFactories: testutils.NewProtoV6ProviderFactory(NewSubprovider()), @@ -84,25 +60,13 @@ func TestDataProperties(t *testing.T) { t.Run("list properties without contract prefix", func(t *testing.T) { client := &papi.Mock{} props := papi.PropertiesItems{Items: buildPapiProperties()} - properties := decodePropertyItems(props.Items, "rule_format", "prd_1") + properties := decodePropertyItems(props.Items, "", "") client.On("GetProperties", mock.Anything, papi.GetPropertiesRequest{GroupID: "grp_test", ContractID: "ctr_test"}, ).Return(&papi.GetPropertiesResponse{Properties: props}, nil) - res := &papi.GetPropertyVersionsResponse{ - Version: papi.PropertyVersionGetItem{ - ProductID: "prd_1", - RuleFormat: "rule_format", - }, - } - - client.On("GetPropertyVersion", - mock.Anything, - mock.Anything, - ).Return(res, nil) - useClient(client, nil, func() { resource.UnitTest(t, resource.TestCase{ ProtoV6ProviderFactories: testutils.NewProtoV6ProviderFactory(NewSubprovider()),