Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Default to attribute struct in jsonprovider #28735

Closed
mavogel opened this issue May 18, 2021 · 2 comments
Closed

feat: add Default to attribute struct in jsonprovider #28735

mavogel opened this issue May 18, 2021 · 2 comments
Labels
enhancement new new issue not yet triaged

Comments

@mavogel
Copy link

mavogel commented May 18, 2021

I would like to be able to let terraform-plugin-docs (which uses terraform-json) generate the documentation for a provider and also append the default value of an attribute, if given.

For example given the entry

"rm": {
	Type:        schema.TypeBool,
	Description: "If true, then <omitted for brevity>.",
	Default:     false,
	Optional:    true,
},

I'd like to have the rendered output in the .md file as follows:

- **rm** (Boolean) If true, then <omitted for brevity>. Defaults to `false`

Current Terraform Version

Terraform v0.15.3
on darwin_amd64

Current tool versions

  • terraform-plugin-docs: v0.4.0
  • terraform-plugin-sdk/v2 v2.6.1

Use-cases

Attempted Solutions

For now I can simply add the value to the Description as follows:

"rm": {
	Type:        schema.TypeBool,
	Description: "If true, then <omitted for brevity>. Defaults to `false`",
	Default:     false,
	Optional:    true,
},

Proposal

Add the attribute Default here:

type attribute struct {
AttributeType json.RawMessage `json:"type,omitempty"`
AttributeNestedType *nestedType `json:"nested_type,omitempty"`
Description string `json:"description,omitempty"`
DescriptionKind string `json:"description_kind,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Required bool `json:"required,omitempty"`
Optional bool `json:"optional,omitempty"`
Computed bool `json:"computed,omitempty"`
Sensitive bool `json:"sensitive,omitempty"`
}
then the steps described in hashicorp/terraform-json#35 (comment) can be implemented in the other libraries/layers.

References

@mavogel mavogel added enhancement new new issue not yet triaged labels May 18, 2021
@jbardin
Copy link
Member

jbardin commented May 18, 2021

Hi @mavogel,

Thanks for the feedback here. The default values you see are implemented by a particular provider SDK, not Terraform itself. The Default field is not included in the provider plugin protocol, and is not seen by the terraform cli. Many Default values are also filled it via functions evaluated during planning, which are not representable in the schema protocol at all, leaving the same problem with displaying the defaults even if Default was added as part of the schema.

Since this is implemented by the plugin SDK, that project repository would be the starting point for a discussion about extending the schema protocol to expose default values. See also #28657 for a similar request.

Thanks!

@jbardin jbardin closed this as completed May 18, 2021
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants