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

feat(instance): add instance_servers data source #1264

Merged
merged 15 commits into from
Jun 7, 2022

Conversation

Codelax
Copy link
Member

@Codelax Codelax commented May 6, 2022

This is an example of how plural datasources could be done and used.

It is used as

data scaleway_instance_servers "plural" {
  tags = ["mytag"]
}

resource scaleway_lb_backend "backend" {
  server_ips       = data.scaleway_instance_servers.plural.servers[*].public_ip
}

Currently public_ip is being put in schema and it would require to expand schema to expose more informations.
But we can still get all missing informations by using singular datasource after the plural one.

data scaleway_instance_servers "plural" {
  tags = ["yes"]
}

data scaleway_instance_server "singular" {
  for_each = {for server in data.scaleway_instance_servers.plural.servers: server.id => server}
  server_id = each.value.id
}

resource scaleway_lb_backend "backend" {
  server_ips       = values(data.scaleway_instance_server.singular)[*].public_ip
}

Using both datasource allow to get all informations while style filtering across all resources. It would be a great improvement while limiting the amount of code required.

@codecov-commenter
Copy link

codecov-commenter commented May 6, 2022

Codecov Report

Merging #1264 (c1afba6) into master (3d6bf9c) will increase coverage by 0.12%.
The diff coverage is 82.02%.

@@            Coverage Diff             @@
##           master    #1264      +/-   ##
==========================================
+ Coverage   70.19%   70.31%   +0.12%     
==========================================
  Files         102      103       +1     
  Lines       16451    16629     +178     
==========================================
+ Hits        11547    11693     +146     
- Misses       3923     3947      +24     
- Partials      981      989       +8     
Impacted Files Coverage Δ
scaleway/data_source_instance_servers.go 81.92% <81.92%> (ø)
scaleway/provider.go 73.39% <100.00%> (+0.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d6bf9c...c1afba6. Read the comment docs.

@Codelax Codelax force-pushed the servers_datasource branch from 9ba35e1 to 8adb94f Compare May 6, 2022 15:34
@Codelax Codelax marked this pull request as ready for review May 31, 2022 12:38
@Codelax Codelax requested a review from Monitob June 1, 2022 12:56
@remyleone remyleone merged commit 6e4aa8d into scaleway:master Jun 7, 2022
remyleone added a commit to remyleone/terraform-provider-scaleway that referenced this pull request Jun 17, 2022
@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
instance Instance issues, bugs and feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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