Download and deploy Terraform

Application Design Center lets you generate and export Terraform code for your templates and applications to a local machine or a GitHub repository.

Exporting Terraform code lets you maintain and deploy applications with your own CI/CD tools. The exported Terraform files automatically register your application in App Hub to enable runtime monitoring in Security Command Center. Externally deployed applications are treated as unmanaged applications. To use managed Application-centric Google Cloud features such as design-time security assessments and tracing security findings to their source, deploy an application using App Design Center.

The system generates the following Terraform files:

  • main.tf: Infrastructure code that includes a module for each component in the template.
  • outputs.tf: Exposes information about infrastructure components that are deployed.
  • variables.tf: Declares name, type, and description for variables used in the main.tf file.
  • input.tfvars: Defines values for variables used in the main.tf file.
  • providers.tf: Defines labels that help Terraform interact with Google Cloud APIs and resources.

For background information, see Overview of Terraform on Google Cloud.

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
Export generated Terraform code locally or to a source control repository Application Admin (roles/designcenter.applicationAdmin), or
Application Editor (roles/designcenter.applicationEditor)

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

Export Terraform code

If you want to maintain your templates and applications outside of Google Cloud, you can generate Terraform and export to your local machine or to your code repository.

Export locally

You can export Terraform code generated from a template or from an application.

Template

  1. In the Google Cloud console, go to the Templates page.

    Go to Templates

  2. Click the Template ID that you want to export.

  3. Click Get Code.

    The system downloads a zip file to your local computer. You can deploy the application using your own deployment tools and workflows.

Application

  1. In the Google Cloud console, go to the Applications page.

    Go to Applications

  2. Click the Application name that you want to export.

  3. Click Get Code.

    The system downloads a zip file to your local computer. You can deploy the application using your own deployment tools and workflows.

Export to your repository

To maintain your templates through your source code management repository, you can export templates and applications to GitHub. You can then use your existing version control workflows, and trigger builds, tests, and deployments using your own CI/CD pipeline.

Connect to your repository

To create a Developer Connect connection between your GitHub repository and your management project, do the following:

  1. Change your organization policy to add the following services to your allowlist:

    1. developerconnect.googleapis.com.
    2. secretmanager.googleapis.com.

    For steps to change your organization policy, see Using the restrict resource service usage constraint.

  2. Create a Developer Connect connection to your GitHub repository, including the following:

    1. Select Enable data residency.
    2. Link the repository where you want to export your application.

    For steps to create a connection and link a repository, see Connect GitHub.

  3. To copy the repository URI, do the following:

    1. Open the Developer Connect Git repositories page.
    2. In the Repositories table, click More Options and select Copy resource path.

Generate and export

To generate Terraform code and export to your GitHub repository, do the following:

Template

  1. Identify your space ID.

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

    Replace the following:

  2. Identify the template ID for the template that you want to export.

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

    Replace the following:

  3. Generate your template's Terraform code, and export to GitHub.

    gcloud design-center spaces application-templates generate APPLICATION_TEMPLATE \
        --space=SPACE \
        --project=PROJECT \
        --location=LOCATION \
        --developer-connect-export-config-repo-uri=DEVELOPER_CONNECT_EXPORT_CONFIG_REPO_URI \
        --developer-connect-export-config-dir=DEVELOPER_CONNECT_EXPORT_CONFIG_DIR \
        --developer-connect-export-config-branch=DEVELOPER_CONNECT_EXPORT_CONFIG_BRANCH
    

    Replace the following:

    • APPLICATION_TEMPLATE: The template ID of the template that you want to export.
    • SPACE: Your space ID.
    • PROJECT: Your management project ID.
    • LOCATION: Your location ID.
    • DEVELOPER_CONNECT_EXPORT_CONFIG_REPO_URI: The Developer Connect repository resource path that you copied in Connect to your repository, such as projects/my-project/locations/us-central1/connections/my-connection/gitRepositoryLinks/my-repo. The repository link must be in the same location (LOCATION) as your space.
    • DEVELOPER_CONNECT_EXPORT_CONFIG_DIR: The directory path relative to the root of your GitHub repository, such as terraform/my-template (or / for the root directory).
    • DEVELOPER_CONNECT_EXPORT_CONFIG_BRANCH: The branch in your GitHub repository.

    For more information, see the gcloud design-center spaces application-templates generate command.

  4. View your repository to verify that the template was exported successfully.

Application

  1. Identify your space ID.

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

    Replace the following:

  2. Identify the application ID for the application that you want to export.

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

    Replace the following:

  3. Generate your application's Terraform code, and export to GitHub.

    gcloud design-center spaces applications generate APPLICATION \
        --space=SPACE \
        --project=PROJECT \
        --location=LOCATION \
        --developer-connect-export-config-repo-uri=DEVELOPER_CONNECT_EXPORT_CONFIG_REPO_URI \
        --developer-connect-export-config-dir=DEVELOPER_CONNECT_EXPORT_CONFIG_DIR \
        --developer-connect-export-config-branch=DEVELOPER_CONNECT_EXPORT_CONFIG_BRANCH
    

    Replace the following:

    • APPLICATION: The application ID of the application that you want to export.
    • SPACE: Your space ID.
    • PROJECT: Your management project ID.
    • LOCATION: Your location ID.
    • DEVELOPER_CONNECT_EXPORT_CONFIG_REPO_URI: The Developer Connect repository resource path that you copied in Connect to your repository, such as projects/my-project/locations/us-central1/connections/my-connection/gitRepositoryLinks/my-repo. The repository link must be in the same location (LOCATION) as your space.
    • DEVELOPER_CONNECT_EXPORT_CONFIG_DIR: The directory path relative to the root of your GitHub repository, such as terraform/my-app (or / for the root directory).
    • DEVELOPER_CONNECT_EXPORT_CONFIG_BRANCH: The branch in your GitHub repository.

    For more information, see the gcloud design-center spaces applications generate command.

  4. View your repository to verify that the application was exported successfully.

What's next