Skip to content

Commit 727c6c2

Browse files
nityaravimelinath
andauthored
Updategenproviders (#12350)
Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
1 parent b311e8a commit 727c6c2

14 files changed

+196
-223
lines changed

docs/content/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Overview"
3-
weight: 20
3+
weight: 10
44
aliases:
55
- /docs/how-to/types-of-resources
66
- /how-to/types-of-resources

docs/content/contribution-process.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Contribution process"
3-
weight: 9
3+
weight: 11
44
aliases:
55
- /docs/getting-started/contributing
66
- /getting-started/contributing
@@ -22,14 +22,15 @@ This page explains how you can contribute code and documentation to the `magic-m
2222

2323
## Contribute code
2424

25+
1. [Set up your development environment]({{< ref "/develop/set-up-dev-environment" >}})
2526
1. [Create a new branch for your change](https://docs.github.com/en/get-started/quickstart/github-flow#create-a-branch)
2627
1. Make the code change. For example:
2728
- [Add or modify a resource]({{< ref "/develop/resource" >}})
2829
- [Add resource tests]({{< ref "/develop/test/test" >}})
2930
- [Add a datasource]({{< ref "/develop/add-handwritten-datasource" >}})
3031
- [Promote to GA]({{< ref "/develop/promote-to-ga" >}})
3132
- [Make a breaking change]({{< ref "/develop/breaking-changes/make-a-breaking-change" >}})
32-
1. [Generate the providers]({{< ref "/get-started/generate-providers" >}}) that include your change.
33+
1. [Generate the providers]({{< ref "/develop/generate-providers" >}}) that include your change.
3334
1. [Run provider tests locally]({{< ref "/develop/test/run-tests" >}}) that are relevant to the change you made
3435
1. [Create a pull request (PR)]({{< ref "/contribute/create-pr" >}})
3536
1. Make changes in response to [code review]({{< ref "/contribute/create-pr#code-review" >}})

docs/content/develop/add-handwritten-datasource.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Add a datasource"
33
summary: "Datasources are like terraform resources except they don't *create* anything."
4-
weight: 40
4+
weight: 14
55
aliases:
66
- /docs/how-to/add-handwritten-datasource
77
- /how-to/add-handwritten-datasource
@@ -52,5 +52,5 @@ library, or the raw HTTP client used in MMV1 through `SendRequest`.
5252
1. Open the data source documentation in [`magic-modules/third_party/terraform/website/docs/d/`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/website/docs/d) using an editor of your choice.
5353
- The name of the file is the name of the data source without a `google_` prefix. For example, for `google_compute_instance`, the file is called `compute_instance.html.markdown`
5454
2. Modify the documentation as needed according to [Handwritten documentation style guide]({{< ref "/develop/handwritten-docs-style-guide" >}}).
55-
4. [Generate the providers]({{< ref "/get-started/generate-providers.md" >}})
55+
4. [Generate the providers]({{< ref "/develop/generate-providers" >}})
5656
5. Copy and paste the generated documentation into the Hashicorp Registry's [Doc Preview Tool](https://registry.terraform.io/tools/doc-preview) to see how it is rendered.

docs/content/develop/custom-code.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Add custom resource code"
3-
weight: 39
3+
weight: 15
44
---
55

66
# Add custom resource code
@@ -17,7 +17,7 @@ custom_code:
1717
1818
By convention, the template files are stored in a directory matching the type of custom code, and the name of the file includes the resource (and, if relevant, field) impacted by the custom code. Like handwritten resource and test code, custom code is written as go templates which render go code.
1919
20-
When in doubt about the behavior of custom code, write the custom code, [generate the providers]({{< ref "/get-started/generate-providers" >}}), and inspect what changed in the providers using `git diff`.
20+
When in doubt about the behavior of custom code, write the custom code, [generate the providers]({{< ref "/develop/generate-providers" >}}), and inspect what changed in the providers using `git diff`.
2121

2222
The following sections describe types of custom code in more detail.
2323

docs/content/develop/diffs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Fix diffs"
3-
weight: 60
3+
weight: 18
44
aliases:
55
- /develop/permadiff
66
---
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: "Generate the providers"
3+
weight: 19
4+
aliases:
5+
- /docs/getting-started/setup
6+
- /getting-started/setup
7+
- /docs/getting-started/generate-providers
8+
- /getting-started/generate-providers
9+
- /get-started/generate-providers
10+
---
11+
12+
# Generate `google` and `google-beta` providers
13+
14+
After making a change to the Terraform providers for Google Cloud, you must
15+
integrate your changes with the providers. This page explains how to generate
16+
provider changes to the `google` and `google-beta` Terraform providers.
17+
18+
## Before you begin
19+
20+
1. [Set up your development environment]({{< ref "/develop/set-up-dev-environment" >}}).
21+
1. Update `magic-modules` as needed. These updates could be any of the following changes:
22+
+ [Adding or modifying a resource]({{< ref "/develop/resource" >}}).
23+
+ [Adding a datasource]({{< ref "/develop/add-handwritten-datasource" >}}).
24+
+ [Adding custom resource code]({{< ref "/develop/custom-code" >}}).
25+
+ [Promoting a resource to GA]({{< ref "/develop/promote-to-ga" >}}).
26+
27+
## Generate a provider change
28+
29+
1. Clone the `google` and `google-beta` provider repositories with the following commands:
30+
31+
```bash
32+
git clone https://github.com/hashicorp/terraform-provider-google.git $GOPATH/src/github.com/hashicorp/terraform-provider-google
33+
git clone https://github.com/hashicorp/terraform-provider-google-beta.git $GOPATH/src/github.com/hashicorp/terraform-provider-google-beta
34+
```
35+
1. Generate changes for the `google` provider:
36+
```bash
37+
make provider VERSION=ga OUTPUT_PATH="$GOPATH/src/github.com/hashicorp/terraform-provider-google" PRODUCT=[PRODUCT_NAME]
38+
```
39+
Where `[PRODUCT_NAME]` is one of the folder names in
40+
https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products.
41+
42+
For example, if your product is `bigqueryanalyticshub`, the command would be
43+
the following:
44+
45+
```bash
46+
make provider VERSION=ga OUTPUT_PATH="$GOPATH/src/github.com/hashicorp/terraform-provider-google" PRODUCT=bigqueryanalyticshub
47+
```
48+
49+
1. Generate changes for the `google-beta` provider:
50+
```bash
51+
make provider VERSION=beta OUTPUT_PATH="$GOPATH/src/github.com/hashicorp/terraform-provider-google-beta" PRODUCT=[PRODUCT_NAME]
52+
```
53+
54+
Where `[PRODUCT_NAME]` is one of the folder names in https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products.
55+
56+
For example, if your product name is `bigqueryanalyticshub`, the command would be the following:
57+
58+
```bash
59+
make provider VERSION=beta OUTPUT_PATH="$GOPATH/src/github.com/hashicorp/terraform-provider-google-beta" PRODUCT=bigqueryanalyticshub
60+
```
61+
62+
1. Confirm that the expected changes were generated:
63+
```bash
64+
cd $GOPATH/src/github.com/hashicorp/terraform-provider-google
65+
git diff -U0
66+
cd $GOPATH/src/github.com/hashicorp/terraform-provider-google-beta
67+
git diff -U0
68+
```
69+
70+
71+
{{< hint info >}}
72+
**Note**: There may be additional changes present due to specifying a
73+
`PRODUCT=` value or due to the `magic-modules` repository being out of sync
74+
with the provider repositories.
75+
{{< /hint >}}
76+
77+
78+
## Troubleshoot
79+
80+
### Too many open files {#too-many-open-files}
81+
82+
If you are getting “Too many open files” ulimit needs to be raised.
83+
84+
{{< tabs "ulimit" >}}
85+
{{< tab "Mac OS" >}}
86+
```bash
87+
ulimit -n 8192
88+
```
89+
{{< /tab >}}
90+
{{< /tabs >}}
91+
92+
## What's next
93+
94+
+ [Learn how to add resource tests]({{< ref "/develop/test/test" >}})
95+
+ [Learn how to run tests]({{< ref "/develop/test/run-tests" >}})
96+
+ [Learn about `make` commands]({{< ref "/reference/make-commands" >}})

docs/content/develop/promote-to-ga.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Promote to GA"
3-
weight: 50
3+
weight: 16
44
---
55

66
# Promote from beta to GA
@@ -13,7 +13,7 @@ For more information about types of resources and the generation process overall
1313

1414
## Before you begin
1515

16-
1. Complete the [Generate the providers]({{< ref "/get-started/generate-providers" >}}) quickstart to set up your environment and your Google Cloud project.
16+
1. Complete the steps in [Set up your development environment]({{< ref "/develop/set-up-dev-environment" >}}) to set up your environment and your Google Cloud project.
1717
2. Ensure that your `magic-modules`, `terraform-provider-google`, and `terraform-provider-google-beta` repositories are up to date.
1818
```
1919
cd ~/magic-modules

docs/content/develop/resource.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Add or modify a resource"
3-
weight: 30
3+
weight: 13
44
aliases:
55
- /docs/how-to/add-mmv1-resource
66
- /how-to/add-mmv1-resource
@@ -31,7 +31,7 @@ For more information about types of resources and the generation process overall
3131

3232
## Before you begin
3333

34-
1. Complete the steps in [Generate the providers]({{< ref "/get-started/generate-providers" >}}) to set up your environment and your Google Cloud project.
34+
1. Complete the steps in [Set up your development environment]({{< ref "/develop/set-up-dev-environment" >}}) to set up your environment and your Google Cloud project.
3535
2. Ensure that your `magic-modules`, `terraform-provider-google`, and `terraform-provider-google-beta` repositories are up to date.
3636
```
3737
cd ~/magic-modules
@@ -151,7 +151,7 @@ For more information about types of resources and the generation process overall
151151
> **Warning:** Handwritten resources are more difficult to develop and maintain. New handwritten resources will only be accepted if implementing the resource in MMv1 would require entirely overriding two or more CRUD methods.
152152
153153
1. Add the resource in MMv1.
154-
2. [Generate the beta provider]({{< ref "/get-started/generate-providers.md" >}})
154+
2. [Generate the beta provider]({{< ref "/develop/generate-providers.md" >}})
155155
3. From the beta provider, copy the files generated for the resource to the following locations:
156156
- Resource: Copy to the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services)
157157
- Documentation: [`magic-modules/mmv1/third_party/terraform/website/docs/r`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/website/docs/r)
@@ -420,7 +420,7 @@ iam_policy:
420420

421421
### Convert to handwritten (not usually necessary)
422422

423-
1. [Generate the beta provider]({{< ref "/get-started/generate-providers.md" >}})
423+
1. [Generate the beta provider]({{< ref "/develop/generate-providers.md" >}})
424424
2. From the beta provider, copy the files generated for the IAM resources to the following locations:
425425
- Resource: Copy to the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services)
426426
- Documentation: [`magic-modules/mmv1/third_party/terraform/website/docs/r`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/website/docs/r)
@@ -442,7 +442,7 @@ iam_policy:
442442
{{< tab "MMv1" >}}
443443
Documentation is autogenerated based on the resource and field configurations. To preview the documentation:
444444

445-
1. [Generate the providers]({{< ref "/get-started/generate-providers.md" >}})
445+
1. [Generate the providers]({{< ref "/develop/generate-providers.md" >}})
446446
2. Copy and paste the generated documentation into the Hashicorp Registry's [Doc Preview Tool](https://registry.terraform.io/tools/doc-preview) to see how it is rendered.
447447
{{< /tab >}}
448448
{{< tab "Handwritten" >}}
@@ -451,7 +451,7 @@ Documentation is autogenerated based on the resource and field configurations. T
451451
1. Open the resource documentation in [`magic-modules/third_party/terraform/website/docs/r/`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/website/docs/r) using an editor of your choice.
452452
- The name of the file is the name of the resource without a `google_` prefix. For example, for `google_compute_instance`, the file is called `compute_instance.html.markdown`
453453
2. Modify the documentation as needed according to [Handwritten documentation style guide]({{< ref "/develop/handwritten-docs-style-guide" >}}).
454-
3. [Generate the providers]({{< ref "/get-started/generate-providers.md" >}})
454+
3. [Generate the providers]({{< ref "/develop/generate-providers.md" >}})
455455
4. Copy and paste the generated documentation into the Hashicorp Registry's [Doc Preview Tool](https://registry.terraform.io/tools/doc-preview) to see how it is rendered.
456456
{{< /tab >}}
457457
{{< /tabs >}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: "Set up your development environment"
3+
weight: 12
4+
---
5+
6+
# Set up your development environment
7+
8+
Before you start adding or updating a Terraform resource using
9+
[magic-modules]({{< ref "/" >}}), you must first set up your environment by
10+
installing the necessary tools. This page explains the steps for setting up your
11+
development environment.
12+
13+
1. [Install the gcloud CLI.](https://cloud.google.com/sdk/docs/install)
14+
1. In the Google Cloud console, on the project selector page, select or
15+
[create a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects).
16+
{{< hint info >}}
17+
18+
**Note:** If you don't already have a project to use for testing changes to
19+
the Terraform providers, create a project instead of selecting an existing
20+
poject. After you finish these steps, you can delete the project, removing
21+
all resources associated with the project.
22+
23+
{{< /hint >}}
24+
{{< button href="https://console.cloud.google.com/projectselector2/home/dashboard" >}}Go to project selector{{< /button >}}
25+
1. Make sure that billing is enabled for your Google Cloud project. Learn how to
26+
[check if billing is enabled on a project](https://cloud.google.com/billing/docs/how-to/verify-billing-enabled).
27+
28+
29+
1. [Install git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
30+
1. [Install go](https://go.dev/doc/install)
31+
1. Add the following values to your environment settings such as `.bashrc`:
32+
```bash
33+
# Add GOPATH variable for convenience
34+
export GOPATH=$(go env GOPATH)
35+
# Add Go binaries to PATH
36+
export PATH=$PATH:$(go env GOPATH)/bin
37+
```
38+
1. Install goimports
39+
```bash
40+
go install golang.org/x/tools/cmd/goimports@latest
41+
```
42+
1. [Install terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli)
43+
1. Clone the `magic-modules` repository
44+
```bash
45+
cd ~
46+
git clone https://github.com/GoogleCloudPlatform/magic-modules.git
47+
```
48+
49+
1. Run the following command from the root of your cloned `magic-modules` repository.
50+
51+
```bash
52+
cd magic-modules
53+
./scripts/doctor
54+
```
55+
56+
Expected output if everything is installed properly:
57+
58+
```
59+
Check for go in path...
60+
found!
61+
Check for goimports in path...
62+
found!
63+
Check for git in path...
64+
found!
65+
Check for terraform in path...
66+
found!
67+
Check for make in path...
68+
found!
69+
```
70+
71+
## What's next
72+
73+
+ [Learn how to add or modify a resource]({{< ref "/develop/resource" >}})
74+
+ [Learn how to add custom resource code]({{< ref "/develop/custom-code" >}})
75+
+ [Learn how to add a datasource]({{< ref "/develop/add-handwritten-datasource" >}})
76+
+ [Learn how to promote a resource to GA]({{< ref "/develop/promote-to-ga" >}})
77+

docs/content/develop/test/run-tests.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ aliases:
1515

1616
## Before you begin
1717

18-
[Generate the modified provider(s)]({{< ref "/get-started/generate-providers" >}})
18+
[Generate the modified provider(s)]({{< ref "/develop/generate-providers" >}})
1919

2020

2121
1. Set up application default credentials for Terraform
@@ -243,7 +243,7 @@ Configure Terraform to use locally-built binaries for `google` and `google-beta`
243243

244244
### Run manual tests
245245

246-
1. [Generate the provider(s) you want to test]({{< ref "/get-started/generate-providers" >}})
246+
1. [Generate the provider(s) you want to test]({{< ref "/develop/generate-providers" >}})
247247
2. Build the provider(s) you want to test
248248

249249
```bash

docs/content/develop/test/test.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ This section assumes you've used the [Add a resource]({{< ref "/develop/resource
100100
> **Note:** If not, you can create one now, or skip this guide and construct the test by hand. Writing tests by hand can sometimes be a better option if there is a similar test you can copy from.
101101

102102
1. Add the test in MMv1. Repeat for all the create tests you will need.
103-
2. [Generate the beta provider]({{< ref "/get-started/generate-providers.md" >}}).
103+
2. [Generate the beta provider]({{< ref "/develop/generate-providers.md" >}}).
104104
3. From the beta provider, copy and paste the generated `*_generated_test.go` file into the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/) as a new file call `*_test.go`.
105105
4. Modify the tests as needed.
106106
- Replace all occurrences of `github.com/hashicorp/terraform-provider-google-beta/google-beta` with `github.com/hashicorp/terraform-provider-google/google`
@@ -120,7 +120,7 @@ An update test is a test that creates the target resource and then makes updates
120120

