You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
resource"cads_application""app1" {
service_profiles {
name ="a3sp"lb {
name ="lbsp"lb_params {
algorithm ="ROUND_ROBIN"
stickiness_type ="SOURCE_IP"# max_server_connections = 1
}
}
}
Debug Output
Expected Behavior
I am writing a custom terraform provider. I need to read the above configuration.
I have written schema in such a way that lb and lb_params are of TypeList with MaxItems=1.
If I do not pass max_server_connections under lb_params in config (.tf file), the terraform SDK is sending max_server_connections=0 in payload.
I do not need this in my payload if it’s not present in the config.
How can I achieve it?
Even though I tried to use the below if block for max_server_connections, I see the max_server_connections in the payload.
Create function snippet
// service_profiles is just like network_functionsifservice_profiles, ok:=d.GetOk("service_profiles"); ok {
serviceProfilesList:=make([]interface{}, 0)
sp:=make(map[string]interface{})
for_, v:=rangeservice_profiles.([]interface{}) {
sp["name"] =v.(map[string]interface{})["name"].(string)
// lb is of TypeList. take only the first element// if lb length is 0, then it is a service profile with no lb paramsiflen(v.(map[string]interface{})["lb"].([]interface{})) >0 {
lbRaw:=v.(map[string]interface{})["lb"].([]interface{})[0].(map[string]interface{})
lbMap:=make(map[string]interface{})
lbMap["name"] =lbRaw["name"].(string)
//lb_params is of TypeList. take only the first elementiflen(lbRaw["lb_params"].([]interface{})) >0 {
lbParamsRaw:=lbRaw["lb_params"].([]interface{})[0].(map[string]interface{})
lbParamsMap:=make(map[string]interface{})
lbParamsMap["algorithm"] =lbParamsRaw["algorithm"].(string)
lbParamsMap["stickiness_type"] =lbParamsRaw["stickiness_type"].(string)
if_, ok:=lbParamsRaw["max_server_connections"]; ok {
lbParamsMap["max_server_connections"] =lbParamsRaw["max_server_connections"].(int)
}
lbMap["lb_params"] =lbParamsMap
}
sp["lb"] =lbMap
}
}
}
SDK version
Relevant provider source code
Schema
Terraform Configuration Files
Debug Output
Expected Behavior
I am writing a custom terraform provider. I need to read the above configuration.
I have written schema in such a way that
lb
andlb_params
are ofTypeList
withMaxItems=1
.If I do not pass
max_server_connections
underlb_params
in config (.tf file), the terraform SDK is sendingmax_server_connections=0
in payload.I do not need this in my payload if it’s not present in the config.
How can I achieve it?
Even though I tried to use the below if block for
max_server_connections
, I see the max_server_connections in the payload.Create function snippet
Actual Behavior
Steps to Reproduce
References
I have asked the same question on discuss.hashicorp.com
https://discuss.hashicorp.com/t/how-to-check-a-nested-attributes-presence-in-a-configuration/44123
The text was updated successfully, but these errors were encountered: