Introduction: Pulumi simplifies cloud infrastructure provisioning by enabling infrastructure as code. This sample Python code demonstrates creating a Google Cloud Storage bucket using Pulumi.
import pulumi
import pulumi_gcp as gcp
# Create a new GCP storage bucket
bucket = gcp.storage.Bucket("my-bucket")
# Export the bucket name as an output
pulumi.export("bucket_name", bucket.name)
Explanation:
- Import Modules: Includes
pulumiandpulumi_gcpfor Google Cloud Platform. - Bucket Creation: Utilizes
gcp.storage.Bucketto create a new GCP storage bucket, specifying a unique name for the bucket. - Export Output: Exports the bucket name using
pulumi.export, allowing access to the name from other parts of the Pulumi program or command line.
To execute this code:
- Ensure Pulumi and required dependencies are installed.
- Initialize a new Pulumi project using
pulumi new gcp-python. - Navigate to the project directory using
cd gcp-python. - Replace the contents of the
__main__.pyfile with the provided sample code. - Run
pulumi upto create the GCP storage bucket. - Upon deployment completion, access the bucket name via
pulumi stack output bucket_name.
Note: Set up appropriate credentials and permissions to access Google Cloud Storage.
Conclusion: Pulumi offers an efficient way to manage cloud resources in a declarative manner, as shown in this example for creating a Google Cloud Storage bucket using Python and Pulumi.
Want to Listen to This Guide While Working?
Try Speechify — the AI voice reader that helps DevOps engineers consume technical documentation while working in the terminal.