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

CP-49366: Implement xenserver_sr provider data source #15

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

xueqingz
Copy link
Collaborator

Test result:

ubuntu@ubuntu-server:~/code/terraform-provider-xenserver$ make testacc
source .env && TF_ACC=1 go test ./xenserver/ -v   -timeout 120m
=== RUN   TestAccPifDataSource
--- PASS: TestAccPifDataSource (0.73s)
=== RUN   TestAccSRDataSource
--- PASS: TestAccSRDataSource (0.65s)
=== RUN   TestAccVMResource
--- PASS: TestAccVMResource (1.62s)
PASS
ok      terraform-provider-xenserver/xenserver  3.010s

manual test :

ubuntu@ubuntu-server:~/code/terraform-provider-xenserver/examples/terraform-main$ terraform apply -auto-approve
╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - xenserver/xenserver in /home/ubuntu/go/bin
│ 
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
data.xenserver_sr.sr: Reading...
data.xenserver_sr.sr: Read complete after 0s

Changes to Outputs:
  + local_storage_output = [
      + {
          + allowed_operations   = [
              + "vdi_enable_cbt",
              + "vdi_list_changed_blocks",
              + "unplug",
              + "plug",
              + "pbd_create",
              + "vdi_disable_cbt",
              + "update",
              + "pbd_destroy",
              + "vdi_resize",
              + "vdi_clone",
              + "vdi_data_destroy",
              + "scan",
              + "vdi_snapshot",
              + "vdi_mirror",
              + "vdi_create",
              + "vdi_destroy",
              + "vdi_set_on_boot",
            ]
          + blobs                = {}
          + clustered            = false
          + content_type         = "user"
          + current_operations   = {}
          + introduced_by        = "OpaqueRef:NULL"
          + is_tools_sr          = false
          + local_cache_enabled  = false
          + name_description     = "Local storage on perfuk-18-06d"
          + name_label           = "Local storage"
          + other_config         = {
              + i18n-key                       = "local-storage"
              + i18n-original-value-name_label = "Local storage"
            }
          + pbds                 = [
              + "OpaqueRef:0af6c800-c6e2-f972-e7b7-bac8369ab52e",
            ]
          + physical_size        = 434982879232
          + physical_utilisation = 4194304
          + shared               = false
          + sm_config            = {
              + allocation = "thick"
              + devserial  = "scsi-364cd98f06b051c00247a5e94c99665c2"
              + use_vhd    = "true"
            }
          + tags                 = []
          + type                 = "lvm"
          + uuid                 = "e1c42b2b-ab3b-fef6-b2cb-741870a12978"
          + vdis                 = []
          + virtual_allocation   = 0
        },
    ]

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

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

local_storage_output = tolist([
  {
    "allowed_operations" = tolist([
      "vdi_enable_cbt",
      "vdi_list_changed_blocks",
      "unplug",
      "plug",
      "pbd_create",
      "vdi_disable_cbt",
      "update",
      "pbd_destroy",
      "vdi_resize",
      "vdi_clone",
      "vdi_data_destroy",
      "scan",
      "vdi_snapshot",
      "vdi_mirror",
      "vdi_create",
      "vdi_destroy",
      "vdi_set_on_boot",
    ])
    "blobs" = tomap({})
    "clustered" = false
    "content_type" = "user"
    "current_operations" = tomap({})
    "introduced_by" = "OpaqueRef:NULL"
    "is_tools_sr" = false
    "local_cache_enabled" = false
    "name_description" = "Local storage on perfuk-18-06d"
    "name_label" = "Local storage"
    "other_config" = tomap({
      "i18n-key" = "local-storage"
      "i18n-original-value-name_label" = "Local storage"
    })
    "pbds" = tolist([
      "OpaqueRef:0af6c800-c6e2-f972-e7b7-bac8369ab52e",
    ])
    "physical_size" = 434982879232
    "physical_utilisation" = 4194304
    "shared" = false
    "sm_config" = tomap({
      "allocation" = "thick"
      "devserial" = "scsi-364cd98f06b051c00247a5e94c99665c2"
      "use_vhd" = "true"
    })
    "tags" = tolist([])
    "type" = "lvm"
    "uuid" = "e1c42b2b-ab3b-fef6-b2cb-741870a12978"
    "vdis" = tolist([])
    "virtual_allocation" = 0
  },
])

Signed-off-by: xueqingz <[email protected]>
@xueqingz
Copy link
Collaborator Author

test result :

