Generate the providers

Generate google and google-beta providers #

This quickstart guides you through setting up your development environment, making a change to magic-modules, generating provider changes to the google and google-beta Terraform providers, and running tests related to the change.

Before you begin #

  1. Install the gcloud CLI.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
    Note: If you don’t already have a project to use for testing changes to the Terraform providers, create a project instead of selecting an existing poject. After you finish these steps, you can delete the project, removing all resources associated with the project.
    Go to project selector
  3. Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.

Set up your development environment #

If you are familiar with Docker or Podman, you may want to use the experimental container-based environment instead of this section.
  1. Install git

  2. Install go

  3. Add the following values to your environment settings such as .bashrc:

    # Add GOPATH variable for convenience
    export GOPATH=$(go env GOPATH)
    # Add Go binaries to PATH
    export PATH=$PATH:$(go env GOPATH)/bin
    
  4. Install goimports

    go install golang.org/x/tools/cmd/goimports@latest
    
  5. Install terraform

  6. Clone the magic-modules repository

    cd ~
    git clone https://github.com/GoogleCloudPlatform/magic-modules.git
    
  7. Run the following command from the root of your cloned magic-modules repository.

    cd magic-modules
    ./scripts/doctor
    

    Expected output if everything is installed properly:

    Check for go in path...
       found!
    Check for goimports in path...
       found!
    Check for git in path...
       found!
    Check for terraform in path...
       found!
    Check for make in path...
       found!
    

Generate a provider change #

  1. In your cloned magic-modules repository, edit mmv1/products/bigqueryanalyticshub/DataExchange.yaml to change the description for the displayName field:

    - name: 'displayName'
      type: NestedObject
      description: |
        UPDATED_DESCRIPTION    
    
  2. Clone the google and google-beta provider repositories with the following commands:

    git clone https://github.com/hashicorp/terraform-provider-google.git $GOPATH/src/github.com/hashicorp/terraform-provider-google
    git clone https://github.com/hashicorp/terraform-provider-google-beta.git $GOPATH/src/github.com/hashicorp/terraform-provider-google-beta
    
  3. Generate changes for the google provider

    make provider VERSION=ga OUTPUT_PATH="$GOPATH/src/github.com/hashicorp/terraform-provider-google" PRODUCT=bigqueryanalyticshub
    
  4. Generate changes for the google-beta provider

    make provider VERSION=beta OUTPUT_PATH="$GOPATH/src/github.com/hashicorp/terraform-provider-google-beta" PRODUCT=bigqueryanalyticshub
    
  5. Confirm that the expected changes were generated

    cd $GOPATH/src/github.com/hashicorp/terraform-provider-google
    git diff -U0
    cd $GOPATH/src/github.com/hashicorp/terraform-provider-google-beta
    git diff -U0
    

    In both cases, the changes should include:

    diff --git a/google/services/bigqueryanalyticshub/resource_bigquery_analytics_hudiff --git a/google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange.go b/google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange.go
    --- a/google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange.go
    +++ b/google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_data_exchange.go
    @@ -66 +66 @@ func ResourceBigqueryAnalyticsHubDataExchange() *schema.Resource {
    -                               Description: `Human-readable display name of the data exchange. The display name must contain only Unicode letters, numbers (0-9), underscores (_), dashes (-), spaces ( ), and must not start or end with spaces.`,
    +                               Description: `UPDATED_DESCRIPTION`,
    diff --git a/website/docs/r/bigquery_analytics_hub_data_exchange.html.markdown b/website/docs/r/bigquery_analytics_hub_data_exchange.html.markdown
    --- a/website/docs/r/bigquery_analytics_hub_data_exchange.html.markdown
    +++ b/website/docs/r/bigquery_analytics_hub_data_exchange.html.markdown
    @@ -63 +63 @@ The following arguments are supported:
    -  Human-readable display name of the data exchange. The display name must contain only Unicode letters, numbers (0-9), underscores (_), dashes (-), spaces ( ), and must not start or end with spaces.
    +  UPDATED_DESCRIPTION
    
    Note: There may be additional changes present due to specifying a PRODUCT= value or due to the magic-modules repository being out of sync with the provider repositories. This is okay as long as tests in the following section pass.

Test changes #

  1. Set up application default credentials for Terraform

    gcloud auth application-default login
    export GOOGLE_USE_DEFAULT_CREDENTIALS=true
    
  2. Set required environment variables

    export GOOGLE_PROJECT=PROJECT_ID
    export GOOGLE_REGION=us-central1
    export GOOGLE_ZONE=us-central1-a
    

    Replace PROJECT_ID with the ID of your Google Cloud project.

  3. Enable required APIs

    gcloud config set project $GOOGLE_PROJECT
    gcloud services enable analyticshub.googleapis.com
    
  4. Run all linters

    cd $GOPATH/src/github.com/hashicorp/terraform-provider-google
    make lint
    cd $GOPATH/src/github.com/hashicorp/terraform-provider-google-beta
    make lint
    
  5. Run all unit tests

    cd $GOPATH/src/github.com/hashicorp/terraform-provider-google
    make test
    cd $GOPATH/src/github.com/hashicorp/terraform-provider-google-beta
    make test
    
  6. Run acceptance tests for BigqueryAnalyticsHub DataExchange

    cd $GOPATH/src/github.com/hashicorp/terraform-provider-google
    make testacc TEST=./google/services/bigqueryanalyticshub TESTARGS='-run=TestAccBigqueryAnalyticsHubDataExchange_'
    cd $GOPATH/src/github.com/hashicorp/terraform-provider-google-beta
    make testacc TEST=./google-beta/services/bigqueryanalyticshub TESTARGS='-run=TestAccBigqueryAnalyticsHubDataExchange_'
    

Troubleshoot #

Too many open files #

If you are getting “Too many open files” ulimit needs to be raised.

ulimit -n 8192

Cleanup #

  1. Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke

What’s next #