-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Add Service resource support #549
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,3 +169,4 @@ func TestNodejsApprovalRulesExample(t *testing.T) { | |
| }, | ||
| }) | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A Service's main purpose is to group entities within it. Should the example include at least one or two entities?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am going to add parts that would be part of the service then come back to this PR so we can tie it all together. This makes a lot of sense to show a full working example. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| name: yaml-service | ||
| runtime: yaml | ||
| description: | | ||
| Example of provisioning a Service with items via Pulumi YAML. | ||
|
|
||
| This example demonstrates THREE ways to specify the organization: | ||
|
|
||
| 1. AUTOMATIC (provider default): Omit organizationName - provider uses the first | ||
| organization from your Pulumi Cloud account where you are a member/admin. | ||
|
|
||
| 2. EXPLICIT API (getCurrentUser): Call getCurrentUser() to get your default org | ||
| from Pulumi Cloud API and reference it explicitly. | ||
|
|
||
| 3. STACK CONTEXT (pulumi.organization): Use the organization from your current | ||
| stack deployment context (e.g., if deploying org/project/stack, uses "org"). | ||
| Note: This requires using the Pulumi SDK function in your language, not shown | ||
| in this YAML example. See TypeScript/Python examples for usage of | ||
| pulumi.getOrganization(). | ||
|
|
||
| configuration: | ||
| ownerName: | ||
| type: string | ||
| projectName: | ||
| type: string | ||
| stackName: | ||
| type: string | ||
|
|
||
| variables: | ||
| # Get current user info from Pulumi Cloud API | ||
| # Returns the user's default organization (first org where they're a member/admin) | ||
| currentUser: | ||
| fn::invoke: | ||
| function: pulumiservice:index:getCurrentUser | ||
| return: defaultOrganization | ||
|
|
||
| resources: | ||
| # Example 1: Explicit API approach using getCurrentUser() | ||
| # Good for: When you want to be explicit about which org from your account to use | ||
| myServiceExplicit: | ||
| type: pulumiservice:index:Service | ||
| properties: | ||
| organizationName: ${currentUser} | ||
| ownerType: user | ||
| ownerName: ${ownerName} | ||
| name: example-service-explicit | ||
| description: Service using explicit defaultOrganization from getCurrentUser | ||
| properties: | ||
| environment: development | ||
| team: platform | ||
| items: | ||
| - itemType: stack | ||
| name: ${currentUser}/${projectName}/${stackName} | ||
|
|
||
| # Example 2: Automatic approach (provider infers from API) | ||
| # Good for: Quick prototyping, single-org scenarios | ||
| myServiceAutomatic: | ||
| type: pulumiservice:index:Service | ||
| properties: | ||
| # organizationName omitted - provider automatically uses default org from your account | ||
| ownerType: user | ||
| ownerName: ${ownerName} | ||
| name: example-service-automatic | ||
| description: Service using automatic default organization | ||
| properties: | ||
| environment: development | ||
| team: platform | ||
|
|
||
| outputs: | ||
| explicitServiceName: ${myServiceExplicit.name} | ||
| explicitOrganization: ${myServiceExplicit.organizationName} | ||
| automaticServiceName: ${myServiceAutomatic.name} | ||
| automaticOrganization: ${myServiceAutomatic.organizationName} | ||
| userDefaultOrg: ${currentUser} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # Service Resource Example | ||
|
|
||
| This example demonstrates how to create and manage a Service resource in Pulumi Cloud. | ||
|
|
||
| ## Overview | ||
|
|
||
| Services in Pulumi Cloud allow you to group and organize related stacks and environments. This example shows three different approaches for specifying the organization: | ||
|
|
||
| ### 1. Automatic Default (Provider Infers) | ||
| The simplest approach - omit `organizationName` and the provider will automatically use the first organization from your Pulumi Cloud account where you are a member, admin, or billing manager. | ||
|
|
||
| ```yaml | ||
| resources: | ||
| myService: | ||
| type: pulumiservice:index:Service | ||
| properties: | ||
| # organizationName omitted - uses default from your account | ||
| ownerType: user | ||
| ownerName: ${ownerName} | ||
| name: my-service | ||
| ``` | ||
|
|
||
| ### 2. Explicit API Call (`getCurrentUser`) | ||
| Use the `getCurrentUser()` function to explicitly retrieve and reference your default organization from the Pulumi Cloud API: | ||
|
|
||
| ```yaml | ||
| variables: | ||
| currentUser: | ||
| fn::invoke: | ||
| function: pulumiservice:index:getCurrentUser | ||
| return: defaultOrganization | ||
|
|
||
| resources: | ||
| myService: | ||
| type: pulumiservice:index:Service | ||
| properties: | ||
| organizationName: ${currentUser} # Explicitly reference | ||
| ownerType: user | ||
| ownerName: ${ownerName} | ||
| name: my-service | ||
| ``` | ||
|
|
||
| ### 3. Stack Context (`pulumi.getOrganization()`) | ||
| In TypeScript, Python, and other SDK languages, you can use the stack's deployment context: | ||
|
|
||
| **TypeScript:** | ||
| ```typescript | ||
| const service = new pulumiservice.Service("myService", { | ||
| organizationName: pulumi.getOrganization(), // Uses org from stack context | ||
| ownerType: "user", | ||
| ownerName: ownerName, | ||
| name: "my-service", | ||
| }); | ||
| ``` | ||
|
|
||
| **Python:** | ||
| ```python | ||
| service = pulumi_service.Service("my-service", | ||
| organization_name=pulumi.get_organization(), # Uses org from stack context | ||
| owner_type="user", | ||
| owner_name=owner_name, | ||
| name="my-service" | ||
| ) | ||
| ``` | ||
|
|
||
| ## When to Use Each Approach | ||
|
|
||
| - **Automatic**: Best for quick prototyping or when you only have one organization | ||
| - **getCurrentUser()**: Best when you want to be explicit and reference your default org from multiple places | ||
| - **pulumi.getOrganization()**: Best when deploying to different orgs (the stack context determines the org) | ||
|
|
||
| ## Difference Between API Default and Stack Context | ||
|
|
||
| - **getCurrentUser() / Automatic**: Returns the first org from your **Pulumi Cloud account** (e.g., `personal-org`) | ||
| - **pulumi.getOrganization()**: Returns the org from your **current stack deployment** (e.g., if deploying `work-org/infra/prod`, returns `work-org`) | ||
|
|
||
| If you're deploying `work-org/project/stack` but your default account org is `personal-org`: | ||
| - `getCurrentUser()` → `personal-org` | ||
| - `pulumi.getOrganization()` → `work-org` | ||
|
|
||
| ## Running the Example | ||
|
|
||
| The example requires minimal configuration since most values are derived automatically: | ||
|
|
||
| ```bash | ||
| # Only set the owner username (should be your Pulumi Cloud username) | ||
| pulumi config set ownerName <your-pulumi-username> | ||
|
|
||
| # The rest are handled automatically: | ||
| # - organizationName: Derived from getCurrentUser() or omitted for automatic default | ||
| # - projectName/stackName: Used only in the item name, can use pulumi.getProject()/getStack() in other languages | ||
|
|
||
| pulumi up | ||
| ``` | ||
|
|
||
| **Note**: In a real-world scenario using TypeScript or Python, you'd typically use: | ||
| ```typescript | ||
| ownerName: pulumi.getOrganization() // Gets current user/org from stack context | ||
| projectName: pulumi.getProject() // Gets project from stack | ||
| stackName: pulumi.getStack() // Gets stack name | ||
| ``` | ||
|
|
||
| So you wouldn't need to configure these at all - they come from your deployment context automatically. | ||
|
|
||
| ## Converting to Other Languages | ||
|
|
||
| This YAML example can be converted to other Pulumi languages using: | ||
|
|
||
| ```bash | ||
| pulumi convert --language typescript --out ts-service | ||
| pulumi convert --language python --out py-service | ||
| pulumi convert --language go --out go-service | ||
| ``` | ||
|
|
||
| See the [Pulumi convert documentation](https://www.pulumi.com/docs/iac/cli/commands/pulumi_convert/) for more details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: seems like an accidental change here.