Skip to content
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

data_source_aws_instances.go hard coded for instance-state-name running #3339

Closed
Gibby opened this issue Feb 12, 2018 · 8 comments · Fixed by #4950
Closed

data_source_aws_instances.go hard coded for instance-state-name running #3339

Gibby opened this issue Feb 12, 2018 · 8 comments · Fixed by #4950
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@Gibby
Copy link

Gibby commented Feb 12, 2018

Affected Resource(s)

Please list the resources as a list, for example:

  • data_source_aws_instances

We are trying to grab instance id's for instances that are not running for building a maintenance window task using data source of aws_instances, however instance-state-name is hardcoded and filtering on only running instances.

	params := &ec2.DescribeInstancesInput{
		Filters: []*ec2.Filter{
			&ec2.Filter{
				Name:   aws.String("instance-state-name"),
				Values: []*string{aws.String("running")},
			},
		},
	}
@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. new-data-source Introduces a new data source. service/ec2 Issues and PRs that pertain to the ec2 service. and removed new-data-source Introduces a new data source. labels Feb 12, 2018
@Ninir Ninir added the easy label Mar 2, 2018
@radeksimko radeksimko removed the easy label Mar 5, 2018
@radeksimko
Copy link
Member

Hi @Gibby
do you mind explaining the use case you have in mind?

for building a maintenance window task

what kind of maintenance do you plan to build and how do you plan to perform it within the context of Terraform?
Generally speaking if the instance is not running most provisioners won't work.

Thanks.

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Mar 5, 2018
@Gibby
Copy link
Author

Gibby commented Mar 5, 2018

Hi @radeksimko

We have some instances that are only powered on during the week when the developers need them. However we still power them on every Sunday to patch and perform maintenance. To build the maintenance window in terraform we had to hardcode the instance ID's instead of using a tag since the filter is hardcoded for running only. Having it hard coded for running does not follow the documentation which says you can use any filter from the AWS CLI reference.

@radeksimko
Copy link
Member

I'm afraid I still don't fully understand how you perform the maintenance, where presumably the very first operation (as you mentioned) is turning the instance on.

We have some plans to possibly eventually support changing state of the instance through Terraform, but it's a little bit more complex topic, so that is likely going to take some time. Regardless, this is not an option currently available in the provider, so my question is how are you turning these instances on?

Thanks.

@Gibby
Copy link
Author

Gibby commented Mar 12, 2018

There are 2 ways we are starting instances for maintenance managed with our terraform templates. However, we have to hardcode the instance ID's in templates since we can not filter on non-running instances. We have maintenance windows in systems manager that we also manage with terraform templates.

Ways we start instances with terraform:

  1. A lambda script that is triggered by a cloud even rule (managed with terraform)
  2. Automation document in Systems Manager for starting instances (managed with terraform)

@radeksimko
Copy link
Member

I see, so AWS SSM or Lambda does that trick for you, to either of which you'd like to pass IDs dynamically via interpolation in Terraform. That makes sense.

Thanks for all your patience in explaining the use case @Gibby , I think it's worth supporting this and we'd be happy to accept PR.

@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Mar 14, 2018
@bflad bflad added this to the v1.26.0 milestone Jul 4, 2018
@bflad
Copy link
Contributor

bflad commented Jul 4, 2018

In version 1.26.0 of the AWS provider, releasing tonight or tomorrow, the aws_instances data source has been updated to optionally accept a new instance_state_names argument, which defaults to the previous behavior of just running, but also accepts other instance states like stopped as well.

@bflad
Copy link
Contributor

bflad commented Jul 4, 2018

This has been released in version 1.26.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
4 participants