1. Hosting a web application with Firebase Hosting

    TypeScript

    When you want to host a web application with Firebase Hosting using Pulumi, you'll leverage the capabilities of the Google Cloud Platform (GCP) provider. Firebase Hosting is a production-grade web content hosting platform that lets you quickly and securely deploy web apps and static content to a global content delivery network (CDN).

    The following Pulumi program in TypeScript will help you set up Firebase Hosting for your web application. We'll be defining a site through Firebase Hosting and creating a new site version which we will then release. The Site resource represents your Firebase site, and the Release resource is used to deploy new content to your site.

    The process consists of these steps:

    1. Setting up a new Firebase project or using an existing one,
    2. Creating a new Firebase site using Site resource,
    3. Uploading files to be hosted,
    4. Creating a version and a release to deploy the files using Version and Release resources.

    We'll start with step 1 and 2, create a new Site resource, and configure some properties.

    import * as pulumi from "@pulumi/pulumi"; import * as gcp from "@pulumi/gcp"; const config = new pulumi.Config(); const projectName = config.require("gcpProject"); const siteId = "your-site-id"; // Choose a unique name for your Firebase site // Create a new Firebase Hosting site const site = new gcp.firebase.HostingSite("mySite", { siteId: siteId, project: projectName, }); // Next, you would typically use Pulumi to upload your site's files to Google Cloud Storage. // However, this step involves procedures outside the scope of Pulumi's Infrastructure-as-Code. // You would include commands or a CI/CD workflow to upload the content to Firebase hosting buckets. // Once files are uploaded, you need to create a version resource. const version = new gcp.firebase.HostingVersion("myVersion", { siteId: siteId, // Other configurations related to headers, redirects, and rewrites can be set here. // The actual files should be uploaded to Firebase through Firebase CLI or another method // since Pulumi is not designed to handle file uploads directly. }); // Finally, create a release to make the version live. const release = new gcp.firebase.HostingRelease("myRelease", { siteId: siteId, versionName: version.name, message: "Deploying my web application", }); export const siteName = site.siteId; export const siteUrl = site.url; export const versionName = version.name; export const releaseName = release.name;

    In the program, replace "your-site-id" with a unique identifier for your Firebase Hosting site. Note that this program assumes you have existing content to be hosted which should be handled typically through Firebase CLI by running firebase deploy.

    This program simply sets up the necessary resources through Pulumi and references them. After that, you need to deploy the actual files using Firebase CLI or an equivalent method outside of Pulumi, since the deployment of web files is not something Pulumi manages directly.

    When deploying using Pulumi, ensure you have the appropriate credentials set up to interact with Google Cloud. This usually means that you've run gcloud auth login and gcloud config set project YOUR_PROJECT_NAME with your project's ID.

    Lastly, don't forget to run pulumi up to deploy the resources specified in the program.

    For further reading, please refer to the following documentation: