diff --git a/datadog/fwprovider/data_source_datadog_application_key.go b/datadog/fwprovider/data_source_datadog_application_key.go index 514696f5b4..2254b17a66 100644 --- a/datadog/fwprovider/data_source_datadog_application_key.go +++ b/datadog/fwprovider/data_source_datadog_application_key.go @@ -37,7 +37,7 @@ func (d *applicationKeyDataSource) Metadata(_ context.Context, req datasource.Me // Schema implements datasource.DataSource. func (d *applicationKeyDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ - Description: "Use this data source to retrieve information about an existing application key.", + Description: "Use this data source to retrieve information about an existing application key. Deprecated. This will be removed in a future release with prior notice. Securely store your application keys using a secret management system or use the datadog_application_key resource to manage application keys in your Datadog account.", Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "Id for Application Key.", @@ -57,6 +57,7 @@ func (d *applicationKeyDataSource) Schema(_ context.Context, req datasource.Sche Sensitive: true, }, }, + DeprecationMessage: "The datadog_application_key data source is deprecated and will be removed in a future release with prior notice. Securely store your application key using a secret management system or use the datadog_application_key resource to manage application keys in your Datadog account.", } } @@ -79,8 +80,10 @@ func (d *applicationKeyDataSource) Read(ctx context.Context, req datasource.Read resp.Diagnostics.Append(utils.FrameworkErrorDiag(err, "error getting application key")) return } - apiKeyData := ddResp.GetData() - d.updateState(&state, &apiKeyData) + appKeyData := ddResp.GetData() + if !d.checkAPIDeprecated(&appKeyData, resp) { + d.updateState(&state, &appKeyData) + } } else if !state.Name.IsNull() { optionalParams := datadogV2.NewListCurrentUserApplicationKeysOptionalParameters() optionalParams.WithFilter(state.Name.ValueString()) @@ -122,7 +125,9 @@ func (d *applicationKeyDataSource) Read(ctx context.Context, req datasource.Read resp.Diagnostics.AddError("your query returned no exact matches, please try a less specific search criteria", "") return } - d.updateState(&state, &applicationKeyData) + if !d.checkAPIDeprecated(&applicationKeyData, resp) { + d.updateState(&state, &applicationKeyData) + } } else { id := applicationKeysData[0].GetId() applicationKeyResponse, _, err := d.Api.GetCurrentUserApplicationKey(d.Auth, id) @@ -131,7 +136,9 @@ func (d *applicationKeyDataSource) Read(ctx context.Context, req datasource.Read return } applicationKeyFullData := applicationKeyResponse.GetData() - d.updateState(&state, &applicationKeyFullData) + if !d.checkAPIDeprecated(&applicationKeyFullData, resp) { + d.updateState(&state, &applicationKeyFullData) + } } } else { resp.Diagnostics.AddError("missing id or name parameter", "") @@ -148,3 +155,12 @@ func (r *applicationKeyDataSource) updateState(state *applicationKeyDataSourceMo state.Name = types.StringValue(applicationKeyAttributes.GetName()) state.Key = types.StringValue(applicationKeyAttributes.GetKey()) } + +func (r *applicationKeyDataSource) checkAPIDeprecated(applicationKeyData *datadogV2.FullApplicationKey, resp *datasource.ReadResponse) bool { + applicationKeyAttributes := applicationKeyData.GetAttributes() + if !applicationKeyAttributes.HasKey() { + resp.Diagnostics.AddError("Deprecated", "The datadog_application_key data source is deprecated and will be removed in a future release. Securely store your application key using a secret management system or use the datadog_application_key resource to manage application keys in your Datadog account.") + return true + } + return false +} diff --git a/datadog/tests/data_source_datadog_application_key_test.go b/datadog/tests/data_source_datadog_application_key_test.go index ec763a397c..54f995db1f 100644 --- a/datadog/tests/data_source_datadog_application_key_test.go +++ b/datadog/tests/data_source_datadog_application_key_test.go @@ -17,7 +17,6 @@ func TestAccDatadogApplicationKeyDatasource_matchId(t *testing.T) { ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t) applicationKeyName := uniqueEntityName(ctx, t) - nonEmptyStringRegex := `[\S\s]+[\S]+` resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV5ProviderFactories: accProviders, @@ -30,7 +29,6 @@ func TestAccDatadogApplicationKeyDatasource_matchId(t *testing.T) { resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", fmt.Sprintf("%s 1", applicationKeyName)), resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)), resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", fmt.Sprintf("%s 1", applicationKeyName)), - resource.TestMatchResourceAttr("data.datadog_application_key.app_key", "key", regexp.MustCompile(nonEmptyStringRegex)), resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"), ), }, @@ -46,7 +44,6 @@ func TestAccDatadogApplicationKeyDatasource_matchName(t *testing.T) { ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t) applicationKeyName := uniqueEntityName(ctx, t) - nonEmptyStringRegex := `[\S\s]+[\S]+` resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV5ProviderFactories: accProviders, @@ -59,7 +56,6 @@ func TestAccDatadogApplicationKeyDatasource_matchName(t *testing.T) { resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", fmt.Sprintf("%s 1", applicationKeyName)), resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)), resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", fmt.Sprintf("%s 1", applicationKeyName)), - resource.TestMatchResourceAttr("data.datadog_application_key.app_key", "key", regexp.MustCompile(nonEmptyStringRegex)), resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"), ), }, @@ -70,7 +66,6 @@ func TestAccDatadogApplicationKeyDatasource_matchName(t *testing.T) { resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", applicationKeyName), resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)), resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", applicationKeyName), - resource.TestMatchResourceAttr("data.datadog_application_key.app_key", "key", regexp.MustCompile(nonEmptyStringRegex)), resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"), ), }, @@ -86,7 +81,6 @@ func TestAccDatadogApplicationKeyDatasource_exactMatchName(t *testing.T) { ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t) applicationKeyName := uniqueEntityName(ctx, t) - nonEmptyStringRegex := `[\S\s]+[\S]+` resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV5ProviderFactories: accProviders, @@ -99,7 +93,6 @@ func TestAccDatadogApplicationKeyDatasource_exactMatchName(t *testing.T) { resource.TestCheckResourceAttr("datadog_application_key.app_key_1", "name", applicationKeyName), resource.TestCheckResourceAttr("datadog_application_key.app_key_2", "name", fmt.Sprintf("%s 2", applicationKeyName)), resource.TestCheckResourceAttr("data.datadog_application_key.app_key", "name", applicationKeyName), - resource.TestMatchResourceAttr("data.datadog_application_key.app_key", "key", regexp.MustCompile(nonEmptyStringRegex)), resource.TestCheckResourceAttrSet("data.datadog_application_key.app_key", "id"), ), }, diff --git a/docs/data-sources/application_key.md b/docs/data-sources/application_key.md index ab29c77b3f..35a2a76d6e 100644 --- a/docs/data-sources/application_key.md +++ b/docs/data-sources/application_key.md @@ -3,12 +3,12 @@ page_title: "datadog_application_key Data Source - terraform-provider-datadog" subcategory: "" description: |- - Use this data source to retrieve information about an existing application key. + Use this data source to retrieve information about an existing application key. Deprecated. This will be removed in a future release with prior notice. Securely store your application keys using a secret management system or use the datadogapplicationkey resource to manage application keys in your Datadog account. --- # datadog_application_key (Data Source) -Use this data source to retrieve information about an existing application key. +Use this data source to retrieve information about an existing application key. Deprecated. This will be removed in a future release with prior notice. Securely store your application keys using a secret management system or use the datadog_application_key resource to manage application keys in your Datadog account. ## Example Usage