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

Make value handling methods more discoverable in the documentation #695

Closed
asaba-hashi opened this issue Mar 20, 2023 · 4 comments · Fixed by #822
Closed

Make value handling methods more discoverable in the documentation #695

asaba-hashi opened this issue Mar 20, 2023 · 4 comments · Fixed by #822
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@asaba-hashi
Copy link

Module version

N/A

Use-cases

As a new framework developer, I would like to easily find the methods for converting go native types to their equivalent type values.

The current documenation for attributes is very long and the full contents are not listed completely on the "On this page".

Attempted Solutions

N/A

Proposal

  1. Add a general "types Conventions" section at the top of the page describing that each type has a "types..IsNull"/"types.ValueFrom"/etc.
  2. Add links to the table at the top of the page to the content further down.
  3. Expand the TOC (or do some other rearrangement of the content) such that each type has an entry in a TOC.

References

@asaba-hashi asaba-hashi added the enhancement New feature or request label Mar 20, 2023
@bflad bflad added documentation Improvements or additions to documentation and removed enhancement New feature or request labels Mar 20, 2023
@bflad
Copy link
Contributor

bflad commented Mar 20, 2023

Just to copy some additional thoughts from an outside-of-GitHub conversation:

Another potential idea here to avoid the long scrolling single page would be to break down each data/attribute type into its own page, then each of those could spend some real estate on adding some more real world examples around going to/from the framework types

The navigation then might become something like:

Handling Data

  • Terraform Concepts (existing)
  • Schemas (existing)
  • Attributes (converted to an overview page)
    • Bool (referencing Built-in Types > Bool)
    • Float64 (referencing Built-in Types > Float64)
    • Int64 (referencing Built-in Types > Int64)
    • List (referencing Built-in Types > List)
    • List Nested (referencing Built-in Types > List)
    • Map (referencing Built-in Types > Map)
    • Map Nested (referencing Built-in Types > Map)
    • Number (referencing Built-in Types > Number)
    • Object (referencing Built-in Types > Object)
    • Set (referencing Built-in Types > Set)
    • Set Nested (referencing Built-in Types > Set)
    • Single Nested (referencing Built-in Types > Object)
    • String (referencing Built-in Types > String)
  • Blocks (converted to an overview page)
    • List (referencing Built-in Types > List)
    • Set (referencing Built-in Types > Set)
    • Single (referencing Built-in Types > Object)
  • Built-in Types (new)
    • Bool (referencing Attributes > Bool)
    • Float64 (referencing Attributes > Float64)
    • Int64 (referencing Attributes > Int64)
    • List (referencing Attributes > List, Attributes > List Nested, Blocks > List)
    • Map (referencing Attributes > Map, Attributes > Map Nested)
    • Number (referencing Attributes > Number)
    • Object (referencing Attributes > Object, Blocks > Single)
    • Set (referencing Attributes > Set, Attributes > Set Nested, and Blocks > Set)
    • String (referencing Attributes > String)
  • Paths (existing)
  • Path Expressions (existing)
  • Accessing Terraform Data (existing, although maybe could use some tweaks)
  • Writing Data (existing, although maybe could use some tweaks)
  • Conversion Rules (removing, these should be documented with each Built-In Type page)
  • Custom Types (existing)

Each of the new Attributes, Blocks, and Built-In Types pages could then provide real world code examples, such as using MapValueFrom() to convert a map[string]string to a types.Map:

// Logic in this example is applicable to any data source, provider, or resource method
// that needs to convert data into a types.Map.
func (r ThingResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
  // ... API handling logic ...

  // Typically this would be an existing field from an API SDK type,
  // however this example shows an inline variable definition for brevity.
  var apiMap map[string]string

  tfMap, diags := types.MapValueFrom(ctx, types.String, apiMap)

  resp.Diagnostics.Append(diags...)

  if resp.Diagnostics.HasError() {
    return
  }

  // ... resp.State.Set() or resp.State.SetAttribute() logic using tfMap ...
}

@mschuchard
Copy link

mschuchard commented Mar 23, 2023

I would also really appreciate this as I struggled for about thirty minutes yesterday to determine proper usage for AsElements and MapValueFrom. I eventually dug around the relevant unit tests to figure it out. When I finally executed an acceptance test and it succeeded first try I almost fell out of my chair, and had to stare at my code for a while out of suspicion.

That example at the end of the comment would be very helpful (especially because I thought at first I needed to use basetypes.StringType{}), but also documentation for e.g. ElementsAs would be helpful in my opinion.

bflad added a commit that referenced this issue Aug 15, 2023
…and examples

Reference: #695

This change creates new attributes, blocks, and types sections, each with full information about each type. The attribute/block pages are cross-linked with their associated type pages and vice-versa.

Web platform changes to redirect the removed pages to existing pages will be handled separately on deployment.
@bflad bflad modified the milestones: v1.4.0, v1.3.5 Aug 17, 2023
bflad added a commit that referenced this issue Aug 17, 2023
…and examples (#822)

Reference: #695

This change creates new attributes, blocks, and types sections, each with full information about each type. The attribute/block pages are cross-linked with their associated type pages and vice-versa.

Web platform changes to redirect the removed pages to existing pages will be handled separately on deployment.
@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 Sep 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
3 participants