Skip to content

Commit

Permalink
r/aws_vpclattice_access_log_subscription: Tidy up.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed May 1, 2023
1 parent 8ab6423 commit 1d6edf7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 108 deletions.
33 changes: 15 additions & 18 deletions internal/service/vpclattice/access_log_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"log"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/vpclattice"
Expand All @@ -21,7 +20,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_vpclattice_access_log_subscription")
// @SDKResource("aws_vpclattice_access_log_subscription", name="Access Log Subscription")
// @Tags(identifierAttribute="arn")
func ResourceAccessLogSubscription() *schema.Resource {
return &schema.Resource{
Expand All @@ -34,17 +33,17 @@ func ResourceAccessLogSubscription() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"destination_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
"resource_arn": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -54,12 +53,6 @@ func ResourceAccessLogSubscription() *schema.Resource {
Required: true,
ForceNew: true,
},
"destination_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},
Expand All @@ -76,24 +69,28 @@ func resourceAccessLogSubscriptionCreate(ctx context.Context, d *schema.Resource
conn := meta.(*conns.AWSClient).VPCLatticeClient()

in := &vpclattice.CreateAccessLogSubscriptionInput{
ClientToken: aws.String(id.UniqueId()),
DestinationArn: aws.String(d.Get("destination_arn").(string)),
ResourceIdentifier: aws.String(d.Get("resource_identifier").(string)),
ClientToken: aws.String(id.UniqueId()),
Tags: GetTagsIn(ctx),
}

out, err := conn.CreateAccessLogSubscription(ctx, in)

if err != nil {
return create.DiagError(names.VPCLattice, create.ErrActionCreating, ResNameAccessLogSubscription, d.Get("destination_arn").(string), err)
}

d.SetId(aws.ToString(out.Id))

return resourceAccessLogSubscriptionRead(ctx, d, meta)
}

func resourceAccessLogSubscriptionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).VPCLatticeClient()

out, err := findAccessLogSubscriptionByID(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] VPCLattice AccessLogSubscription (%s) not found, removing from state", d.Id())
d.SetId("")
Expand All @@ -104,10 +101,10 @@ func resourceAccessLogSubscriptionRead(ctx context.Context, d *schema.ResourceDa
return create.DiagError(names.VPCLattice, create.ErrActionReading, ResNameAccessLogSubscription, d.Id(), err)
}

d.Set("resource_identifier", out.ResourceId)
d.Set("arn", out.Arn)
d.Set("destination_arn", out.DestinationArn)
d.Set("resource_arn", out.ResourceArn)
d.Set("arn", out.Arn)
d.Set("resource_identifier", out.ResourceId)

return nil
}
Expand All @@ -121,7 +118,6 @@ func resourceAccessLogSubscriptionDelete(ctx context.Context, d *schema.Resource
conn := meta.(*conns.AWSClient).VPCLatticeClient()

log.Printf("[INFO] Deleting VPCLattice AccessLogSubscription %s", d.Id())

_, err := conn.DeleteAccessLogSubscription(ctx, &vpclattice.DeleteAccessLogSubscriptionInput{
AccessLogSubscriptionIdentifier: aws.String(d.Id()),
})
Expand All @@ -134,6 +130,7 @@ func resourceAccessLogSubscriptionDelete(ctx context.Context, d *schema.Resource

return create.DiagError(names.VPCLattice, create.ErrActionDeleting, ResNameAccessLogSubscription, d.Id(), err)
}

return nil
}

Expand Down
90 changes: 0 additions & 90 deletions internal/service/vpclattice/access_log_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ func TestAccVPCLatticeAccessLogSubscription_basic(t *testing.T) {
resourceName := "aws_vpclattice_access_log_subscription.test"
serviceNetworkResourceName := "aws_vpclattice_service_network.test"
s3BucketResourceName := "aws_s3_bucket.test"
// cloudWatchLogGroupName := "aws_cloudwatch_log_group.test"
// kinesisDeliveryStreamName := "aws_kinesis_firehose_delivery_stream.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -48,36 +46,13 @@ func TestAccVPCLatticeAccessLogSubscription_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "destination_arn", s3BucketResourceName, "arn"),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", names.VPCLatticeEndpointID, regexp.MustCompile(`accesslogsubscription/.+$`)),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "tags_all.%", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
// {
// Config: testAccAccessLogSubscriptionConfig_basicCloudwatch(rName),
// Check: resource.ComposeTestCheckFunc(
// testAccCheckAccessLogSubscriptionExists(ctx, resourceName, &accesslogsubscription),
// resource.TestCheckResourceAttrPair(resourceName, "resource_identifier", serviceNetworkResourceName, "id"),
// resource.TestCheckResourceAttrPair(resourceName, "destination_arn", cloudWatchLogGroupName, "arn"),
// acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "vpc-lattice", regexp.MustCompile(`accesslogsubscription/.+$`)),
// resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
// resource.TestCheckResourceAttr(resourceName, "tags_all.%", "0"),
// ),
// },
// {
// Config: testAccAccessLogSubscriptionConfig_basicKinesis(rName),
// Check: resource.ComposeTestCheckFunc(
// testAccCheckAccessLogSubscriptionExists(ctx, resourceName, &accesslogsubscription),
// resource.TestCheckResourceAttrPair(resourceName, "resource_identifier", serviceNetworkResourceName, "id"),
// resource.TestCheckResourceAttrPair(resourceName, "destination_arn", kinesisDeliveryStreamName, "arn"),
// acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "vpc-lattice", regexp.MustCompile(`accesslogsubscription/.+$`)),
// resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
// resource.TestCheckResourceAttr(resourceName, "tags_all.%", "0"),
// ),
// },
},
})
}
Expand Down Expand Up @@ -231,71 +206,6 @@ resource "aws_vpclattice_access_log_subscription" "test" {
`, rName)
}

/*
func testAccAccessLogSubscriptionConfig_basicCloudWatch(rName string) string {
return fmt.Sprintf(`
resource "aws_vpclattice_service_network" "test" {
name = %[1]q
}
resource "aws_cloudwatch_log_group" "test" {
name = %[1]q
}
resource "aws_vpclattice_access_log_subscription" "test" {
resource_identifier = aws_vpclattice_service_network.test.id
destination_arn = aws_cloudwatch_log_group.test.arn
}
`, rName)
}
func testAccAccessLogSubscriptionConfig_basicKinesis(rName string) string {
return fmt.Sprintf(`
resource "aws_vpclattice_service_network" "test" {
name = %[1]q
}
resource "aws_s3_bucket" "test" {
bucket = %[1]q
force_destroy = true
}
resource "aws_iam_role" "test" {
name = %[1]q
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "firehose.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}]
}
EOF
}
resource "aws_kinesis_firehose_delivery_stream" "test" {
destination = "extended_s3"
name = %[1]q
extended_s3_configuration {
role_arn = aws_iam_role.test.arn
bucket_arn = aws_s3_bucket.test.arn
}
}
resource "aws_vpclattice_access_log_subscription" "test" {
resource_identifier = aws_vpclattice_service_network.test.id
destination_arn = aws_kinesis_firehose_delivery_stream.test.arn
}
`, rName)
}
*/

func testAccAccessLogSubscriptionConfig_tags1(rName, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_vpclattice_service_network" "test" {
Expand Down
1 change: 1 addition & 0 deletions internal/service/vpclattice/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1d6edf7

Please sign in to comment.