func expandAction()

in internal/elasticsearch/index/ilm.go [592:626]


func expandAction(a []interface{}, serverVersion *version.Version, settings ...string) (map[string]interface{}, diag.Diagnostics) {
	var diags diag.Diagnostics
	def := make(map[string]interface{})

	if action := a[0]; action != nil {
		for _, setting := range settings {
			if v, ok := action.(map[string]interface{})[setting]; ok && v != nil {
				options := ilmActionSettingOptions[setting]

				if options.minVersion != nil && options.minVersion.GreaterThan(serverVersion) {
					if v != options.def {
						return nil, diag.Errorf("[%s] is not supported in the target Elasticsearch server. Remove the setting from your module definition or set it to the default [%s] value", setting, options.def)
					}

					// This setting is not supported, and shouldn't be set in the ILM policy object
					continue
				}

				if options.skipEmptyCheck || !utils.IsEmpty(v) {
					// these 3 fields must be treated as JSON objects
					if setting == "include" || setting == "exclude" || setting == "require" {
						res := make(map[string]interface{})
						if err := json.Unmarshal([]byte(v.(string)), &res); err != nil {
							return nil, diag.FromErr(err)
						}
						def[setting] = res
					} else {
						def[setting] = v
					}
				}
			}
		}
	}
	return def, diags
}