Skip to content

Commit

Permalink
You can enable the Lightsail connect CIDR list alias only on TCP port…
Browse files Browse the repository at this point in the history
…s 22 or 3389
  • Loading branch information
bschaatsbergen committed Dec 15, 2022
1 parent fdc0381 commit 29ef95a
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions internal/service/lightsail/instance_public_ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,38 @@ func TestAccLightsailInstancePublicPorts_cidrs(t *testing.T) {
})
}

func TestAccLightsailInstancePublicPorts_cidrListAliases(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_lightsail_instance_public_ports.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(t)
acctest.PreCheckPartitionHasService(lightsail.EndpointsID, t)
testAccPreCheck(t)
},
ErrorCheck: acctest.ErrorCheck(t, lightsail.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckInstancePublicPortsDestroy,
Steps: []resource.TestStep{
{
Config: testAccInstancePublicPortsConfig_cidrListAliases(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstancePublicPortsExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "port_info.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "port_info.*", map[string]string{
"protocol": "tcp",
"from_port": "22",
"to_port": "22",
"cidr_list_aliases.#": "1",
}),
resource.TestCheckTypeSetElemAttr(resourceName, "port_info.*.cidr_list_aliases.*", "lightsail-connect"),
),
},
},
})
}

func TestAccLightsailInstancePublicPorts_disappears(t *testing.T) {
resourceName := "aws_lightsail_instance_public_ports.test"
rName := sdkacctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -315,3 +347,34 @@ resource "aws_lightsail_instance_public_ports" "test" {
}
`, rName)
}

func testAccInstancePublicPortsConfig_cidrListAliases(rName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
state = "available"
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}
resource "aws_lightsail_instance" "test" {
name = %[1]q
availability_zone = data.aws_availability_zones.available.names[0]
blueprint_id = "amazon_linux"
bundle_id = "nano_1_0"
}
resource "aws_lightsail_instance_public_ports" "test" {
instance_name = aws_lightsail_instance.test.name
port_info {
protocol = "tcp"
from_port = 22
to_port = 22
cidr_list_aliases = ["lightsail-connect"]
}
}
`, rName)
}

0 comments on commit 29ef95a

Please sign in to comment.