-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
GCE managed group instances' IPs as output #1246
Comments
So, good news and bad news. Good news: this should be possible when #1906 lands. Use the Bad news: it still won't do what you want. Because managed instance groups are, well, managed, the instances in them are not static. They change over time. This could be from things like autoscaling, it could be from things like an instance getting deleted, it could be from a lot of things. But because the group is managed by Google, not by Terraform, you can't rely on the instances in it remaining static between Terraform runs. This brings a lot of nice benefits! It's a good thing. However, it does mean that Terraform can't be relied upon to do the things you outline in your use cases.
When a new instance comes up, it will not have the code deployed on it, because Terraform doesn't run continuously. So Terraform won't know about it until the next Terraform apply, meaning Jenkins can't deploy the code over SSH until the next apply. At which point, there's no point in using managed instances groups, just use a regular instance group. If you need to deploy code over SSH, a managed instance group is almost certainly not what you want. Managed instance groups should only rely on instance templates to be ready for use.
When an instance gets recreated, for whatever reason, you now have an IP that isn't associated with an instance that has access to your database, and you have an instance that doesn't have access to your database. You probably want to use the CloudSQL proxy. But, as noted in the GCP docs (emphasis mine):
|
I'm going to close this out, as we've released the compute instance data source, so people should be able to string this together by themselves, if they really want to. I'm weakly against adding documentation/an example on how to do it, because I think it's behaviour that should be discouraged. If anyone feels strongly it should be documented, feel free to chime in, and we can reopen the issue. |
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. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Hi there,
Terraform Version
Terraform v0.11.3
Affected Resource(s)
Terraform Configuration Files
Expected Behavior
I would like to be able to discover managed instances IPs via Terraform and expose them as an output.
Use case:
Step 1 - create managed instances with Terraform
Step 2 - run code deploy on them, using Jenkins. Jenkins gets IPs from Terraform's output and uses SSH to connect with them.
Another use case:
Step 1 - create managed instances with Terraform
Step 2 - add instances' IPs to "authorized_networks" on "google_sql_database_instance" resource.
Right now in step 2, we're using gcloud command to discover IPs.
Something like this is possible with AWS, using "aws_instance" data source or "aws_instances" data source.
For GCP, there is no "google_compute_instance" data source. There is however "google_compute_region_instance_group" data source, but it doesn't expose IPs as an attribute.
The text was updated successfully, but these errors were encountered: