1. Answers
  2. Using Gcp Folder With Deploymentmanager

Using Gcp Folder With Deploymentmanager

Introduction

In this guide, we will create a Pulumi program to manage a Google Cloud Platform (GCP) folder using Deployment Manager. We will use TypeScript as the programming language, following the organization’s system prompts. The key services involved are GCP Folder and Deployment Manager.

Step-by-Step Explanation

Step 1: Install Pulumi and GCP Provider

First, ensure you have Pulumi installed. If not, you can install it using the following command:

curl -fsSL https://get.pulumi.com | sh

Next, install the Pulumi GCP provider:

npm install @pulumi/gcp

Step 2: Create a New Pulumi Project

Create a new Pulumi project by running:

pulumi new typescript

Follow the prompts to set up your project.

Step 3: Define the GCP Folder

In your index.ts file, define the GCP folder resource. Here is an example:

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const folder = new gcp.organizations.Folder("my-folder", {
    displayName: "My Folder",
    parent: "organizations/123456789",
});

Step 4: Define the Deployment Manager Configuration

Next, define the Deployment Manager configuration. You can use a YAML file to specify the deployment configuration. Create a file named deployment.yaml with the following content:

resources:
- name: my-deployment
  type: gcp-types/deploymentmanager-v2beta2:deployments
  properties:
    target:
      config:
        content: |
          resources:
          - name: my-folder
            type: gcp-types/cloudresourcemanager-v2:folders
            properties:
              displayName: My Folder
              parent: organizations/123456789          

Step 5: Deploy the Resources

Finally, deploy the resources using Pulumi:

pulumi up

This command will show you a preview of the changes and ask for confirmation to apply them.

Conclusion

In this guide, we have demonstrated how to create and manage a GCP folder using Pulumi and Deployment Manager. We covered the installation of Pulumi and the GCP provider, setting up a new Pulumi project, defining the GCP folder and Deployment Manager configuration, and deploying the resources. Pulumi makes it easy to manage cloud resources using familiar programming languages and tools.

Full Code Example

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

// Define the GCP folder resource
const folder = new gcp.organizations.Folder("my-folder", {
    displayName: "My Folder",
    parent: "organizations/123456789",
});

// Define the Deployment Manager configuration
const deployment = new gcp.deploymentmanager.Deployment("my-deployment", {
    target: {
        config: {
            content: \`resources:
            - name: my-folder
              type: gcp-types/cloudresourcemanager-v2:folders
              properties:
                displayName: My Folder
                parent: organizations/123456789\`
        }
    }
});

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up