-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
d/aws_ec2_host: Get acceptance tests working.
- Loading branch information
Showing
5 changed files
with
186 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,119 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccAWSEc2HostDataSource_basic(t *testing.T) { | ||
dataSourceName := "data.aws_ec2_host.test" | ||
resourceName := "aws_ec2_host.test" | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDedicatedHostDataSourceConfig, | ||
Config: testAccDataSourceAWSEc2HostConfig(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "instance_type", resourceName, "instance_type"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "auto_placement", resourceName, "auto_placement"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone", resourceName, "availability_zone"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "instance_family", resourceName, "instance_family"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "cores", resourceName, "cores"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "total_vcpus", resourceName, "total_vcpus"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "sockets", resourceName, "sockets"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "cores"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "host_id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "host_recovery", resourceName, "host_recovery"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "instance_family", resourceName, "instance_family"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "instance_type", resourceName, "instance_type"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "owner_id", resourceName, "owner_id"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "sockets"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "total_vcpus"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSEc2HostDataSource_Filter(t *testing.T) { | ||
dataSourceName := "data.aws_ec2_host.test" | ||
resourceName := "aws_ec2_host.test" | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAWSEc2HostConfigFilter(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "auto_placement", resourceName, "auto_placement"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.tag1", "test-value1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.tag2", "test-value2"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone", resourceName, "availability_zone"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "cores"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "host_id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "host_recovery", resourceName, "host_recovery"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "instance_family", resourceName, "instance_family"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "instance_type", resourceName, "instance_type"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "owner_id", resourceName, "owner_id"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "sockets"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "total_vcpus"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDedicatedHostDataSourceConfig = ` | ||
func testAccDataSourceAWSEc2HostConfig(rName string) string { | ||
return composeConfig(testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(` | ||
resource "aws_ec2_host" "test" { | ||
instance_type = "c5.xlarge" | ||
availability_zone = "${data.aws_availability_zones.available.names[0]}" | ||
host_recovery = "on" | ||
auto_placement = "on" | ||
tags = { | ||
tag1 = "test-value1" | ||
tag2 = "test-value2" | ||
availability_zone = data.aws_availability_zones.available.names[0] | ||
instance_type = "a1.large" | ||
tags = { | ||
Name = %[1]q | ||
} | ||
} | ||
data "aws_ec2_host" "test" { | ||
host_id = aws_ec2_host.test.id | ||
} | ||
`, rName)) | ||
} | ||
|
||
func testAccDataSourceAWSEc2HostConfigFilter(rName string) string { | ||
return composeConfig(testAccAvailableAZsNoOptInConfig(), fmt.Sprintf(` | ||
resource "aws_ec2_host" "test" { | ||
availability_zone = data.aws_availability_zones.available.names[0] | ||
instance_type = "a1.large" | ||
tags = { | ||
%[1]q = "True" | ||
} | ||
} | ||
data "aws_ec2_host" "test" { | ||
filter { | ||
name = "availability-zone" | ||
values = [aws_ec2_host.test.availability_zone] | ||
} | ||
data "aws_availability_zones" "available" { | ||
state = "available" | ||
filter { | ||
name = "opt-in-status" | ||
values = ["opt-in-not-required"] | ||
} | ||
filter { | ||
name = "instance-type" | ||
values = [aws_ec2_host.test.instance_type] | ||
} | ||
` | ||
filter { | ||
name = "tag-key" | ||
values = [%[1]q] | ||
} | ||
} | ||
`, rName)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.