Import components

Importing custom Terraform modules into Application Design Center lets you add your own reusable Google Cloud configurations as components in your application templates. When you import a Terraform module, App Design Center creates a component template in your space's catalog so developers can reuse your established design decisions and policies.

For background on authoring Terraform modules for Google Cloud, see the following:

Before you begin

To perform the tasks in this document, ask your administrator to grant you the necessary roles on the app-enabled folder or management project, as listed in the following table:

Task Required roles
Import Terraform modules as custom components Application Design Center Admin (roles/designcenter.admin), or
Application Design Center User (roles/designcenter.user)

For more information about roles, see Access control with IAM.

Configure and import your modules

Complete the following steps to connect to GitHub, create a metadata file, and import a Terraform module.

Connect to your repository using Developer Connect

Create a Developer Connect connection to the GitHub repository where you store your Google Cloud Terraform modules. You'll use this connection when you import.

  1. Create a Developer Connect connection.

    For steps, see Connect to GitHub.

  2. Create a Developer Connect repository link.

    For steps, see Add repository links to existing connections.

Optional: Prepare your Terraform module metadata

When you import your Terraform module, you can supply your own metadata, or let App Design Center create a metadata file for you.

For example, the following is a metadata.yaml file that you might create for a service account:

  spec:
    info:
      actuationTool:
        flavor: Terraform
        version: ">= 1.3"
    interfaces: # Optional
      variables:
        - name: service_account
          connections:
            - source:
                source: github.com/terraform-google/terraform-google-service-accounts
                version: ">= 4.4"
              spec:
                outputExpr: email
    requirements:
      roles: # Optional after IAM integrations
        - level: Project
          roles:
            - roles/iam.serviceAccountUser
            - roles/iap.admin
            - roles/run.admin
            - roles/iam.serviceAccountAdmin
      providerVersions:
        - source: hashicorp/google
          version: ">= 6, < 7"
        - source: hashicorp/google-beta
          version: ">= 6, < 7"
    ui: # Optional
      input:
        variables:
          ca_root_module:
            name: ca_root_module
            title: CA Root Module
          service_account:
            name: service_account
            title: Service Account

Import from your repository

You can create an App Design Center component by importing a Terraform module that is based on a single Google Cloud product. If you make changes to your Terraform module in your repository, repeat these steps to import your changes.

To import your Terraform module, do the following:

  1. Identify the catalog where you want to create your component.

      gcloud design-center spaces catalogs list \
      --project=PROJECT \
      --location=LOCATION \
      --space=SPACE
    

    Replace the following:

    For more information, see gcloud design-center spaces catalogs list.

  2. Create a catalog template in your space's private catalog.

      gcloud design-center spaces catalogs templates create COMPONENT_TEMPLATE \
      --project=PROJECT \
      --catalog=CATALOG \
      --location=LOCATION \
      --space=SPACE \
      --template-category=component-template
    

    Replace the following:

    • COMPONENT_TEMPLATE: The template ID for the component template that you want to create.
    • PROJECT: Your management project ID.
    • CATALOG: Your catalog ID.
    • LOCATION: Your location ID.
    • SPACE: Your space ID.

    For more information, see gcloud design-center spaces catalogs templates create.

  3. Create a catalog template revision based on the Terraform module in your repository.

      gcloud design-center spaces catalogs templates revisions create REVISION \
      --project=PROJECT \
      --catalog=CATALOG \
      --location=LOCATION \
      --space=SPACE \
      --template=COMPONENT_TEMPLATE \
      --developer-connect-repo=DEVELOPER_CONNECT_REPO \
      --developer-connect-repo-ref=DEVELOPER_CONNECT_REPO_REF \
      --developer-connect-repo-dir=DEVELOPER_CONNECT_REPO_DIR \
      --metadata=METADATA
    
    

    Replace the following:

    • REVISION: The revision ID for the revision that you want to create.
    • PROJECT: Your management project ID.
    • CATALOG: Your catalog ID.
    • LOCATION: Your location ID.
    • SPACE: Your space ID.
    • COMPONENT_TEMPLATE: The template ID that you created in the previous step.
    • DEVELOPER_CONNECT_REPO: The Developer Connect repository to use as a source. For example, projects/my-project/locations/us-central1/connections/my-connection/gitRepositoryLinks/my-repo.
    • DEVELOPER_CONNECT_REPO_REF: The Git branch or tag in the repository. For example, refs/tags/v1.0.0 or refs/heads/main.
    • DEVELOPER_CONNECT_REPO_DIR: The directory in the repository. For example, modules/my-product.
    • To specify the Terraform module metadata, do one of the following:
      • To use your own metadata file, replace METADATA with your metadata.yaml file.
      • To automatically use metadata files located in your repository, leave the --metadata flag unspecified.

    For more information, see gcloud design-center spaces catalogs templates revisions create.

  4. Share your catalog with other spaces.

      gcloud design-center spaces catalogs shares create SHARE \
      --project=PROJECT \
      --catalog=CATALOG \
      --location=LOCATION \
      --space=SPACE \
      --destination-space=DESTINATION_SPACE
    

    Replace the following:

    • SHARE: The share ID for the share that you want to create.
    • PROJECT: Your management project ID.
    • CATALOG: Your catalog ID.
    • LOCATION: Your location ID.
    • SPACE: Your space ID.
    • DESTINATION_SPACE: The destination space ID.

    For more information, see gcloud design-center spaces catalogs shares create.

