Skip to content

Commit

Permalink
Merge pull request #11997 from CGreenburg/master
Browse files Browse the repository at this point in the history
Add `skip_destroy` parameter to `aws_lambda_layer_version` resource
  • Loading branch information
YakDriver authored Nov 18, 2021
2 parents 7af9627 + 9f74fbd commit 16371e9
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 148 deletions.
3 changes: 3 additions & 0 deletions .changelog/11997.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_lambda_layer_version: Add `skip_destroy` attribute
```
2 changes: 1 addition & 1 deletion internal/service/lambda/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (

func init() {
acctest.RegisterServiceErrorCheckFunc(lambda.EndpointsID, testAccErrorCheckSkipLambda)

}

func testAccErrorCheckSkipLambda(t *testing.T) resource.ErrorCheckFunc {
return acctest.ErrorCheckSkipMessagesContaining(t,
"InvalidParameterValueException: Unsupported source arn",
"InvalidParameterValueException: CompatibleArchitectures are not",
)
}

Expand Down
94 changes: 52 additions & 42 deletions internal/service/lambda/layer_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/flex"
)

const awsMutexLambdaLayerKey = `aws_lambda_layer_version`
const mutexLayerKey = `aws_lambda_layer_version`

func ResourceLayerVersion() *schema.Resource {
return &schema.Resource{
Expand All @@ -30,6 +30,10 @@ func ResourceLayerVersion() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"compatible_architectures": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -40,9 +44,24 @@ func ResourceLayerVersion() *schema.Resource {
ValidateFunc: validation.StringInSlice(lambda.Architecture_Values(), false),
},
},
"layer_name": {
"compatible_runtimes": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
MinItems: 0,
MaxItems: 15,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(lambda.Runtime_Values(), false),
},
},
"created_date": {
Type: schema.TypeString,
Required: true,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"filename": {
Expand All @@ -51,6 +70,21 @@ func ResourceLayerVersion() *schema.Resource {
ForceNew: true,
ConflictsWith: []string{"s3_bucket", "s3_key", "s3_object_version"},
},
"layer_arn": {
Type: schema.TypeString,
Computed: true,
},
"layer_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"license_info": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(0, 512),
},
"s3_bucket": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -69,55 +103,26 @@ func ResourceLayerVersion() *schema.Resource {
ForceNew: true,
ConflictsWith: []string{"filename"},
},
"compatible_runtimes": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
MinItems: 0,
MaxItems: 15,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(lambda.Runtime_Values(), false),
},
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"license_info": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(0, 512),
},

"arn": {
"signing_job_arn": {
Type: schema.TypeString,
Computed: true,
},
"layer_arn": {
"signing_profile_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"created_date": {
Type: schema.TypeString,
Computed: true,
"skip_destroy": {
Type: schema.TypeBool,
Default: false,
ForceNew: true,
Optional: true,
},
"source_code_hash": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"signing_profile_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"signing_job_arn": {
Type: schema.TypeString,
Computed: true,
},
"source_code_size": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -145,8 +150,8 @@ func resourceLayerVersionPublish(d *schema.ResourceData, meta interface{}) error

var layerContent *lambda.LayerVersionContentInput
if hasFilename {
conns.GlobalMutexKV.Lock(awsMutexLambdaLayerKey)
defer conns.GlobalMutexKV.Unlock(awsMutexLambdaLayerKey)
conns.GlobalMutexKV.Lock(mutexLayerKey)
defer conns.GlobalMutexKV.Unlock(mutexLayerKey)
file, err := loadFileContent(filename.(string))
if err != nil {
return fmt.Errorf("Unable to load %q: %s", filename.(string), err)
Expand Down Expand Up @@ -260,6 +265,11 @@ func resourceLayerVersionRead(d *schema.ResourceData, meta interface{}) error {
}

func resourceLayerVersionDelete(d *schema.ResourceData, meta interface{}) error {
if v, ok := d.GetOk("skip_destroy"); ok && v.(bool) {
log.Printf("[DEBUG] Retaining Lambda Layer Version %q", d.Id())
return nil
}

conn := meta.(*conns.AWSClient).LambdaConn

version, err := strconv.ParseInt(d.Get("version").(string), 10, 64)
Expand All @@ -272,7 +282,7 @@ func resourceLayerVersionDelete(d *schema.ResourceData, meta interface{}) error
VersionNumber: aws.Int64(version),
})
if err != nil {
return fmt.Errorf("error deleting Lambda Layer Version (%s): %s", d.Id(), err)
return fmt.Errorf("Error deleting Lambda Layer Version (%s): %s", d.Id(), err)
}

log.Printf("[DEBUG] Lambda layer %q deleted", d.Get("arn").(string))
Expand Down
Loading

0 comments on commit 16371e9

Please sign in to comment.