Open gramsa49 opened 1 year ago
Hi @gramsa49 👋🏻 , thanks for submitting the issue and sorry you're running into trouble here.
tfplugindocs
makes use of Go template strings which, as you noted, utilize the double curly braces. For your use case you should be able to use a raw string constant with backticks (`) and another pair of double curly braces, like:
{{`{{issue.control.name}}`}}
Full example w/ your use-case:
return &schema.Resource{
Description: "Automation Rules define associations between actions and findings.",
Schema: map[string]*schema.Schema{
"servicenow_summary": {
Type: schema.TypeString,
Required: true,
Default: "Wiz Issue: {{`{{issue.control.name}}`}}",
Description: "Ticket summary",
},
Let me know if that doesn't solve the issue!
That has the downside that it alters the default value for the schema in the provider. I was able to work around the issue in the call to tfplugindocs as follows:
func init() {
// Set descriptions to support markdown syntax, this will be used in document generation and the language server.
schema.DescriptionKind = schema.StringMarkdown
// Customize the content of descriptions when output. For example you can add defaults on
// to the exported descriptions if present.
schema.SchemaDescriptionBuilder = func(s *schema.Schema) string {
desc := s.Description
switch v := s.Default.(type) {
case string:
_ = v
if s.Default != nil {
desc += fmt.Sprintf("\n - Defaults to `{{`%s`}}`.", s.Default.(string))
}
default:
if s.Default != nil {
desc += fmt.Sprintf("\n - Defaults to `%v`.", s.Default)
}
}
if s.ConflictsWith != nil {
desc += fmt.Sprintf("\n - Conflicts with `%v`.", s.ConflictsWith)
}
if s.AtLeastOneOf != nil {
desc += fmt.Sprintf("\n - Requires least one of: `%v`.", s.AtLeastOneOf)
}
if s.ExactlyOneOf != nil {
desc += fmt.Sprintf("\n - Required exactly one of: `%v`.", s.ExactlyOneOf)
}
return strings.TrimSpace(desc)
}
}
This takes a similar approach to the one proposed, but changes the handling by terraform-plugin-docs versus changing the default value in the Terraform providr.
Ah! I overlooked your example was with Default
and not Description
, apologies.
Re-opening the issue as we'd need to tweak tfplugindocs
escape handling to remedy this.
running into the same problem for https://github.com/ibm-hyper-protect/terraform-provider-hpcr
Error executing command: unable to generate website: unable to render data source template "data-sources\\encryption_certs.md.tmpl": unable to execute template: template: resourceTemplate:24:114: executing "resourceTemplate" at <.Major>: can't evaluate field Major in type struct { Type string; Name string; Description string; HasExample bool; ExampleFile string; HasImport bool; ImportFile string; ProviderName string; ProviderShortName string; SchemaMarkdown string; RenderedProviderName string }
Take the following code snippet from a Terraform provider:
An error is returned:
There looks to be an issue when a default value for a resource element contains double curly braces, which is what the tfplugindocs template format uses.
It's worth noting that the provider is configured to render the defaults in the docs: