-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
d/aws_ssm_instances #23162
d/aws_ssm_instances #23162
Conversation
@kamilturek The code changes LGTM but the acceptance tests continually fail: % make testacc TESTS=TestAccSSMInstancesDataSource_ PKG=ssm
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ssm/... -v -count 1 -parallel 20 -run='TestAccSSMInstancesDataSource_' -timeout 180m
=== RUN TestAccSSMInstancesDataSource_filter
=== PAUSE TestAccSSMInstancesDataSource_filter
=== CONT TestAccSSMInstancesDataSource_filter
instances_data_source_test.go:18: Step 1/1 error: Check failed: 2 errors occurred:
* Check 1/2 error: data.aws_ssm_instances.test: Attribute 'ids.#' expected "1", got "0"
* Check 2/2 error: data.aws_ssm_instances.test: Attribute "ids.0" not set, but "id" is set in aws_instance.test as "i-08cceda591b59bee6"
--- FAIL: TestAccSSMInstancesDataSource_filter (133.40s)
FAIL
FAIL github.com/hashicorp/terraform-provider-aws/internal/service/ssm 138.191s
FAIL
make: *** [testacc] Error 1 Do you think this could be a timing issue - the SSM agent on the EC2 instance hasn't registered at the time the |
@ewbankkit Thanks for reviewing the PR! Indeed, I believe the failing test is a result of a timing issue. It passes on my machine, but I guess it's because the test takes longer to execute on my side (171 s vs 138 s on yours) and the delay is sufficient for the instance to register itself in SSM. I'd think about increasing a time period before the check by moving it to a separate step: diff --git a/internal/service/ssm/instances_data_source_test.go b/internal/service/ssm/instances_data_source_test.go
index ebc86bfeab..a2cfc945ea 100644
--- a/internal/service/ssm/instances_data_source_test.go
+++ b/internal/service/ssm/instances_data_source_test.go
@@ -21,7 +21,10 @@ func TestAccSSMInstancesDataSource_filter(t *testing.T) {
Providers: acctest.Providers,
Steps: []resource.TestStep{
{
- Config: testAccCheckInstancesDataSourceConfig_filter(rName),
+ Config: testAccCheckInstancesDataSourceConfig_filter_instance(rName),
+ },
+ {
+ Config: testAccCheckInstancesDataSourceConfig_filter_dataSource(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "ids.#", "1"),
resource.TestCheckResourceAttrPair(dataSourceName, "ids.0", resourceName, "id"),
@@ -31,7 +34,7 @@ func TestAccSSMInstancesDataSource_filter(t *testing.T) {
})
}
-func testAccCheckInstancesDataSourceConfig_filter(rName string) string {
+func testAccCheckInstancesDataSourceConfig_filter_instance(rName string) string {
return acctest.ConfigCompose(
acctest.AvailableEC2InstanceTypeForRegion("t2.micro", "t3.micro"),
fmt.Sprintf(`
@@ -83,12 +86,18 @@ resource "aws_instance" "test" {
instance_type = data.aws_ec2_instance_type_offering.available.instance_type
iam_instance_profile = aws_iam_instance_profile.test.name
}
+`, rName))
+}
+func testAccCheckInstancesDataSourceConfig_filter_dataSource(rName string) string {
+ return acctest.ConfigCompose(
+ testAccCheckInstancesDataSourceConfig_filter_instance(rName),
+ `
data "aws_ssm_instances" "test" {
filter {
name = "InstanceIds"
values = [aws_instance.test.id]
}
}
-`, rName))
+`)
} Or even an explicit sleep: diff --git a/internal/service/ssm/instances_data_source_test.go b/internal/service/ssm/instances_data_source_test.go
index ebc86bfeab..ea4f2aec1e 100644
--- a/internal/service/ssm/instances_data_source_test.go
+++ b/internal/service/ssm/instances_data_source_test.go
@@ -3,10 +3,12 @@ package ssm_test
import (
"fmt"
"testing"
+ "time"
"github.com/aws/aws-sdk-go/service/ssm"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)
@@ -15,14 +17,25 @@ func TestAccSSMInstancesDataSource_filter(t *testing.T) {
dataSourceName := "data.aws_ssm_instances.test"
resourceName := "aws_instance.test"
+ fulfillSleep := func() resource.TestCheckFunc {
+ return func(s *terraform.State) error {
+ time.Sleep(1 * time.Minute)
+ return nil
+ }
+ }
+
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, ssm.EndpointsID),
Providers: acctest.Providers,
Steps: []resource.TestStep{
{
- Config: testAccCheckInstancesDataSourceConfig_filter(rName),
+ Config: testAccCheckInstancesDataSourceConfig_filter_instance(rName),
+ },
+ {
+ Config: testAccCheckInstancesDataSourceConfig_filter_dataSource(rName),
Check: resource.ComposeAggregateTestCheckFunc(
+ fulfillSleep(),
resource.TestCheckResourceAttr(dataSourceName, "ids.#", "1"),
resource.TestCheckResourceAttrPair(dataSourceName, "ids.0", resourceName, "id"),
),
@@ -31,7 +44,7 @@ func TestAccSSMInstancesDataSource_filter(t *testing.T) {
})
}
-func testAccCheckInstancesDataSourceConfig_filter(rName string) string {
+func testAccCheckInstancesDataSourceConfig_filter_instance(rName string) string {
return acctest.ConfigCompose(
acctest.AvailableEC2InstanceTypeForRegion("t2.micro", "t3.micro"),
fmt.Sprintf(`
@@ -83,12 +96,18 @@ resource "aws_instance" "test" {
instance_type = data.aws_ec2_instance_type_offering.available.instance_type
iam_instance_profile = aws_iam_instance_profile.test.name
}
+`, rName))
+}
+func testAccCheckInstancesDataSourceConfig_filter_dataSource(rName string) string {
+ return acctest.ConfigCompose(
+ testAccCheckInstancesDataSourceConfig_filter_instance(rName),
+ `
data "aws_ssm_instances" "test" {
filter {
name = "InstanceIds"
values = [aws_instance.test.id]
}
}
-`, rName))
+`)
} All the variants pass on my machine so I really don't have a way to verify if they solve the timing issue 😞 |
Let's try with the explicit |
@ewbankkit That's done 🙂 Please give it a try.
Let me know please if there's anything else I could do here. |
…cate with the SSM service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀.
% make testacc TESTS=TestAccSSMInstancesDataSource_ PKG=ssm
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ssm/... -v -count 1 -parallel 20 -run='TestAccSSMInstancesDataSource_' -timeout 180m
=== RUN TestAccSSMInstancesDataSource_filter
=== PAUSE TestAccSSMInstancesDataSource_filter
=== CONT TestAccSSMInstancesDataSource_filter
--- PASS: TestAccSSMInstancesDataSource_filter (327.96s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/ssm 332.257s
@kamilturek Thanks for the contribution 🎉 👏. |
@ewbankkit Ah, that's why! It makes sense. Thanks, that's nice learning! |
This functionality has been released in v4.2.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Closes #23135.
Output from acceptance testing: