Hello
Today I faced with issue that I cant get all information from schema.
I have resource
resource "custom_configuration" "new" {
restart = 0
dashboard_api_access_token = "7099454d2064f8d9c43d316e4ff32f3"
password_enforce_complexity = false
password_lockout_attempts = 0
storage_enabled = true
prefer_local_reads = false
# cloud_boot_enabled = true
cloud_boot_domain_name_servers = var.cp_mgmt
cloud_boot_target = var.cp_mgmt
snmptrap_addresses = var.cp_mgmt
nfs_root_ip = var.cp_mgmt
enforce_redundancy = false
disable_hypervisor_failover = true
}
Also I have function to get all fields from schema to the map. This is test function because previous method also not work.
func createSettings(d *schema.ResourceData) *map[string]interface{} {
res := make(map[string]interface{})
t := reflect.TypeOf(&custom.Configuration{}).Elem()
for i := 0; i < t.NumField(); i++ {
fieldName := jsonTag(t.Field(i))
if attr, ok := d.GetOk(fieldName); ok {
res[fieldName] = attr
log.Printf("CHANGED +++++++++++++++ %s = %+v", fieldName, attr)
}
}
log.Printf("[DEBUG] createSettings +++++ %#v", res)
return &res
}
This function return next output:
CHANGED +++++++++++++++ cloud_boot_domain_name_servers = 192.168.16.5
CHANGED +++++++++++++++ cloud_boot_target = 192.168.16.5
CHANGED +++++++++++++++ dashboard_api_access_token = 7099454d20619b07b943d316e4ff32f3
CHANGED +++++++++++++++ disable_hypervisor_failover = true
CHANGED +++++++++++++++ nfs_root_ip = 192.168.16.5
CHANGED +++++++++++++++ snmptrap_addresses = 192.168.16.5
CHANGED +++++++++++++++ storage_enabled = true
[DEBUG] createSettings map[string]interface {}{"cloud_boot_domain_name_servers":"192.168.16.5", "cloud_boot_target":"192.168.16.5", "dashboard_api_access_token":"7099454d20619b07b943d316e4ff32f3", "disable_hypervisor_failover":true, "nfs_root_ip":"192.168.16.5", "snmptrap_addresses":"192.168.16.5", "storage_enabled":true}
So as we could see, there are not some values from terraform configuration,
password_enforce_complexity = false
password_lockout_attempts = 0
As I understand this is because GetOk function return only non zero, non empty value from resource schema. If I use Get function I of course get all data from resource schema, but I can’t send this data because I overwrite correct values on the resource…
The question is how I can resolve this problem?