Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create resource in GCP #2632

Closed
cvatsops opened this issue Nov 14, 2024 · 5 comments
Closed

Can't create resource in GCP #2632

cvatsops opened this issue Nov 14, 2024 · 5 comments
Assignees
Labels
kind/question Questions about existing features resolution/fixed This issue was fixed

Comments

@cvatsops
Copy link

cvatsops commented Nov 14, 2024

What happened?

Hello Team ,

I am trying to create a GCS bucket using pulumi as backend code which is serving via a fast api server .

Here's the request i am using to create the resource:

curl -X POST "http://127.0.0.1:8000/create-bucket" -H "Content-Type: application/json" -d '{
    "bucket_name": "fastapi-pulumi-bucket",
    "location": "europe-west3",
    "force_destroy": true
}'

I have even setup the gcp project using pulumi config set gcp:project $projectname.

And below is the error i am facing:

{"detail":"\n code: 255\n stdout: Updating (aws):\n\n@ updating....\n    pulumi:pulumi:Stack aws-aws running warning: unable to detect a global setting for GCP Project.\n@ updating....\n +  gcp:storage:Bucket fastapi-pulumi-bucket creating (0s)\n +  gcp:storage:Bucket fastapi-pulumi-bucket creating (0s) error:   sdk-v2/provider2.go:520: sdk.helper_schema: project: required field is not set: [email protected]\n +  gcp:storage:Bucket fastapi-pulumi-bucket creating (0s) error: 1 error occurred:\n +  gcp:storage:Bucket fastapi-pulumi-bucket **creating failed** error: 1 error occurred:\n    pulumi:pulumi:Stack aws-aws running error: update failed\n@ updating......\n    pulumi:pulumi:Stack aws-aws **failed** 1 error; 1 warning\nDiagnostics:\n  pulumi:pulumi:Stack (aws-aws):\n    warning: unable to detect a global setting for GCP Project.\n    Pulumi will rely on per-resource settings for this operation.\n    Set the GCP Project by using:\n        `pulumi config set gcp:project <project>`\n    error: update failed\n\n  gcp:storage:Bucket (fastapi-pulumi-bucket):\n    error:   sdk-v2/provider2.go:520: sdk.helper_schema: project: required field is not set: [email protected]\n    error: 1 error occurred:\n    \t* project: required field is not set\n\nResources:\n    1 unchanged\n\nDuration: 3s\n\n stderr: "}% 

Example

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import pulumi
from pulumi_gcp import storage
from pulumi.automation import select_stack, Stack
import os


app = FastAPI()

os.environ['PULUMI_CONFIG_PASSPHRASE'] = "******"


class BucketRequest(BaseModel):
    bucket_name: str
    location: str 
    force_destroy: bool = False


def create_gcs_bucket(bucket_name: str, location: str, force_destroy: bool):
    bucket = storage.Bucket(
        bucket_name,
        location=location,
        force_destroy=force_destroy
    )
    pulumi.export("bucket_name", bucket.name)


@app.post("/create-bucket")
async def create_bucket(request: BucketRequest):
    # Use an existing stack
    stack_name = "aws"  
    try:
        # Select the existing stack
        stack = select_stack(
            stack_name=stack_name,
            project_name="aws",
            program=lambda: create_gcs_bucket(request.bucket_name, request.location, request.force_destroy)
        )
        
     
        up_result = stack.up()
        
        return {
            "message": f"Bucket '{request.bucket_name}' created successfully",
            "output": up_result.outputs,
        }

    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

Output of pulumi about

CLI          
Version      3.138.0
Go Version   go1.23.2
Go Compiler  gc

Plugins
KIND      NAME        VERSION
resource  automation  0.1.0
resource  gcp         8.9.1
language  python      unknown

Host     
OS       darwin
Version  15.1
Arch     x86_64

This project is written in python: executable='/Users/chaitanyavats/IdeaProjects/pulumi/venv/bin/python' version='3.12.4'

Current Stack: organization/aws/aws

TYPE                  URN
pulumi:pulumi:Stack   urn:pulumi:aws::aws::pulumi:pulumi:Stack::aws-aws
pulumi:providers:gcp  urn:pulumi:aws::aws::pulumi:providers:gcp::default_8_9_1
pulumi:providers:gcp  urn:pulumi:aws::aws::pulumi:providers:gcp::default_8_8_1


Found no pending operations associated with aws

Backend        
Name           abc
URL            file://~
User           chaitanyavats
Organizations  
Token type     personal

Dependencies:
NAME               VERSION
fastapi            0.115.5
Flask              3.1.0
pip                24.3.1
pulumi-automation  0.1.0
pulumi_gcp         8.9.1
setuptools         75.4.0
uvicorn            0.32.0
wheel              0.45.0

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@cvatsops cvatsops added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Nov 14, 2024
@Frassle Frassle transferred this issue from pulumi/pulumi Nov 14, 2024
@VenelinMartinov
Copy link
Contributor

VenelinMartinov commented Nov 14, 2024

Hi @cvatsops. Thanks for posting your problem here.

The error message suggests you need to set a project for your bucket. Did that not work?
EDIT: I see that you are using Automation API, did you try setting the config on the Automation API stack like the example here: https://www.pulumi.com/docs/iac/packages-and-automation/automation-api/getting-started-automation-api/#configure-your-provider-plugins?

@VenelinMartinov VenelinMartinov added kind/question Questions about existing features and removed kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Nov 14, 2024
@cvatsops
Copy link
Author

Hi @VenelinMartinov I have already set the gcp project using pulumi config set gcp:project project_name.
Is there any other way to set it?

@cvatsops
Copy link
Author

Hi @cvatsops. Thanks for posting your problem here.

The error message suggests you need to set a project for your bucket. Did that not work? EDIT: I see that you are using Automation API, did you try setting the config on the Automation API stack like the example here: https://www.pulumi.com/docs/iac/packages-and-automation/automation-api/getting-started-automation-api/#configure-your-provider-plugins?

Can you instead provide the example for GCP.

@VenelinMartinov
Copy link
Contributor

Yeah, it looks like you are using Automation API. Please take a look at https://www.pulumi.com/docs/iac/packages-and-automation/automation-api/getting-started-automation-api/#configure-your-provider-plugins

Also, a great place to find help with questions related to pulumi is the pulumi community slack channel: https://slack.pulumi.com/

@VenelinMartinov
Copy link
Contributor

VenelinMartinov commented Nov 14, 2024

Can you instead provide the example for GCP.

You'd need to adapt the instructions for the GCP provider: https://www.pulumi.com/registry/packages/gcp/installation-configuration/#authenticate-using-the-cli to work with the automation API: https://www.pulumi.com/docs/iac/packages-and-automation/automation-api/getting-started-automation-api/#configure-your-provider-plugins

something like:

stack.set_config("gcp:project", auto.ConfigValue(value="my_project"))

Note that the Automation API is a somewhat advanced feature, you might have an easier time starting off with one of the "Getting Started" guides.

@VenelinMartinov VenelinMartinov self-assigned this Nov 14, 2024
@VenelinMartinov VenelinMartinov added the resolution/fixed This issue was fixed label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Questions about existing features resolution/fixed This issue was fixed
Projects
None yet
Development

No branches or pull requests

2 participants