ubuntu@ubuntu-server:~/code/terraform-provider-xenserver$ make testacc
source .env && TF_ACC=1 go test ./xenserver/ -v   -timeout 120m
=== RUN   TestAccPifDataSource
--- PASS: TestAccPifDataSource (0.70s)
=== RUN   TestAccSRDataSource
--- PASS: TestAccSRDataSource (0.65s)
=== RUN   TestAccVMResource
--- PASS: TestAccVMResource (1.89s)
PASS
ok      terraform-provider-xenserver/xenserver  3.256s
ubuntu@ubuntu-server:~/code/terraform-provider-xenserver/examples/terraform-main$ terraform apply -auto-approve
╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - xenserver/xenserver in /home/ubuntu/go/bin
│ 
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
xenserver_vm.vm: Refreshing state... [id=2c7a179c-d1ed-d6ab-4e2e-2902ef28933d]
data.xenserver_pif.pif_data: Reading...
data.xenserver_sr.sr: Reading...
data.xenserver_pif.pif_data: Read complete after 0s
data.xenserver_sr.sr: Read complete after 0s

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # xenserver_vm.vm will be updated in-place
  ~ resource "xenserver_vm" "vm" {
        id            = "2c7a179c-d1ed-d6ab-4e2e-2902ef28933d"
      ~ name_label    = "Test CentOS VM" -> "Test CentOS VM1"
      ~ snapshots     = [] -> (known after apply)
        # (2 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Changes to Outputs:
  ~ vm_out               = {
        id            = "2c7a179c-d1ed-d6ab-4e2e-2902ef28933d"
      ~ name_label    = "Test CentOS VM" -> "Test CentOS VM1"
      ~ snapshots     = [] -> (known after apply)
        # (2 unchanged attributes hidden)
    }
xenserver_vm.vm: Modifying... [id=2c7a179c-d1ed-d6ab-4e2e-2902ef28933d]
xenserver_vm.vm: Modifications complete after 0s [id=2c7a179c-d1ed-d6ab-4e2e-2902ef28933d]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Outputs:

local_storage_output = tolist([
  {
    "allowed_operations" = tolist([
      "vdi_enable_cbt",
      "vdi_list_changed_blocks",
      "unplug",
      "plug",
      "pbd_create",
      "vdi_disable_cbt",
      "update",
      "pbd_destroy",
      "vdi_resize",
      "vdi_clone",
      "vdi_data_destroy",
      "scan",
      "vdi_snapshot",
      "vdi_mirror",
      "vdi_create",
      "vdi_destroy",
      "vdi_set_on_boot",
    ])
    "blobs" = tomap({})
    "clustered" = false
    "content_type" = "user"
    "current_operations" = tomap({})
    "introduced_by" = "OpaqueRef:NULL"
    "is_tools_sr" = false
    "local_cache_enabled" = false
    "name_description" = "Local storage on perfuk-18-06d"
    "name_label" = "Local storage"
    "other_config" = tomap({
      "i18n-key" = "local-storage"
      "i18n-original-value-name_label" = "Local storage"
    })
    "pbds" = tolist([
      "OpaqueRef:0af6c800-c6e2-f972-e7b7-bac8369ab52e",
    ])
    "physical_size" = 434982879232
    "physical_utilisation" = 4194304
    "shared" = false
    "sm_config" = tomap({
      "allocation" = "thick"
      "devserial" = "scsi-364cd98f06b051c00247a5e94c99665c2"
      "use_vhd" = "true"
    })
    "tags" = tolist([])
    "type" = "lvm"
    "uuid" = "e1c42b2b-ab3b-fef6-b2cb-741870a12978"
    "vdis" = tolist([])
    "virtual_allocation" = 0
  },
])
pif_data_out = {
  "device" = "eth0"
  "management" = true
  "network" = "ea0e0fb4-6c5f-9728-2c2a-913ffe20e7d6"
}
vm_out = {
  "id" = "2c7a179c-d1ed-d6ab-4e2e-2902ef28933d"
  "name_label" = "Test CentOS VM1"
  "other_config" = tomap({
    "flag" = "1"
  })
  "snapshots" = tolist([])
  "template_name" = "CentOS 7"
}

if err != nil {
resp.Diagnostics.AddError(
"Error update data",
"Unable to update VM resource model computed fields",
Copy link
Member

Choose a reason for hiding this comment

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

-> Unable to update the computed fields of VM resource model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok , will update in follow PR.

@xueqingz xueqingz merged commit 7054b64 into xenserver:master Jun 12, 2024
2 checks passed
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.

3 participants