-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40958 from hashicorp/b-lambda_invocation-createon…
…ly-update
- Loading branch information
Showing
4 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```release-note:bug | ||
resource/aws_lambda_invocation: Prevent a new invocation when upgrading from a version less than `v5.1.0` with no configuration changes | ||
``` | ||
```release-note:bug | ||
resource/aws_lambda_invocation: Fix failed input transformations when upgrading from a version less than `v5.1.0` with an `input` that cannot be marshaled into a `map[string]interface{}` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package lambda | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
"github.com/hashicorp/terraform-provider-aws/internal/enum" | ||
"github.com/hashicorp/terraform-provider-aws/names" | ||
) | ||
|
||
func resourceInvocationConfigV0() *schema.Resource { | ||
// Resource with v0 schema (provider v5.83.0 and below) | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"function_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"input": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsJSON, | ||
}, | ||
"lifecycle_scope": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: lifecycleScopeCreateOnly, | ||
ValidateDiagFunc: enum.Validate[lifecycleScope](), | ||
}, | ||
"qualifier": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
Default: FunctionVersionLatest, | ||
}, | ||
"result": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"terraform_key": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "tf", | ||
}, | ||
names.AttrTriggers: { | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// This upgrader _should have_ been implemented in v5.1.0 alongside the | ||
// additions of the lifecycle_scope and terraform_key arguments with | ||
// default values, but was overlooked at the time. Because we cannot | ||
// reasonably go back and patch the schemas for all versions in between, | ||
// we instead handle both pre-v5.1.0 and v5.1.0-v5.83.0 versions of the | ||
// previous state. | ||
func invocationStateUpgradeV0(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
if rawState == nil { | ||
rawState = map[string]interface{}{} | ||
} | ||
|
||
// If upgrading from a version < v5.1.0, these values will be unset and | ||
// should be set to the defaults added in v5.1.0 | ||
if rawState["lifecycle_scope"] == nil { | ||
rawState["lifecycle_scope"] = lifecycleScopeCreateOnly | ||
} | ||
if rawState["terraform_key"] == nil { | ||
rawState["terraform_key"] = "tf" | ||
} | ||
|
||
return rawState, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters