-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add a guide on authoring tpgtools new resources #5452
Add a guide on authoring tpgtools new resources #5452
Conversation
Hi! I'm the modular magician. Your PR hasn't generated any diffs, but I'll let you know if a future commit does. |
tpgtools/README.md
Outdated
|
||
### Adding Documentation | ||
|
||
Documentation will be automatically generated based on the resource description in the DCL and examples will be generated from the samples for this resource. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provided you've added samples ... otherwise, you'll need to write the documentation for the resource manually.
I've seen a few resources not get docs, I think samples are the thing that opts them in? Been a while since I wrote a resource w/ DCL+tpgtools.
tpgtools/README.md
Outdated
@@ -176,3 +176,33 @@ doc_hide: | |||
test_hide: | |||
- basic_workload.yaml | |||
``` | |||
|
|||
## New Resource Guide (tpgtools only) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## New Resource Guide (tpgtools only) | |
## New Resource Guide |
This part feels implied!
@@ -176,3 +176,33 @@ doc_hide: | |||
test_hide: | |||
- basic_workload.yaml | |||
``` | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider putting this higher up, between "Usage" and "Development"
tpgtools/README.md
Outdated
|
||
For the first pass try nothing. If behavior is needed to change the resource's behavior in Terraform from the default DCL resource, then you can add these at a later date. Generally no overrides will be needed for a new resource, but they will be needed for resources that exist in mmv1 that are being converted to use tpgtools. | ||
|
||
### Adding Samples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider putting the samples section here, instead of referencing it elsewhere in the README- that will avoid a context switch! Also, we may want to touch those up- I think we need to copy samples manually rn, and the go get
call can be replaced by make upgrade-dcl
, for two low-hanging fruit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ndmckinley also recently revamped how we pull in substitutions, I think less work is needed on those than is written here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this should Just Work for new versions of the DCL now. There's some no-op cleanup to do with deduplicating variables as it stands, but tpgtools handles it fine.
tpgtools/README.md
Outdated
|
||
This guide is written to document the process for adding a resource to the Google Terraform Provider (TPG) after it has been added to the [DCL](https://github.com/GoogleCloudPlatform/declarative-resource-client-library). | ||
|
||
### Adding Resource Overrides |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this + the header below: I'd recommend assuming that the override file will always be blank, explain briefly what an override is, and recommend that folks reach out to an experienced team member if they believe an override will be needed for their resource(s). To cover brownfield resources, I'd leave them out of this flow entirely and add them as an appendix afterwards- "those were the guidelines for new resources, here's how a brownfield resource is different"
Motivation(s):
- This keeps things simple for folks that are making their first contribution. It isn't true that you never need overrides yet, but we need to make it true.
- Deferring to an experienced engineer will mean they can help solve the root cause that needed an override in the first place.
- This is in contrast to the MMv1 field guide, where I explain some MMv1 overrides- using them is pretty normal, even for simple contributions.
- We expect most brownfield conversions to be done for our team (or another experienced member of a sister team) so having the information out of a new dev's critical path means there's less information overload
tpgtools/README.md
Outdated
|
||
See [guide above](#samples) for adding samples. | ||
|
||
### Adding Additional Information to Handwritten/MMv1 Generated Files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "Additional Information..." feels optional. "Registering the Resource", maybe?
tpgtools/README.md
Outdated
|
||
Additionally you may need to add a few line to provider.go for the endpoint if this resource is in a new product that doesn't have any other resources currently in the provider. Find the correct lines in the diff on `provider_dcl_endpoints.go` within the provider once it has been generated with the new resource. | ||
|
||
### Adding Documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want a section about writing handwritten tests as well! Copying the DCL samples may not result in the level of testing we want, or we may need customised tests for some resources.
I have triggered VCR tests in RECORDING mode for the following tests that failed during VCR: TestAccDatasourceGoogleServiceNetworkingPeeredDnsDomain_basic|TestAccAssuredWorkloadsWorkload_BasicHandWritten|TestAccAssuredWorkloadsWorkload_FullHandWritten|TestAccCloudFunctionsFunction_vpcConnector|TestAccComputeGlobalForwardingRule_privateServiceConnectGoogleApisExample|TestAccComputeForwardingRule_update|TestAccComputeInstanceFromMachineImage_basic|TestAccComputeInstanceFromMachineImage_overrideMetadataDotStartupScript|TestAccComputeInstanceFromMachineImage_diffProject|TestAccComputeRegionHealthCheck_tcp_update|TestAccComputeRegionHealthCheck_typeTransition|TestAccComputeRegionHealthCheck_logConfigDisabled|TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupAppengineExample|TestAccComputeServiceAttachment_serviceAttachmentBasicExampleUpdate|TestAccContainerCluster_withILBSubsetting|TestAccContainerCluster_regionalWithNodePool|TestAccContainerCluster_withNodePoolBasic|TestAccContainerCluster_withNodePoolResize|TestAccContainerCluster_withNodePoolUpdateVersion|TestAccContainerCluster_withNodePoolAutoscaling|TestAccContainerCluster_withNodePoolMultiple|TestAccContainerCluster_withNodePoolNodeConfig|TestAccContainerCluster_withEnableKubernetesAlpha|TestAccContainerNodePool_basic|TestAccContainerNodePool_basicWithClusterId|TestAccContainerNodePool_nodeLocations|TestAccContainerNodePool_maxPodsPerNode|TestAccContainerNodePool_withNodeConfig|TestAccContainerNodePool_withWorkloadIdentityConfig|TestAccContainerNodePool_withSandboxConfig|TestAccContainerNodePool_withKubeletConfig|TestAccContainerNodePool_withLinuxNodeConfig|TestAccContainerNodePool_withUpgradeSettings|TestAccContainerNodePool_withInvalidUpgradeSettings|TestAccContainerNodePool_withManagement|TestAccContainerNodePool_withGPU|TestAccContainerNodePool_withNodeConfigScopeAlias|TestAccContainerNodePool_regionalAutoscaling|TestAccContainerNodePool_resize|TestAccContainerNodePool_autoscaling|TestAccContainerNodePool_version|TestAccContainerNodePool_regionalClusters|TestAccContainerNodePool_EmptyGuestAccelerator|TestAccContainerNodePool_012_ConfigModeAttr|TestAccContainerNodePool_ephemeralStorageConfig|TestAccDataprocWorkflowTemplate_basic|TestAccEventarcTrigger_BasicHandWritten|TestAccServiceNetworkingPeeredDNSDomain_basic|TestAccMonitoringMonitoredProject_BasicMonitoredProject|TestAccNetworkServicesEdgeCacheOrigin_networkServicesEdgeCacheOriginBasicExample|TestAccNetworkServicesEdgeCacheOrigin_networkServicesEdgeCacheOriginAdvancedExample|TestAccNetworkServicesEdgeCacheService_networkServicesEdgeCacheServiceAdvancedExample|TestAccOrgPolicyPolicy_EnforcePolicy|TestAccOrgPolicyPolicy_FolderPolicy|TestAccOrgPolicyPolicy_ProjectPolicy|TestAccPrivatecaCertificateTemplate_BasicCertificateTemplate|TestAccSqlDatabaseInstance_withPrivateNetwork|TestAccSqlUser_postgresIAM You can view the result here: https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=218107 |
Tests failed during RECORDING mode: TestAccComputeInstanceFromMachineImage_overrideMetadataDotStartupScript|TestAccComputeInstanceFromMachineImage_basic|TestAccComputeInstanceFromMachineImage_diffProject|TestAccCloudFunctionsFunction_vpcConnector|TestAccComputeRegionNetworkEndpointGroup_regionNetworkEndpointGroupAppengineExample|TestAccContainerNodePool_nodeLocations|TestAccEventarcTrigger_BasicHandWritten|TestAccContainerNodePool_withInvalidUpgradeSettings|TestAccSqlUser_postgresIAM Please fix these to complete your PR |
Hi! I'm the modular magician. Your PR hasn't generated any diffs, but I'll let you know if a future commit does. |
tpgtools/README.md
Outdated
Start by copying the relevant samples from the DCL for your new resource. These will be added to | ||
the [tpgtools/api folder](https://github.com/GoogleCloudPlatform/magic-modules/tree/master/tpgtools/api) under the relevant product. | ||
These samples can be found under the samples/ folder within the DCL for the resource being added. For example, assured | ||
workloads can be found [here](https://github.com/GoogleCloudPlatform/declarative-resource-client-library/tree/main/services/google/assuredworkloads/samples). | ||
|
||
You may need to re-serialize `serialization.go` if you are adding newer resources. | ||
To do this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we can use make upgrade-dcl
below rather than go get
directly.
tpgtools/README.md
Outdated
Start by copying the relevant samples from the DCL for your new resource. These will be added to | ||
the [tpgtools/api folder](https://github.com/GoogleCloudPlatform/magic-modules/tree/master/tpgtools/api) under the relevant product. | ||
These samples can be found under the samples/ folder within the DCL for the resource being added. For example, assured | ||
workloads can be found [here](https://github.com/GoogleCloudPlatform/declarative-resource-client-library/tree/main/services/google/assuredworkloads/samples). | ||
|
||
You may need to re-serialize `serialization.go` if you are adding newer resources. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Given this is a new resource guide, we can omit this condition.
|
||
#### Adding to provider.go | ||
|
||
Add the resource definition within the `ResourceMapWithErrors` map. There is currently a block of tpgtools resources, so adding to that block is preferred. If this resource is available only at a specific version (beta, private) then add version tags around the resource definition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Consider using a code block to show a sample diff!
Hi! I'm the modular magician. Your PR hasn't generated any diffs, but I'll let you know if a future commit does. |
…5452) * Add a guide on authoring tpgtools new resources * Wrong headers * Simplify samples, reorder per PR feedback * PR feedback
Let me know if you have feedback!
Fixes: hashicorp/terraform-provider-google#10544
If this PR is for Terraform, I acknowledge that I have:
make test
andmake lint
to ensure it passes unit and linter tests.Release Note Template for Downstream PRs (will be copied)