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 rbenv, ensuring you follow both steps 1 and 2.

  3. Use rbenv to install ruby 3.1.0

    rbenv install 3.1.0
  4. Install go

  5. 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
  6. Install goimports

    go install
  7. Install terraform

  8. Clone the magic-modules repository

    cd ~
    git clone
  9. Run the following command from the root of your cloned magic-modules repository.

    cd magic-modules

    Expected output if everything is installed properly:

    Check for ruby in path...
    Check for go in path...
    Check for goimports in path...
    Check for git in path...
    Check for terraform in path...
    Check for make in path...

Generate a provider change #

  1. In your cloned magic-modules repository, edit mmv1/products/pubsub/Topic.yaml to change the description for the schemaSettings field:

    - !ruby/object:Api::Type::NestedObject
      name: 'schemaSettings'
      description: |
  2. Clone the google and google-beta provider repositories with the following commands:

    git clone $GOPATH/src/
    git clone $GOPATH/src/
  3. Generate changes for the google provider

    make provider VERSION=ga OUTPUT_PATH="$GOPATH/src/" PRODUCT=pubsub
  4. Generate changes for the google-beta provider

    make provider VERSION=beta OUTPUT_PATH="$GOPATH/src/" PRODUCT=pubsub
  5. Confirm that the expected changes were generated

    cd $GOPATH/src/
    git diff -U0
    cd $GOPATH/src/
    git diff -U0

    In both cases, the changes should include:

    diff --git a/google-beta/resource_pubsub_topic.go b/google-beta/resource_pubsub_topic.go
    --- a/google-beta/resource_pubsub_topic.go
    +++ b/google-beta/resource_pubsub_topic.go
    @@ -115 +115 @@ and is not a valid configuration.`,
    -                               Description: `Settings for validating messages published against a schema.`,
    +                               Description: `UPDATED_DESCRIPTION`,
    diff --git a/website/docs/r/pubsub_topic.html.markdown b/website/docs/r/pubsub_topic.html.markdown
    --- a/website/docs/r/pubsub_topic.html.markdown
    +++ b/website/docs/r/pubsub_topic.html.markdown
    @@ -146 +146 @@ The following arguments are supported:
    -  Settings for validating messages published against a schema.
    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
  2. Set required environment variables

    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
    gcloud services enable
  4. Run all linters

    cd $GOPATH/src/
    make lint
    cd $GOPATH/src/
    make lint
  5. Run all unit tests

    cd $GOPATH/src/
    make test
    cd $GOPATH/src/
    make test
  6. Run acceptance tests for Pub/Sub Topic

    cd $GOPATH/src/
    make testacc TEST=./google/services/pubsub TESTARGS='-run=TestAccPubsubTopic_'
    cd $GOPATH/src/
    make testacc TEST=./google-beta/services/pubsub TESTARGS='-run=TestAccPubsubTopic_'

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 #