/// <summary> /// https://www.terraform.io/docs/configuration/variables.html /// Valid values are string, list, and map. If this field is omitted, the variable type will be inferred based on default. /// If no default is provided, the type is assumed to be string. /// </summary> static string GetType(JToken token) { var type = token.SelectToken("type"); if (type != null) { return(TerraformDataTypes.MapToType(type.ToString())); } // We can determine the type from the default value var defaultValue = token.SelectToken("default"); if (defaultValue == null) { return("string"); } switch (defaultValue.Type) { case JTokenType.Array: return(TerraformDataTypes.RawList); case JTokenType.Object: return(TerraformDataTypes.RawMap); } return("string"); // Otherwise we default to a string }
/// <summary> /// https://www.terraform.io/docs/configuration/variables.html /// Valid values are string, list, and map. If this field is omitted, the variable type will be inferred based on default. /// If no default is provided, the type is assumed to be string. /// </summary> string GetType(HclElement token) { var type = token.Children?.FirstOrDefault(child => child.Name == "type"); if (type != null) { return(TerraformDataTypes.MapToType(type.Value)); } // We can determine the type from the default value var defaultValue = token.Children?.FirstOrDefault(child => child.Name == "default"); if (defaultValue == null) { return("string"); } switch (defaultValue.Type) { case HclElement.ListType: case HclElement.ListPropertyType: return(TerraformDataTypes.RawList); case HclElement.MapType: case HclElement.MapPropertyType: return(TerraformDataTypes.RawMap); } // Otherwise we default to a string return("string"); }