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 compute limits as a data source #1418

Merged

Conversation

ba-work
Copy link
Contributor

@ba-work ba-work commented Jul 27, 2022

This address my comment in #1289

Tested on a real OpenStack

openstack command:

$ o limits show --absolute --project 16c91b6234df4cebabbe704b4a6f2083
+--------------------------+-------+
| Name                     | Value |
+--------------------------+-------+
| maxServerMeta            |   128 |
| maxPersonality           |     5 |
| totalServerGroupsUsed    |     0 |
| maxImageMeta             |   128 |
| maxPersonalitySize       | 10240 |
| maxTotalKeypairs         |   100 |
| maxSecurityGroupRules    |    20 |
| maxServerGroups          |    10 |
| totalCoresUsed           |     8 |
| totalRAMUsed             | 16384 |
| totalInstancesUsed       |     3 |
| maxSecurityGroups        |    10 |
| totalFloatingIpsUsed     |     0 |
| maxTotalCores            |    20 |
| maxServerGroupMembers    |    10 |
| maxTotalFloatingIps      |    10 |
| totalSecurityGroupsUsed  |     1 |
| maxTotalInstances        |    10 |
| maxTotalRAMSize          | 51200 |
| totalSnapshotsUsed       |     0 |
| maxTotalBackups          |    50 |
| maxTotalVolumeGigabytes  |  1500 |
| maxTotalSnapshots        |    10 |
| maxTotalBackupGigabytes  |     0 |
| totalBackupGigabytesUsed |     0 |
| maxTotalVolumes          |   100 |
| totalVolumesUsed         |    35 |
| totalBackupsUsed         |     0 |
| totalGigabytesUsed       |  1238 |
+--------------------------+-------+

and tf:

brock@micro:~/os-test$ cat main.tf && tf plan
terraform {
  required_providers {
    openstack = {
      version = "0.1"
      source  = "registry.terraform.io/terraform-provider-openstack/openstack"
    }
  }
}
provider "openstack" { insecure = true }
data "openstack_compute_limits_v2" "source" { project_id = "16c91b6234df4cebabbe704b4a6f2083" }
output "info" { value = data.openstack_compute_limits_v2.source }

Changes to Outputs:
  + info = {
      + id                         = "16c91b6234df4cebabbe704b4a6f2083/regionOne"
      + max_image_meta             = 128
      + max_personality            = 5
      + max_personality_size       = 10240
      + max_security_group_rules   = 20
      + max_security_groups        = 10
      + max_server_group_members   = 10
      + max_server_groups          = 10
      + max_server_meta            = 128
      + max_total_cores            = 20
      + max_total_floating_ips     = 10
      + max_total_instances        = 10
      + max_total_keypairs         = 100
      + max_total_ram_size         = 51200
      + project_id                 = "16c91b6234df4cebabbe704b4a6f2083"
      + total_cores_used           = 8
      + total_floating_ips_used    = 0
      + total_instances_used       = 3
      + total_ram_used             = 16384
      + total_security_groups_used = 1
      + total_server_groups_used   = 0
    }

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run
"terraform apply" now.

I basically just copied the conventions in #1302, #1318, and #1319

This allows you to use data source custom conditions to make sure the target project has enough available quota for whatever you are about to deploy.

@ba-work ba-work requested a review from nikParasyr July 28, 2022 12:52
Copy link
Member

@nikParasyr nikParasyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works. Thank you for picking it up :)

@nikParasyr nikParasyr merged commit e35b6fb into terraform-provider-openstack:main Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants