func()

in resource/types/azapi_definition.go [36:86]


func (def AzapiDefinition) String() string {
	expressions := fmt.Sprintf(`  type = "%[1]s@%[2]s"`, def.AzureResourceType, def.ApiVersion)
	fields := []string{"resource_id", "parent_id", "name", "location", "action", "method"}
	for _, field := range fields {
		if value, ok := def.AdditionalFields[field]; ok {
			expressions += fmt.Sprintf(`
  %[1]s = %[2]s`, field, value)
		}
	}
	if def.Body != nil {
		bodyMap, ok := def.Body.(map[string]interface{})
		if ok {
			tagRaw, ok := bodyMap["tags"]
			if ok && tagRaw != nil {
				if tagMap, ok := tagRaw.(map[string]interface{}); ok && len(tagMap) == 0 {
					delete(bodyMap, "tags")
				}
			}
		}
		if len(bodyMap) > 0 {
			if def.BodyFormat == BodyFormatJson {
				jsonBody, _ := json.MarshalIndent(bodyMap, "", "    ")
				expressions += fmt.Sprintf(`<<BODY
%s
BODY`, jsonBody)
			} else {
				expressions += fmt.Sprintf(`
  body = %[1]s`, hcl.MarshalIndent(bodyMap, "  ", "  "))
			}
		}
	}
	for _, field := range []string{"schema_validation_enabled", "ignore_casing", "ignore_missing_property", "depends_on"} {
		if value, ok := def.AdditionalFields[field]; ok {
			expressions += fmt.Sprintf(`
  %[1]s = %[2]s`, field, value)
		}
	}
	config := fmt.Sprintf(
		`%[1]s "%[2]s" "%[3]s" {
%[4]s
}
`, def.Kind, def.ResourceName, def.Label, expressions)
	if len(def.LeadingComments) > 0 {
		comment := ""
		for _, line := range def.LeadingComments {
			comment += fmt.Sprintf("// %s\n", line)
		}
		config = comment + config
	}
	return config
}