121121
{{< tabs "update" >}}
122122
{{< tab "MMv1" >}}
123-
1. [Generate the beta provider]({{< ref "/get-started/generate-providers.md" >}}).
123+
1. [Generate the beta provider]({{< ref "/develop/generate-providers" >}}).
124124
2. From the beta provider, copy and paste the generated `*_generated_test.go` file into the appropriate service folder inside [`magic-modules/mmv1/third_party/terraform/services`](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services) as a new file call `*_test.go`.
125125
3. Using an editor of your choice, delete the `*DestroyProducer` function, and all but one test. The remaining test should be the "full" test, or if there is no "full" test, the "basic" test. This will be the starting point for your new update test.
126126
4. Modify the `TestAcc*` *test function* to support updates.
@@ -274,4 +274,4 @@ func TestSignatureAlgorithmDiffSuppress(t *testing.T) {
274274

275275
## What's next?
276276

277-
- [Run your tests]({{< ref "/develop/test/run-tests.md" >}})
277+
- [Run your tests]({{< ref "/develop/test/run-tests" >}})

docs/content/develop/update-dependencies.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Update dependencies"
3-
weight: 300
3+
weight: 17
44
aliases:
55
- /docs/update-dependencies
66
---

docs/content/get-started/_index.md

-4
This file was deleted.

0 commit comments

Comments
 (0)