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

Tagging tests for drs #39061

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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
1 change: 1 addition & 0 deletions internal/service/drs/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsInIDElem=ResourceArn -ServiceTagsMap -SkipTypesImp -KVTValues -TagOp=TagResource -TagInIDElem=ResourceArn -UntagOp=UntagResource -CreateTags -ListTags -UpdateTags
//go:generate go run ../../generate/servicepackage/main.go
//go:generate go run ../../generate/tagstests/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

package drs
14 changes: 6 additions & 8 deletions internal/service/drs/replication_configuration_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource(name="Replication Configuration Template")
// @FrameworkResource("aws_drs_replication_configuration_template", name="Replication Configuration Template")
// @Tags(identifierAttribute="arn")
// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/drs/types;awstypes;awstypes.ReplicationConfigurationTemplate")
// @Testing(serialize=true)
func newReplicationConfigurationTemplateResource(_ context.Context) (resource.ResourceWithConfigure, error) {
r := &replicationConfigurationTemplateResource{}

Expand All @@ -56,9 +58,7 @@ func (r *replicationConfigurationTemplateResource) Metadata(_ context.Context, r
func (r *replicationConfigurationTemplateResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
names.AttrARN: schema.StringAttribute{
Computed: true,
},
names.AttrARN: framework.ARNAttributeComputedOnly(),
"associate_default_security_group": schema.BoolAttribute{
Required: true,
},
Expand Down Expand Up @@ -90,9 +90,7 @@ func (r *replicationConfigurationTemplateResource) Schema(ctx context.Context, r
"ebs_encryption_key_arn": schema.StringAttribute{
Optional: true,
},
names.AttrID: schema.StringAttribute{
Computed: true,
},
names.AttrID: framework.IDAttribute(),
"replication_server_instance_type": schema.StringAttribute{
Required: true,
},
Expand All @@ -104,7 +102,7 @@ func (r *replicationConfigurationTemplateResource) Schema(ctx context.Context, r
Required: true,
},

"staging_area_tags": tftags.TagsAttribute(),
"staging_area_tags": tftags.TagsAttributeRequired(),
names.AttrTags: tftags.TagsAttribute(),
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),

Expand Down
1,874 changes: 1,874 additions & 0 deletions internal/service/drs/replication_configuration_template_tags_gen_test.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccDRSReplicationConfigurationTemplate_serial(t *testing.T) {
testCases := map[string]func(t *testing.T){
acctest.CtBasic: testAccReplicationConfigurationTemplate_basic,
acctest.CtDisappears: testAccReplicationConfigurationTemplate_disappears,
"tags": testAccDRSReplicationConfigurationTemplate_tagsSerial,
}

acctest.RunSerialTests1Level(t, testCases, 5*time.Second)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

resource "aws_drs_replication_configuration_template" "test" {
associate_default_security_group = false
bandwidth_throttling = 12
create_public_ip = false
data_plane_routing = "PRIVATE_IP"
default_large_staging_disk_type = "GP2"
ebs_encryption = "NONE"
use_dedicated_replication_server = false
replication_server_instance_type = "t3.small"
replication_servers_security_groups_ids = [aws_security_group.test.id]
staging_area_subnet_id = aws_subnet.test[0].id

pit_policy {
enabled = true
interval = 10
retention_duration = 60
units = "MINUTE"
rule_id = 1
}

pit_policy {
enabled = true
interval = 1
retention_duration = 24
units = "HOUR"
rule_id = 2
}

pit_policy {
enabled = true
interval = 1
retention_duration = 3
units = "DAY"
rule_id = 3
}

staging_area_tags = {
Name = var.rName
}

tags = var.resource_tags
}

resource "aws_security_group" "test" {
name = var.rName
description = var.rName
vpc_id = aws_vpc.test.id

ingress {
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
}

# acctest.ConfigVPCWithSubnets(rName, 1)

resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"

tags = {
Name = var.rName
}
}

resource "aws_subnet" "test" {
count = 1

vpc_id = aws_vpc.test.id
availability_zone = data.aws_availability_zones.available.names[count.index]
cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, count.index)
}

# acctest.ConfigAvailableAZsNoOptInDefaultExclude()

data "aws_availability_zones" "available" {
exclude_zone_ids = local.default_exclude_zone_ids
state = "available"

filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

locals {
default_exclude_zone_ids = ["usw2-az4", "usgw1-az2"]
}

variable "rName" {
description = "Name for resource"
type = string
nullable = false
}

variable "resource_tags" {
description = "Tags to set on resource. To specify no tags, set to `null`"
# Not setting a default, so that this must explicitly be set to `null` to specify no tags
type = map(string)
nullable = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

provider "null" {}

resource "aws_drs_replication_configuration_template" "test" {
associate_default_security_group = false
bandwidth_throttling = 12
create_public_ip = false
data_plane_routing = "PRIVATE_IP"
default_large_staging_disk_type = "GP2"
ebs_encryption = "NONE"
use_dedicated_replication_server = false
replication_server_instance_type = "t3.small"
replication_servers_security_groups_ids = [aws_security_group.test.id]
staging_area_subnet_id = aws_subnet.test[0].id

pit_policy {
enabled = true
interval = 10
retention_duration = 60
units = "MINUTE"
rule_id = 1
}

pit_policy {
enabled = true
interval = 1
retention_duration = 24
units = "HOUR"
rule_id = 2
}

pit_policy {
enabled = true
interval = 1
retention_duration = 3
units = "DAY"
rule_id = 3
}

staging_area_tags = {
Name = var.rName
}

tags = {
(var.unknownTagKey) = null_resource.test.id
}
}

resource "aws_security_group" "test" {
name = var.rName
description = var.rName
vpc_id = aws_vpc.test.id

ingress {
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
}

# acctest.ConfigVPCWithSubnets(rName, 1)

resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"

tags = {
Name = var.rName
}
}

resource "aws_subnet" "test" {
count = 1

vpc_id = aws_vpc.test.id
availability_zone = data.aws_availability_zones.available.names[count.index]
cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, count.index)
}

# acctest.ConfigAvailableAZsNoOptInDefaultExclude()

data "aws_availability_zones" "available" {
exclude_zone_ids = local.default_exclude_zone_ids
state = "available"

filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

locals {
default_exclude_zone_ids = ["usw2-az4", "usgw1-az2"]
}

resource "null_resource" "test" {}

variable "rName" {
description = "Name for resource"
type = string
nullable = false
}

variable "unknownTagKey" {
type = string
nullable = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

provider "null" {}

resource "aws_drs_replication_configuration_template" "test" {
associate_default_security_group = false
bandwidth_throttling = 12
create_public_ip = false
data_plane_routing = "PRIVATE_IP"
default_large_staging_disk_type = "GP2"
ebs_encryption = "NONE"
use_dedicated_replication_server = false
replication_server_instance_type = "t3.small"
replication_servers_security_groups_ids = [aws_security_group.test.id]
staging_area_subnet_id = aws_subnet.test[0].id

pit_policy {
enabled = true
interval = 10
retention_duration = 60
units = "MINUTE"
rule_id = 1
}

pit_policy {
enabled = true
interval = 1
retention_duration = 24
units = "HOUR"
rule_id = 2
}

pit_policy {
enabled = true
interval = 1
retention_duration = 3
units = "DAY"
rule_id = 3
}

staging_area_tags = {
Name = var.rName
}

tags = {
(var.unknownTagKey) = null_resource.test.id
(var.knownTagKey) = var.knownTagValue
}
}

resource "aws_security_group" "test" {
name = var.rName
description = var.rName
vpc_id = aws_vpc.test.id

ingress {
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
}

# acctest.ConfigVPCWithSubnets(rName, 1)

resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"

tags = {
Name = var.rName
}
}

resource "aws_subnet" "test" {
count = 1

vpc_id = aws_vpc.test.id
availability_zone = data.aws_availability_zones.available.names[count.index]
cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, count.index)
}

# acctest.ConfigAvailableAZsNoOptInDefaultExclude()

data "aws_availability_zones" "available" {
exclude_zone_ids = local.default_exclude_zone_ids
state = "available"

filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

locals {
default_exclude_zone_ids = ["usw2-az4", "usgw1-az2"]
}

resource "null_resource" "test" {}

variable "rName" {
description = "Name for resource"
type = string
nullable = false
}

variable "unknownTagKey" {
type = string
nullable = false
}

variable "knownTagKey" {
type = string
nullable = false
}

variable "knownTagValue" {
type = string
nullable = false
}
Loading
Loading