Closed dimi4ik closed 8 months ago
Hi @dimi4ik ,
There are a couple of things that might have gone wrong in your process:
terraform apply
instead of terraform import
. Since the catalog already exist, you will eventually get an error complaining about catalog name conflict.provisioning_scheme.machine_config.service_offering
field in your terraform, as suggested in the documentation: https://registry.terraform.io/providers/citrix/citrix/latest/docs/resources/daas_machine_catalog#service_offering.
However, we understand that the existing documentation is quite cumbersome to understand as there are a lot of fields shared across multiple hypervisors that have different semantic meaning according to the context. There is an upcoming release to address this problem and hopefully make the user experience smoother. Please let me know if you are able to import your catalog once you try the above solution.
Thank you.
Hello @zhuolun-citrix 👍 and thank you for your reply,
perhaps I did not write down correctly what I did and would like to explain it again in more detail:
resource "citrix_daas_machine_catalog" "mc" {
}
terraform import citrix_daas_machine_catalog.mc xxxxxx-406d-b1a3-xxxxxxxx
Terraform Import, and here is the output of it.
citrix_daas_machine_catalog.mc: Import prepared!
Prepared citrix_daas_machine_catalog for import
citrix_daas_machine_catalog.mc: Refreshing state... [id=xxxxxx-406d-b1a3-xxxxxxxx]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
I then read the information from the local terraform state terraform state show citrix_daas_machine_catalog.mc and entered it into the existing terraform file.
With the Terraform plan, I received the following output.
│ Error: Incorrect attribute value type
│
│ on 06_machine_catalog_import.tf line 7, in resource "citrix_daas_machine_catalog" "mc":
│ provisioning_scheme = {
│ availability_zones = ""
│ machine_account_creation_rules = {
│ domain = "xxxx.de"
│ domain_ou = "OU=HSD,DC=muster,DC=com"
│ naming_scheme = "xxx0010500##"
│ naming_scheme_type = "Numeric"
│ }
│ machine_config = {
│ hypervisor = "xxxxxx-4710-4c58-add8-xxxxxx"
│ hypervisor_resource_pool = "xxxxxx-a2e4a6e-5a7a-4429-b950-xxxxxxx"
│ machine_profile = "xxx001050000"
│ master_image = "xxx001050000_OsDisk_1_xxxxxxxxxxxxxxxx"
│ resource_group = "rg-ctx-prod-xx-m001"
│ }
│ number_of_total_machines = 1
│ storage_type = "StandardSSD_LRS"
│ use_managed_disks = true
│ }
│
│ Inappropriate value for attribute "provisioning_scheme": attribute "machine_config": attributes "service_account" and "service_account_password" are required.
machine_config = {
│ hypervisor = "xxxxxx-4710-4c58-add8-xxxxxx"
│ hypervisor_resource_pool = "xxxxxx-a2e4a6e-5a7a-4429-b950-xxxxxxx"
│ machine_profile = "xxx001050000"
│ master_image = "xxx001050000_OsDisk_1_xxxxxxxxxxxxxxxx"
│ resource_group = "rg-ctx-prod-xx-m001"
NEW service_account = "azureuser"
NEW service_account_password = "xxxxx"
**Plan: 0 to add, 2 to change, 0 to destroy**.
│ Error: Error updating Resource Pool xxxxxxxxxxxxxxx
│
│ with citrix_daas_azure_hypervisor_resource_pool.resource_pool,
│ on 05_hypervisor.tf line 12, in resource "citrix_daas_azure_hypervisor_resource_pool" "resource_pool":
│ 12: resource "citrix_daas_azure_hypervisor_resource_pool" "resource_pool" {
│
│ TransactionId: e1dd07fc-eef9-4e72-9994-006079cd3999
│ JobId: 13f61dd1-4b21-496d-9642-6b79560b7471
│ Error message: Cannot rename Hosting Unit. An object with the same name already exists.
╵
╷
│ Error: Error updating Machine Catalog
│
│ with citrix_daas_machine_catalog.mc,
│ on 06_machine_catalog_import.tf line 1, in resource "citrix_daas_machine_catalog" "mc":
│ 1: resource "citrix_daas_machine_catalog" "mc" {
│
│ Failed to resolve service offering on Azure, error: could not find resource
If I want to retrieve the information from the terraform state with the command
terraform state rm citrix_daas_machine_catalog.mc
and create a new TF file with a different name for the machine catalog, I think the new MC should be created. Therefore, I think the error lies with Terraform Import.
I actually want to create a new MC catalog with Terraform, and unfortunately I cannot. The examples in the repository are not usable for me, because I don't have a VHDX file on the Azure Storage account. Instead, I have a master MCS VM.
Can you please either review Terraform Import or give me an example of how I can create a MC catalog?
Just FYI, I was able to do this with the old provider version. 💯
Thanks Dima
Hi @dimi4ik ,
There are some nuances that lies within terraform provider framework design and terraform in general about import. What terraform import does is a best effort attempt to first read the resource from remote, and then map it to the schema model. Unfortunately due to the special use cases, there will be certain fields that could not be imported.
I would strongly advice not using the result of terraform import
+ terraform show
as is to get the terraform from an existing resource. You can of course use the result as an example, but you will also need to inspect terraform and cross reference the documentation to make sure that all fields mandatory for your use case (which is Azure MCS in this case) are presented.
We will have a new release soon that introduces some breaking change to improve the schema validation and documentation of our provider. I believe that the change will also help smoothen the experience you get with terraform import
+ terraform show
for reverse engineering a TF for the existing env. In fact, we also have this automated on our side, but yet to be released. Please stay tuned to the future release.
From the error message your shared in the comment, I saw that there were two issues:
service_offering
specified in your TF, while service_offering
is a mandatory field for Azure MCS.From the following comment:
I actually want to create a new MC catalog with Terraform, and unfortunately I cannot. The examples in the repository are not usable for me, because I don't have a VHDX file on the Azure Storage account. Instead, I have a master MCS VM.
I assume that your were trying to use a VM's managed disk / snapshot as the image of the machine catalog. In that case, you don't have to specify storage_account
or container
. Simply specify the resource_group
that contains the VM snapshot / managed disk, and the name of the snapshot / managed disk in master_image
as suggested in the doc:
https://registry.terraform.io/providers/citrix/citrix/latest/docs/resources/daas_machine_catalog#master_image
So your machine_config
will be:
machine_config = { hypervisor = "xxxxxx-4710-4c58-add8-xxxxxx" hypervisor_resource_pool = "xxxxxx-a2e4a6e-5a7a-4429-b950-xxxxxxx" service_offering = "Standard_D2_v2" master_image = "xxx001050000_OsDisk_1_xxxxxxxxxxxxxxxx" resource_group = "rg-ctx-prod-xx-m001" }
@zhuolun-citrix Thank you for your comment. 👍 As you described, I tried to create an MC, but unfortunately without success. Now I am waiting for the new version of Terraform, then I will try again and test it. 🥇
In fact, we also have this automated on our side, but yet to be released. Please stay tuned to the future release.
It's released now! This script can import your existing resources and create the TF files: https://github.com/citrix/terraform-provider-citrix/tree/main/scripts/onboarding-helper
Terraform Core Version
he semantic version of Terraform Core used when experiencing the bug. If multiple versions have been tested, a comma separated list.
Terraform v1.5.6 on linux_amd64
provider registry.terraform.io/citrix/citrix v0.3.6 provider registry.terraform.io/hashicorp/azurerm v3.87.0 provider registry.terraform.io/hashicorp/random v3.6.0
Description
I want to import a manually created machine catalog using Terraform and I get an error:
error: Error updating Machine Catalog │ │ with citrix_daas_machine_catalog.mc, │ on 06_machine_catalog_import_case.tf line 2, in resource "citrix_daas_machine_catalog" "mc": │ 2: resource "citrix_daas_machine_catalog" "mc" { │ │ Failed to resolve service offering on Azure, error: could not find resource
for me it is very interesting that terraform plan runs without errors, but terraform apply throws an error
If you need further logs/data from me, please send me a PM
Affected Resource(s) Please list the affected resource(s) and/or data source(s). ==============================
citrix_daas_machine_catalog
Expected Behavior What should have happened?
Import machine catalog with Terraform
Relevant Error/Panic Output Snippet If applicable, provide a relevant snippet from the error or panic output. This will be rendered as shell, so there is no need to add a
error: Error updating Machine Catalog │ │ with citrix_daas_machine_catalog.mc, │ on 06_machine_catalog_import_case.tf line 2, in resource "citrix_daas_machine_catalog" "mc": │ 2: resource "citrix_daas_machine_catalog" "mc" { │ │ Failed to resolve service offering on Azure, error: could not find resource
Terraform Configuration Files ===========================
here is the code, I want to import the machine catalog with terraform: the code was extracted from the terraform state file and written to a tf file