-
Notifications
You must be signed in to change notification settings - Fork 46
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: implement data element for block devices #200
feat: implement data element for block devices #200
Conversation
9037370
to
08fd21e
Compare
utility-wise, now we can do things like: locals {
disk_names = ["sda", "sdb", "sdc", "sdd", "sde", "sdf", "sdg", "sdf"]
disk_map_1 = distinct(flatten(([
for disk_name in local.disk_names : [
for machine in openstack_compute_instance_v2.metal-1 : {
disk = disk_name
machine = machine.name
}
]
])))
}
data "maas_block_device" "metal-1" {
for_each = { for entry in local.disk_map_1: "${entry.machine}.${entry.disk}" => entry }
name = each.value.disk
machine = each.value.machine
}
resource "maas_block_device" "metal-1-sda" {
for_each = { for k,v in data.maas_block_device.metal-1: k => v if v.name == "sda" }
machine = each.value.machine
name = "sda"
id_path = each.value.id_path
size_gigabytes = 64
tags = [
"os_drive",
]
partitions {
size_gigabytes = 32
fs_type = "ext4"
label = "os"
mount_point = "/"
}
partitions {
size_gigabytes = 1
fs_type = "fat32"
mount_point = "/boot"
}
}
resource "maas_block_device" "metal-1-data" {
for_each = { for k,v in data.maas_block_device.metal-1: k => v if v.size_gigabytes == 128 && v.name == "sda" }
machine = each.value.machine
name = each.value.name
id_path = each.value.id_path
size_gigabytes = 1
tags = [
"data_drive",
]
partitions {
size_gigabytes = 128
fs_type = "xfs"
label = "data"
}
} which on just 4 machines produce: OpenTofu will perform the following actions:
# maas_block_device.metal-1-data["test-metal1-00.sdb"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_3c0f9f80-014d-4f9e-8d37-37cc57911ea9"
+ machine = "fwtq6w"
+ model = (known after apply)
+ name = "sdb"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-00.sdc"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_f53c08da-8c39-4112-8610-0a1c0a9f581b"
+ machine = "fwtq6w"
+ model = (known after apply)
+ name = "sdc"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-00.sdd"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_668d5958-6c8a-4342-a2d5-999731e81723"
+ machine = "fwtq6w"
+ model = (known after apply)
+ name = "sdd"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-00.sde"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_552ce1f9-ebf7-43d2-95fc-3a8f06599dcd"
+ machine = "fwtq6w"
+ model = (known after apply)
+ name = "sde"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-00.sdf"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_19e99891-e4d5-4ba0-b8f6-12e3eb5f295f"
+ machine = "fwtq6w"
+ model = (known after apply)
+ name = "sdf"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-01.sdb"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_170dae87-3e3e-41fd-8d29-72333bce542f"
+ machine = "ssmxyw"
+ model = (known after apply)
+ name = "sdb"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-01.sdc"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_ffe27ee5-dd48-45cf-b9b8-0cd3e3e564cc"
+ machine = "ssmxyw"
+ model = (known after apply)
+ name = "sdc"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-01.sdd"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_9610c723-b078-4ca1-93d7-97bdadc51bdb"
+ machine = "ssmxyw"
+ model = (known after apply)
+ name = "sdd"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-01.sde"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_8c9ad6ea-df74-43a4-9c7a-a4ed2c910822"
+ machine = "ssmxyw"
+ model = (known after apply)
+ name = "sde"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-01.sdf"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_69216d51-5636-47a3-98ce-0bd7b925d138"
+ machine = "ssmxyw"
+ model = (known after apply)
+ name = "sdf"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-02.sdb"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_e21ffede-7c38-4f3d-903c-60f23dde86ce"
+ machine = "kherdk"
+ model = (known after apply)
+ name = "sdb"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-02.sdc"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_d4ecbad3-afa2-4edd-b7d7-6ed635e14413"
+ machine = "kherdk"
+ model = (known after apply)
+ name = "sdc"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-02.sdd"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_e5f412a5-5c55-4b18-bf40-c7fa844b1b59"
+ machine = "kherdk"
+ model = (known after apply)
+ name = "sdd"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-02.sde"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_539dc79e-2909-484a-9837-805c33c2dba0"
+ machine = "kherdk"
+ model = (known after apply)
+ name = "sde"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-02.sdf"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_e78a0ed7-b6ca-4cf9-8ef6-3e7d1bc7b5e4"
+ machine = "kherdk"
+ model = (known after apply)
+ name = "sdf"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-03.sdb"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_5a992add-e46f-4e94-9ddc-44a819f40f7f"
+ machine = "yxsy7e"
+ model = (known after apply)
+ name = "sdb"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-03.sdc"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_eb51d787-6df8-4b40-98e8-663a23b265b1"
+ machine = "yxsy7e"
+ model = (known after apply)
+ name = "sdc"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-03.sdd"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_1dd2bab7-26b3-4f0a-a23e-5a435dfddd29"
+ machine = "yxsy7e"
+ model = (known after apply)
+ name = "sdd"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-03.sde"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_81063dc4-ef55-4964-a8b1-fe8d7f778309"
+ machine = "yxsy7e"
+ model = (known after apply)
+ name = "sde"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-data["test-metal1-03.sdf"] will be created
+ resource "maas_block_device" "metal-1-data" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_a74b3c68-f468-462a-8e0e-884c4e0f0b0c"
+ machine = "yxsy7e"
+ model = (known after apply)
+ name = "sdf"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 1
+ tags = [
+ "data_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "xfs"
+ label = "data"
+ path = (known after apply)
+ size_gigabytes = 128
}
}
# maas_block_device.metal-1-sda["test-metal1-00.sda"] will be created
+ resource "maas_block_device" "metal-1-sda" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_ef57b0e9-646c-479b-9565-485e9bc6842d"
+ machine = "fwtq6w"
+ model = (known after apply)
+ name = "sda"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 64
+ tags = [
+ "os_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "ext4"
+ label = "os"
+ mount_point = "/"
+ path = (known after apply)
+ size_gigabytes = 32
}
+ partitions {
+ fs_type = "fat32"
+ mount_point = "/boot"
+ path = (known after apply)
+ size_gigabytes = 1
}
}
# maas_block_device.metal-1-sda["test-metal1-01.sda"] will be created
+ resource "maas_block_device" "metal-1-sda" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_e74258a3-e454-46cc-b54e-5a375fdbc1e8"
+ machine = "ssmxyw"
+ model = (known after apply)
+ name = "sda"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 64
+ tags = [
+ "os_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "ext4"
+ label = "os"
+ mount_point = "/"
+ path = (known after apply)
+ size_gigabytes = 32
}
+ partitions {
+ fs_type = "fat32"
+ mount_point = "/boot"
+ path = (known after apply)
+ size_gigabytes = 1
}
}
# maas_block_device.metal-1-sda["test-metal1-02.sda"] will be created
+ resource "maas_block_device" "metal-1-sda" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_f4b1f935-b88a-45e0-81a1-d386a87da8b0"
+ machine = "kherdk"
+ model = (known after apply)
+ name = "sda"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 64
+ tags = [
+ "os_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "ext4"
+ label = "os"
+ mount_point = "/"
+ path = (known after apply)
+ size_gigabytes = 32
}
+ partitions {
+ fs_type = "fat32"
+ mount_point = "/boot"
+ path = (known after apply)
+ size_gigabytes = 1
}
}
# maas_block_device.metal-1-sda["test-metal1-03.sda"] will be created
+ resource "maas_block_device" "metal-1-sda" {
+ block_size = 512
+ id = (known after apply)
+ id_path = "/dev/disk/by-id/scsi-SQEMU_QEMU_HARDDISK_5d5de7e6-d88a-4d95-ac26-b014132eca33"
+ machine = "yxsy7e"
+ model = (known after apply)
+ name = "sda"
+ path = (known after apply)
+ serial = (known after apply)
+ size_gigabytes = 64
+ tags = [
+ "os_drive",
]
+ uuid = (known after apply)
+ partitions {
+ fs_type = "ext4"
+ label = "os"
+ mount_point = "/"
+ path = (known after apply)
+ size_gigabytes = 32
}
+ partitions {
+ fs_type = "fat32"
+ mount_point = "/boot"
+ path = (known after apply)
+ size_gigabytes = 1
}
} |
Copy and trim the block device resource code to act as data for dynamic dispatch of configuration assignments from the attributes retrieved. Update logic to handle finding disks by name. Testing: Internal lab in conjunction with OpenStack provider/environment. TODO: Update documentation Pass upstream review for merge
da77367
to
5520033
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sempervictus. Thank you for the contribution. Let's take a look of what is missing to get it merged:
- Please take care of the inline comment/suggestions
- Please run
go fmt ./...
to make the linter happy - Please sign the Canonical CLA so that our CI check is happy. You can start from this page: https://ubuntu.com/legal/contributors
- Please add acceptance tests. Tests will use terraform data source to fetch a block device from MAAS and also confirm that the fields are populated with expected values.
maas/data_source_maas_resource_pool_test.go
is a good source for inspiration. If you face any problem, I can always add a skeleton in your PR so that you can finalize it. Please let me know 🙂
Once again, thank you very much for your time and the contribution spirit 🍺
## Example Usage | ||
|
||
```hcl | ||
data "maas_block_device" "metal-1" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the embedded Terraform on this doc file should be moved into a new file under the path examples/data-sources/maas_block_device/data-source.tf
. Afterwards, make generate_docs
will do the job to fetch it into the autogenerated markdown. Please give it a try 🙂
@@ -0,0 +1,160 @@ | |||
package maas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the file should be changes from data_source_maas_block_revice.go
to data_source_maas_block_device.go
Thank you for the review and rmedy @skatsaounis Co-authored-by: Stamatis Katsaounis <[email protected]>
51b5026
to
26d6111
Compare
Thank you very much, applied and credited accordingly. Far as CLA's go: NO. I am getting sick of repeating this on every GH repo which wants to commercialize code: i hold patent rights and fiduciary responsibility to protect them with further inventions not yet patented; therefore, on the costly advice of corporate counsel, cannot sign any such waivers of intellectual property rights without legal review. If Canonical would like to compensate the cost of said review and my time (i'm a security architect of ~30y running several companies, you can play "guess my rate" until you are reasonably queasy), by all means. Otherwise, please take the free work and use it with the rest of the code-base. |
Signing the CLA is mandatory for contributing to Canonical's open source projects (see here). |
@sempervictus please have a look at https://ubuntu.com/legal/contributors and https://ubuntu.com/legal/contributors/faq - we ask for CLA to be able to use and distribute your solution, while you retain the copyright. And if you own any patents on the code you contribute, the CLA grants us license to use these inventions. If you change your mind about signing the CLA, your contributions are welcome. |
Hi @sempervictus I just realised that you mentioned me as a co-author of this commit: 0f4dfd2. Could you please remove this as being inaccurate and due to the fact that it was added without my acknowledge? I didn't commit the changes. Instead, within my review, I proposed to remove the parts of description of the fields that was implying to the users that they need to set the fields. On data sources, nothing is set apart from the resource ID. Everything else is always computed. My contribution is just the review suggestion which is credited accordingly by GitHub itself without the need to reflect it in the upcoming commit. Thank you in advance for the removal of my inaccurate co-authorship. |
Copy and trim the block device resource code to act as data for dynamic dispatch of configuration assignments from the attributes retrieved. Update logic to handle finding disks by name.
Testing:
Internal lab in conjunction with OpenStack provider/environment.
TODO:
Update documentation
Pass upstream review for merge