Skip to content

Commit

Permalink
data-source/aws_lambda_invocation: Deprecate result_map attribute
Browse files Browse the repository at this point in the history
Reference: #9184
Reference: #9190
Reference: #9189
Reference: #13439
Reference: hashicorp/terraform-plugin-sdk#344
Reference: hashicorp/terraform-plugin-sdk#451

The `result_map` attribute was created as a workaround for Terraform 0.11 and earlier not having native JSON decoding abilities. This attribute came with the caveat that it only worked when the JSON was only a flat map of strings, where we otherwise ignore the `(helper/schema.ResourceData).Set()` error and instead return a warning log. In Terraform Plugin SDK v2, this error will now panic in the acceptance testing as these errors are generally indicative of resource bugs, which is unavoidable in this case.

Practitioners should instead opt for the Terraform 0.12 and later `jsondecode()` function against the `result` attribute, which can handle much more arbitrary JSON structures. This has been documented in the `aws_lambda_invocation` data source for awhile now. For JSON structures not compliant with Terraform's JSON decoding, the `result` attribute's string value can still be passed to other processing logic, such as calling the `jq` tool.
  • Loading branch information
bflad committed May 26, 2020
1 parent f991d94 commit 7a144ea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 3 additions & 2 deletions aws/data_source_aws_lambda_invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func dataSourceAwsLambdaInvocation() *schema.Resource {
},

"result_map": {
Type: schema.TypeMap,
Computed: true,
Type: schema.TypeMap,
Computed: true,
Deprecated: "use `result` attribute with jsondecode() function",
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/lambda_invocation.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ output "result_entry_tf012" {
## Attributes Reference

* `result` - String result of the lambda function invocation.
* `result_map` - This field is set only if result is a map of primitive types, where the map is string keys and string values. In Terraform 0.12 and later, use the [`jsondecode()` function](/docs/configuration/functions/jsondecode.html) with the `result` attribute instead to convert the result to all supported native Terraform types.
* `result_map` - (**DEPRECATED**) This field is set only if result is a map of primitive types, where the map is string keys and string values. In Terraform 0.12 and later, use the [`jsondecode()` function](/docs/configuration/functions/jsondecode.html) with the `result` attribute instead to convert the result to all supported native Terraform types.
27 changes: 27 additions & 0 deletions website/docs/guides/version-3-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Upgrade topics:
<!-- TOC depthFrom:2 depthTo:2 -->

- [Provider Version Configuration](#provider-version-configuration)
- [Data Source: aws_lambda_invocation](#data-source-aws_lambda_invocation)
- [Resource: aws_emr_cluster](#resource-aws_emr_cluster)

<!-- /TOC -->
Expand Down Expand Up @@ -51,6 +52,32 @@ provider "aws" {
}
```

## Data Source: aws_lambda_invocation

### result_map Attribute Removal

Switch your Terraform configuration to the `result` attribute with the [`jsondecode()` function](https://www.terraform.io/docs/configuration/functions/jsondecode.html) instead.

For example, given this previous configuration:

```hcl
# In Terraform 0.11 and earlier, the result_map attribute can be used
# to convert a result JSON string to a map of string keys to string values.
output "lambda_result" {
value = "${data.aws_lambda_invocation.example.result_map["key1"]}"
}
```

An updated configuration:

```hcl
# In Terraform 0.12 and later, the jsondecode() function can be used
# to convert a result JSON string to native Terraform types.
output "lambda_result" {
value = jsondecode(data.aws_lambda_invocation.example.result)["key1"]
}
```

## Resource: aws_emr_cluster

### core_instance_count Argument Removal
Expand Down

0 comments on commit 7a144ea

Please sign in to comment.