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

Add an example to put all instances that got a given tag in a certain scaleway lb backend #762

Closed
remyleone opened this issue Jan 19, 2021 · 2 comments · Fixed by #1264
Closed
Assignees
Labels
documentation enhancement instance Instance issues, bugs and feature requests load-balancer Load-balancer issues, bugs and feature requests
Milestone

Comments

@remyleone
Copy link
Member

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

New or Affected Resource(s)

  • scaleway_XXXXX

Potential Terraform Configuration

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.

References

  • #0000
@remyleone remyleone added documentation load-balancer Load-balancer issues, bugs and feature requests labels Apr 27, 2021
@meroupatate
Copy link

Hi!

Do you already have an idea on how the example should get the list of instances with a specific tag?

I thought about two possibilities:

  • The first one would be if we only want to get the instances created in the same state as the lb backend, then i thought that something like this could be done:
resource "scaleway_lb_backend" "web" {
  (...)
  server_ips = [ for instance in scaleway_instance_server.* : instance.private_ip if contains(instance.tags, "xxxx")]
}

However it seems like terraform doesn't allow looping through all resources of a specific type using a wildcard like this scaleway_instance_server.*, and i feel like it wouldn't make much sense anyway to filter the instances by tags if they already can be selected using their name when they are created in the same module as the lb backend.

  • The other possibility would be if the idea behind this issue is to get all the existing instances with a specific tag. In this case, i believe it would require getting this list of instances using a data source.
    However, the scaleway_instance_server only gets information for a single instance and not multiple ones. I think it would be useful for this issue to have a data source that would get the list of instances that matches a specific filter (tags in this case)

I saw that the idea for a scaleway_instances data source has already been mentioned in #311, the answer given at the time was to use for_each loop, which won't serve our use case here (if i understood it correctly). Wouldn't the implementation of such a data source be required in this case? or maybe is there another way to filter the instances with a specific tag?

@Monitob Monitob added this to the v2.3.0 milestone Jan 4, 2022
@Codelax Codelax self-assigned this May 5, 2022
@Codelax
Copy link
Member

Codelax commented May 6, 2022

Hello,

I looked into this issue and came up with different ways.
As stated, the way to do it with external resources would be a new data source scaleway_instances or scaleway_instance_servers that allow to filter multiple instances.
This start the question of plural datasources that would allow users to fetch multiple resources using filters.

It could be as

data scaleway_instance_servers "servers" {
  tags = ["tag"]
}

resource scaleway_lb_backend "backend" {
  server_ips = data.scaleway_instance_servers.servers.public_ips
}

Those instances could also be managed with terraform, an example:

locals {
  server_count = 3
}

resource scaleway_instance_ip "server_ips" {
  count = local.server_count
}

resource scaleway_instance_server "servers" {
  count = local.server_count
  name = "server${count.index}"
  ip_id = scaleway_instance_ip.server_ips[count.index].id
}

resource scaleway_lb_backend "backend" {
  lb_id            = scaleway_lb.base.id
  name             = "backend01"
  forward_protocol = "http"
  forward_port     = "80"
  server_ips = scaleway_instance_ip.server_ips[*].address
}

@Codelax Codelax removed their assignment May 6, 2022
@Codelax Codelax self-assigned this May 31, 2022
@remyleone remyleone linked a pull request Jun 1, 2022 that will close this issue
@remyleone remyleone added the instance Instance issues, bugs and feature requests label Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation enhancement instance Instance issues, bugs and feature requests load-balancer Load-balancer issues, bugs and feature requests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants