-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,755 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
component: sdk | ||
kind: Improvements | ||
body: Add experimental support for the new transforms systemAdd experimental support | ||
for the new transforms system | ||
time: 2024-03-04T13:12:07.2773112Z | ||
custom: | ||
PR: "234" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.pulumi/ | ||
[Bb]in/ | ||
[Oo]bj/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2016-2024, Pulumi Corporation. All rights reserved. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Pulumi; | ||
|
||
class MyComponent : ComponentResource | ||
{ | ||
public Random Child { get; } | ||
|
||
public MyComponent(string name, ComponentResourceOptions? options = null) | ||
: base("my:component:MyComponent", name, options) | ||
{ | ||
this.Child = new Random($"{name}-child", | ||
new RandomArgs { Length = 5 }, | ||
new CustomResourceOptions {Parent = this, AdditionalSecretOutputs = {"length"} }); | ||
} | ||
} | ||
|
||
class TransformsStack : Stack | ||
{ | ||
public TransformsStack() : base(new StackOptions { XResourceTransforms = {Scenario3} }) | ||
{ | ||
// Scenario #1 - apply a transformation to a CustomResource | ||
var res1 = new Random("res1", new RandomArgs { Length = 5 }, new CustomResourceOptions | ||
{ | ||
XResourceTransforms = | ||
{ | ||
args => | ||
{ | ||
var options = CustomResourceOptions.Merge( | ||
(CustomResourceOptions)args.Options, | ||
new CustomResourceOptions {AdditionalSecretOutputs = {"result"}}); | ||
return new ResourceTransformResult(args.Args, options); | ||
} | ||
} | ||
}); | ||
|
||
// Scenario #2 - apply a transformation to a Component to transform its children | ||
var res2 = new MyComponent("res2", new ComponentResourceOptions | ||
{ | ||
XResourceTransforms = | ||
{ | ||
args => | ||
{ | ||
if (args.Resource.GetResourceType() == "testprovider:index:Random") | ||
{ | ||
var resultArgs = args.Args; | ||
resultArgs = resultArgs.Add("prefix", "newDefault"); | ||
|
||
var options = CustomResourceOptions.Merge( | ||
(CustomResourceOptions)args.Options, | ||
new CustomResourceOptions {AdditionalSecretOutputs = {"result"}}); | ||
|
||
return new ResourceTransformResult(resultArgs, resultOpts); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
}); | ||
|
||
// Scenario #3 - apply a transformation to the Stack to transform all resources in the stack. | ||
var res3 = new Random("res3", new RandomArgs { Length = Output.Secret(5) }); | ||
|
||
// Scenario #4 - Transforms are applied in order of decreasing specificity | ||
// 1. (not in this example) Child transformation | ||
// 2. First parent transformation | ||
// 3. Second parent transformation | ||
// 4. Stack transformation | ||
var res4 = new MyComponent("res4", new ComponentResourceOptions | ||
{ | ||
XResourceTransforms = { args => scenario4(args, "value1"), args => scenario4(args, "value2") } | ||
}); | ||
|
||
ResourceTransformResult? scenario4(ResourceTransformArgs args, string v) | ||
{ | ||
if (args.Resource.GetResourceType() == RandomStringType && args.Args is RandomStringArgs oldArgs) | ||
{ | ||
var resultArgs = new RandomStringArgs | ||
{Length = oldArgs.Length, OverrideSpecial = Output.Format($"{oldArgs.OverrideSpecial}{v}")}; | ||
return new ResourceTransformResult(resultArgs, args.Options); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
// Scenario #3 - apply a transformation to the Stack to transform all (future) resources in the stack | ||
private static ResourceTransformResult? Scenario3(ResourceTransformArgs args) | ||
{ | ||
if (args.Resource.GetResourceType() == "testprovider:index:Random") | ||
{ | ||
var resultArgs = args.Args; | ||
resultArgs = resultArgs.Add("prefix", "stackDefault"); | ||
|
||
var options = CustomResourceOptions.Merge( | ||
(CustomResourceOptions)args.Options, | ||
new CustomResourceOptions {AdditionalSecretOutputs = {"result"}}); | ||
|
||
return new ResourceTransformResult(resultArgs, resultOpts); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private const string RandomStringType = "random:index/randomString:RandomString"; | ||
} | ||
|
||
class Program | ||
{ | ||
static Task<int> Main(string[] args) => Deployment.RunAsync<TransformsStack>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: transformations_dotnet | ||
description: A simple .NET program that uses transformations. | ||
runtime: dotnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2016-2021, Pulumi Corporation. All rights reserved. | ||
|
||
// Exposes the Random resource from the testprovider. | ||
|
||
using Pulumi; | ||
|
||
public partial class Random : Pulumi.CustomResource | ||
{ | ||
[Output("length")] | ||
public Output<int> Length { get; private set; } = null!; | ||
|
||
[Output("result")] | ||
public Output<string> Result { get; private set; } = null!; | ||
|
||
public Random(string name, RandomArgs args, CustomResourceOptions? options = null) | ||
: base("testprovider:index:Random", name, args ?? new RandomArgs(), options) | ||
{ | ||
} | ||
} | ||
|
||
public sealed class RandomArgs : Pulumi.ResourceArgs | ||
{ | ||
[Input("length", required: true)] | ||
public Input<int> Length { get; set; } = null!; | ||
|
||
public RandomArgs() | ||
{ | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
integration_tests/transformations_remote/Transformations.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.