-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Allow Data Source for AWS instances to get instances that are in a state other than running #4950
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,22 @@ func TestAccAWSInstancesDataSource_tags(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSInstancesDataSource_instance_state_names(t *testing.T) { | ||
rInt := acctest.RandInt() | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccInstancesDataSourceConfig_instance_state_names(rInt), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_instances.test", "ids.#", "2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccInstancesDataSourceConfig_ids = ` | ||
data "aws_ami" "ubuntu" { | ||
most_recent = true | ||
|
@@ -113,3 +129,41 @@ data "aws_instances" "test" { | |
} | ||
`, rInt) | ||
} | ||
|
||
func testAccInstancesDataSourceConfig_instance_state_names(rInt int) string { | ||
return fmt.Sprintf(` | ||
data "aws_ami" "ubuntu" { | ||
most_recent = true | ||
|
||
filter { | ||
name = "name" | ||
values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"] | ||
} | ||
|
||
filter { | ||
name = "virtualization-type" | ||
values = ["hvm"] | ||
} | ||
|
||
owners = ["099720109477"] # Canonical | ||
} | ||
|
||
resource "aws_instance" "test" { | ||
count = 2 | ||
ami = "${data.aws_ami.ubuntu.id}" | ||
instance_type = "t2.micro" | ||
tags { | ||
Name = "TfAccTest-HelloWorld" | ||
TestSeed = "%[1]d" | ||
} | ||
} | ||
|
||
data "aws_instances" "test" { | ||
instance_tags { | ||
Name = "*" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To properly setup the resource and data source ordering, you can reference the Name = "${aws_instance.test.0.tags["Name"]}" This should be enough to delay the data source to catch the two new instances 👍 Let me know if this still is causing an issue and we can dive in deeper. Thanks for your work here! |
||
} | ||
|
||
instance_state_names = [ "pending", "running" ] | ||
} | ||
`, rInt) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ data "aws_instances" "test" { | |
name = "instance.group-id" | ||
values = ["sg-12345678"] | ||
} | ||
|
||
instance_state_names = [ "running", "stopped" ] | ||
} | ||
|
||
resource "aws_eip" "test" { | ||
|
@@ -45,6 +47,8 @@ resource "aws_eip" "test" { | |
* `instance_tags` - (Optional) A mapping of tags, each pair of which must | ||
exactly match a pair on desired instances. | ||
|
||
* `instance_state_names` - (Optional) A list of instance states that should be applicable to the desired instances. The permitted values are: `pending, running, shutting-down, stopped, stopping, terminated` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should list the default behavior of returning only |
||
|
||
* `filter` - (Optional) One or more name/value pairs to use as filters. There are | ||
several valid keys, for a full reference, check out | ||
[describe-instances in the AWS CLI reference][1]. | ||
|
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.
The enhancement here needs to allow the
instance-state
to either be configurable, while leaving the existing default behavior to not break backwards compatibility. This can be accomplished two ways:Less preferably as a string attribute, but provided as an example, e.g.
Where it is referenced in the code with:
Or, more preferably, as a set so you can configure one or more instance states:
Where it is referenced in the code with:
Either case should implement a new acceptance test that creates two instances and immediately calls the data source that accepts the
pending
(and probablyrunning
as well) instance states.