Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resource aws_ebs_snapshot_lock #37436

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions internal/service/ec2/ebs_snapshot_block_public_access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package ec2

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
)

// @SDKResource("aws_ebs_snapshot_block_public_access")
func ResourceEBSSnapshotBlockPublicAccess() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceEBSSnapshotBlockPublicAccessCreate,
ReadWithoutTimeout: resourceEBSSnapshotBlockPublicAccessRead,
UpdateWithoutTimeout: resourceEBSSnapshotBlockPublicAccessUpdate,
DeleteWithoutTimeout: resourceEBSSnapshotBlockPublicAccessDelete,

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
"state": {
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: enum.Validate[types.SnapshotBlockPublicAccessState](),
},
},
}
}

func resourceEBSSnapshotBlockPublicAccessCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EC2Client(ctx)

input := &ec2.EnableSnapshotBlockPublicAccessInput{
State: types.SnapshotBlockPublicAccessState(d.Get("state").(string)),
}

_, err := conn.EnableSnapshotBlockPublicAccess(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "enabling EBS snapshot block public access: %s", err)
}

d.SetId(meta.(*conns.AWSClient).Region)

return append(diags, resourceEBSSnapshotBlockPublicAccessRead(ctx, d, meta)...)
}

func resourceEBSSnapshotBlockPublicAccessRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EC2Client(ctx)

output, err := conn.GetSnapshotBlockPublicAccessState(ctx, &ec2.GetSnapshotBlockPublicAccessStateInput{})

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading EBS snapshot block public access: %s", err)
}

d.Set("state", string(output.State))

return diags
}

func resourceEBSSnapshotBlockPublicAccessUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EC2Client(ctx)

input := &ec2.EnableSnapshotBlockPublicAccessInput{
State: types.SnapshotBlockPublicAccessState(d.Get("state").(string)),
}

_, err := conn.EnableSnapshotBlockPublicAccess(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "update EBS snapshot block public access: %s", err)
}

d.SetId(meta.(*conns.AWSClient).Region)

return append(diags, resourceEBSSnapshotBlockPublicAccessRead(ctx, d, meta)...)
}

func resourceEBSSnapshotBlockPublicAccessDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EC2Client(ctx)

_, err := conn.DisableSnapshotBlockPublicAccess(ctx, &ec2.DisableSnapshotBlockPublicAccessInput{})

if err != nil {
return sdkdiag.AppendErrorf(diags, "disabling EBS snapshot block public access: %s", err)
}

return diags
}
48 changes: 48 additions & 0 deletions internal/service/ec2/ebs_snapshot_block_public_access_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package ec2_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccSnapshotBlockPublicAccess_basic(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_ebs_snapshot_block_public_access.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckSnapshotBlockAccessDestroy(ctx),

Check failure on line 24 in internal/service/ec2/ebs_snapshot_block_public_access_test.go

View workflow job for this annotation

GitHub Actions / providerlint

undefined: testAccCheckSnapshotBlockAccessDestroy

Check failure on line 24 in internal/service/ec2/ebs_snapshot_block_public_access_test.go

View workflow job for this annotation

GitHub Actions / providerlint

undefined: testAccCheckSnapshotBlockAccessDestroy

Check failure on line 24 in internal/service/ec2/ebs_snapshot_block_public_access_test.go

View workflow job for this annotation

GitHub Actions / 2 of 2

undefined: testAccCheckSnapshotBlockAccessDestroy

Check failure on line 24 in internal/service/ec2/ebs_snapshot_block_public_access_test.go

View workflow job for this annotation

GitHub Actions / go test

undefined: testAccCheckSnapshotBlockAccessDestroy
Steps: []resource.TestStep{
{
Config: testAccSnapshotBlockPublicAccess_basic(string(types.SnapshotBlockPublicAccessStateBlockAllSharing)),
Check: resource.ComposeTestCheckFunc(
testAccCheckSnapshotBlockPublicAccess(ctx, resourceName, false),

Check failure on line 29 in internal/service/ec2/ebs_snapshot_block_public_access_test.go

View workflow job for this annotation

GitHub Actions / providerlint

undefined: testAccCheckSnapshotBlockPublicAccess

Check failure on line 29 in internal/service/ec2/ebs_snapshot_block_public_access_test.go

View workflow job for this annotation

GitHub Actions / providerlint

undefined: testAccCheckSnapshotBlockPublicAccess

Check failure on line 29 in internal/service/ec2/ebs_snapshot_block_public_access_test.go

View workflow job for this annotation

GitHub Actions / 2 of 2

undefined: testAccCheckSnapshotBlockPublicAccess (typecheck)

Check failure on line 29 in internal/service/ec2/ebs_snapshot_block_public_access_test.go

View workflow job for this annotation

GitHub Actions / go test

undefined: testAccCheckSnapshotBlockPublicAccess
resource.TestCheckResourceAttr(resourceName, names.AttrEnabled, "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccSnapshotBlockPublicAccess_basic(status string) string {
return fmt.Sprintf(`
resource "aws_ebs_snapshot_block_public_access" "test" {
status = %[1]s
}
`, status)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
subcategory: "EBS (EC2)"
layout: "aws"
page_title: "AWS: aws_ebs_snapshot_block_public_access"
description: |-
Manages EBS snapshot public access block configuration
---

# Resource: aws_ebs_snapshot_block_public_access
Loading