Skip to content

Commit

Permalink
DXE-4287 Disable fetching property versions as part of akamai_propert…
Browse files Browse the repository at this point in the history
…ies datasource and deprecate problematic fields

Merge in DEVEXP/terraform-provider-akamai from bugfix/DXE-4287-rollback to release/v6.5.0
  • Loading branch information
wzagrajcz committed Oct 9, 2024
1 parent fa5bbcc commit fcbfcdb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 58 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand Down
64 changes: 46 additions & 18 deletions pkg/providers/property/data_akamai_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
42 changes: 3 additions & 39 deletions pkg/providers/property/data_akamai_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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()),
Expand All @@ -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()),
Expand Down

0 comments on commit fcbfcdb

Please sign in to comment.