terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

Add typed enums and inlined docs in CDKTF and related providers

Open IhnatKlimchuk opened this issue 2 years ago • 2 comments

Description

I use cdktf with @cdktf/provider-azurerm provider. I use Typescript for managing stacks and constructs. I created a stack with StorageAccount from @cdktf/provider-azurerm/lib/storage-account like this:

...
    const account = new StorageAccount(this, "storage-account", {
      location: this.region,
      accountTier: "Standard",
      accountReplicationType: "LRS",
      resourceGroupName: this.resourceGroup.name,
      name: `${env.name}${"servicename"}`,
    });
...

in case I open accountTier definition I see next:

...
/**
* Docs at Terraform Registry: {@link https://registry.terraform.io/providers/hashicorp/azurerm/3.58.0/docs/resources/storage_account#account_tier StorageAccount#account_tier}
*/
readonly accountTier: string;
...

while according to docs

account_tier - (Required) Defines the Tier to use for this storage account. Valid options are Standard and Premium. For BlockBlobStorage and FileStorage accounts only Premium is valid. Changing this forces a new resource to be created.

This approach is looks like very time consuming and requires a lot of hops between code and docs. So I would expect to have:

  1. Docs copied in place for simpler navigation and code writing.
  2. Typed possible options, so I don't need to navigate to landing page each new property

Like this:

...
/** account_tier - (Required) Defines the Tier to use for this storage account. Valid options are "Standard" and "Premium". For "BlockBlobStorage" and "FileStorage" accounts only "Premium" is valid. Changing this forces a new resource to be created.
* Link - https://registry.terraform.io/providers/hashicorp/azurerm/3.58.0/docs/resources/storage_account#account_tier 
*/
readonly accountTier: "Standard" | "Premium"; 

// or 'readonly accountTier: "Standard" | "Premium" | string' for backward compatibility
// or 'readonly accountTier: StorageAccountTiers' with proper docs for each option
...

References

No response

Help Wanted

  • [X] I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

IhnatKlimchuk avatar Jun 14 '23 16:06 IhnatKlimchuk

Hi @IhnatKlimchuk 👋

We agree with you! Unfortunately those docs in the Terraform Registry are not available in a structured format so we can't easily include them in the inline docs and there's no enum type information that we can use.

However, in the long term we are working with the respective teams that manage these other bits and are aligned on making such information easy to access programmatically which would then allow us to implement what you requested.

ansgarm avatar Jun 23 '23 09:06 ansgarm

checking in two years later to say that this is still sorely needed

shellscape avatar Sep 13 '25 04:09 shellscape