Hi all! Pulumi seems like a great tool, and I'm co...
# general
n
Hi all! Pulumi seems like a great tool, and I'm considering it as a replacement for Terraform inside my org. Question, though: is it possible to create new GCP projects, or do I have to pre-create one using the CLI before I can use Pulumi? We have an existing multi-project IaC repo using Terraform that I'd like to port mostly intact.
m
You can use Pulumi to create a new GCP project: https://www.pulumi.com/registry/packages/gcp/api-docs/organizations/project/ So if you're currently using Terraform to manage the GCP projects, you can replicate this 1:1 with Pulumi. But it's not required, you can also create the projects through other means and point Pulumi to deploy resources into the existing project.
n
Thanks, @modern-zebra-45309. I see that the quickstart actually has the
${PROJECT}
in the YAML, is it possible to use Pulumi without that config? All of the docs show how to retrieve a project, but none actually create it.
m
Yeah, I think it's generally more common that orgs have an IT or infrastructure unit that manages orgs and projects, and then hands them off to the dev teams, which is reflected in the docs and examples.
n
I'd like to avoid creating projects outside of Pulumi or another IaC system, since we don't have many Ops Engineers on staff, and a lot of the existing teams rely on using GitHub for that thing.
1
m
That makes a lot of sense, and it's probably the dream of most IaC people to work in a world where everything is managed through a unified IaC solution 😉 Sadly, most of us are not living in such a world 😢
Do you have a link to the quickstart? I can probably give you a hint how to make it work without the project
If you're referring to https://www.pulumi.com/docs/clouds/gcp/get-started/review-project/ you'd have to put the GCP project resource into the program, prior to creating the bucket
If this is your first time working with Pulumi, I think my recommendation is to just go through the quickstart with a manually-created GCP project and then start a new Pulumi project where you start your Pulumi program with the creation of the GCP project. You will probably have to explicitly create a provider (instead of using the default provider) based on the output of your Pulumi-created GCP project: https://www.pulumi.com/registry/packages/gcp/api-docs/provider/ This should be pretty straightfoward once you get going with Pulumi but it requires some familiarity with how Pulumi works.
If you want to see an example of this pattern, have a look at the GKE tutorial: https://www.pulumi.com/registry/packages/kubernetes/how-to-guides/gke/ You'll see that it first creates the Kubernetes cluster (which in your case would be the GCP project) and then uses the information provided by this resource (such as the endpoint and CA certificate) to create a Kubernetes provider for this cluster (the
clusterProvider
). This provider is then passed to all resources that are created on the Kubernetes cluster, e.g.,
const ns = new k8s.core.v1.Namespace(name, {}, { provider: clusterProvider });
tells Pulumi to use the
clusterProvider
to make the namespace.) In your case, you make the GCP project, then you create a GCP provider for this particular project, and then you pass this specific provider to the resources you want to create in that project.
Alternatively, it seems like you can pass the
project
as an input to GCP Pulumi resources. This would actually already work with the quickstart:
Copy code
import pulumi
from pulumi_gcp import storage, organizsations

# Create a new GCP project
my_project = organizations.Project("my_project",
    name="My Project",
    project_id="your-project-id",
    org_id="1234567")

# Create a Google Cloud resource (Storage Bucket)
bucket = storage.Bucket("my-bucket", project=my_project.project_id, location="US")

# Export the DNS name of the bucket
pulumi.export("bucket_name", bucket.url)
n
Excellent, I think the provider configuration is what I'm looking for; rather than having it automatically built based on the YAML definition. Unfortunately, I also can't take the easy path - since we're already committed here. 😄
Thank you so much for your help, this should get me started on the right path.
👍 1
m
Yes, I think you'll be happiest with the provider approach in the long term.