mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Add note to aws_security_group data source describing the default security group for a VPC. (#10247)
Add a corresponding acceptance test.
This commit is contained in:
parent
44885f45d3
commit
fd8d41f6a5
@ -20,6 +20,7 @@ func TestAccDataSourceAwsSecurityGroup(t *testing.T) {
|
|||||||
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_tag"),
|
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_tag"),
|
||||||
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_filter"),
|
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_filter"),
|
||||||
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_name"),
|
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_name"),
|
||||||
|
testAccDataSourceAwsSecurityGroupCheckDefault("data.aws_security_group.default_by_name"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -67,6 +68,31 @@ func testAccDataSourceAwsSecurityGroupCheck(name string) resource.TestCheckFunc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccDataSourceAwsSecurityGroupCheckDefault(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("root module has no resource called %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
vpcRs, ok := s.RootModule().Resources["aws_vpc.test"]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("can't find aws_vpc.test in state")
|
||||||
|
}
|
||||||
|
attr := rs.Primary.Attributes
|
||||||
|
|
||||||
|
if attr["id"] != vpcRs.Primary.Attributes["default_security_group_id"] {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"id is %s; want %s",
|
||||||
|
attr["id"],
|
||||||
|
vpcRs.Primary.Attributes["default_security_group_id"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const testAccDataSourceAwsSecurityGroupConfig = `
|
const testAccDataSourceAwsSecurityGroupConfig = `
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "eu-west-1"
|
region = "eu-west-1"
|
||||||
@ -94,6 +120,12 @@ data "aws_security_group" "by_id" {
|
|||||||
data "aws_security_group" "by_name" {
|
data "aws_security_group" "by_name" {
|
||||||
name = "${aws_security_group.test.name}"
|
name = "${aws_security_group.test.name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data "aws_security_group" "default_by_name" {
|
||||||
|
vpc_id = "${aws_vpc.test.id}"
|
||||||
|
name = "default"
|
||||||
|
}
|
||||||
|
|
||||||
data "aws_security_group" "by_tag" {
|
data "aws_security_group" "by_tag" {
|
||||||
tags {
|
tags {
|
||||||
Name = "${aws_security_group.test.tags["Name"]}"
|
Name = "${aws_security_group.test.tags["Name"]}"
|
||||||
|
@ -67,3 +67,4 @@ any fields that are not included in the configuration with the data for
|
|||||||
the selected Security Group.
|
the selected Security Group.
|
||||||
Additionally, the `description` attribute is exported.
|
Additionally, the `description` attribute is exported.
|
||||||
|
|
||||||
|
~> **Note:** The [default security group for a VPC](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_SecurityGroups.html#DefaultSecurityGroup) has the name `default`.
|
||||||
|
Loading…
Reference in New Issue
Block a user