Create an application template using imported components

Create an application template using your imported components and Google-provided components.

  1. Create a new application template.

      gcloud design-center spaces application-templates create APPLICATION_TEMPLATE \
      --project=PROJECT \
      --location=LOCATION \
      --space=SPACE
    

    Replace the following:

    • APPLICATION_TEMPLATE: The template ID for the application template that you want to create.
    • PROJECT: Your management project ID.
    • LOCATION: Your location ID.
    • SPACE: Your space ID.

    For more information, see gcloud design-center spaces application-templates create.

  2. Identify the template revision URIs for the components that you want to add to the template.

      gcloud design-center spaces shared-templates list \
      --project=PROJECT \
      --location=LOCATION \
      --space=SPACE \
      --uri
    

    Replace the following:

    For more information, see gcloud design-center spaces shared-templates list.

  3. Add a component to your application template.

      gcloud design-center spaces application-templates components create COMPONENT \
      --project=PROJECT \
      --location=LOCATION \
      --space=SPACE \
      --application-template=APPLICATION_TEMPLATE \
      --shared-template-revision-uri=SHARED_TEMPLATE_URI
    

    Replace the following:

    • COMPONENT: The component ID for the component that you want to add to the template.
    • PROJECT: Your management project ID.
    • LOCATION: Your location ID.
    • SPACE: Your space ID.
    • APPLICATION_TEMPLATE: The template ID for the application template where you are adding the component.
    • SHARED_TEMPLATE_URI: The component shared template URI. For example, projects/my-project/locations/us-central1/spaces/my-space/sharedTemplates/my-shared-template/revisions/rev1.

    For more information, see gcloud design-center spaces application-templates components create.

  4. Add a second component to your template.

      gcloud design-center spaces application-templates components create COMPONENT_2 \
      --project=PROJECT \
      --location=LOCATION \
      --space=SPACE \
      --application-template=APPLICATION_TEMPLATE \
      --shared-template-revision-uri=SHARED_TEMPLATE_URI_2
    

    Replace the following:

    • COMPONENT_2: The component ID for the second component that you want to add to the template.
    • PROJECT: Your management project ID.
    • LOCATION: Your location ID.
    • SPACE: Your space ID.
    • APPLICATION_TEMPLATE: The template ID for the application template where you are adding the component.
    • SHARED_TEMPLATE_URI_2: The second component shared template URI. For example, projects/my-project/locations/us-central1/spaces/my-space/sharedTemplates/my-shared-template/revisions/rev1.

    For more information, see gcloud design-center spaces application-templates components create.

  5. Create a connection between the two components.

      gcloud design-center spaces application-templates components connections create CONNECTION \
      --project=PROJECT \
      --location=LOCATION \
      --space=SPACE \
      --application-template=APPLICATION_TEMPLATE \
      --component=COMPONENT \
      --destination-component-uri=SHARED_TEMPLATE_URI_2
    

    Replace the following:

    • CONNECTION: The connection ID for the connection that you want to add to the template.
    • PROJECT: Your management project ID.
    • LOCATION: Your location ID.
    • SPACE: Your space ID.
    • APPLICATION_TEMPLATE: The template ID for the application template where you are adding the component.
    • SHARED_TEMPLATE_URI_2: The second component shared template URI. For example, projects/my-project/locations/us-central1/spaces/my-space/sharedTemplates/my-shared-template/revisions/rev1.

    For more information, see gcloud design-center spaces application-templates components connections create.

What's next