-
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
18 changed files
with
1,328 additions
and
52 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,129 @@ | ||
// Copyright 2016-2024, Pulumi Corporation. All rights reserved. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Pulumi; | ||
using Pulumi.Random; | ||
|
||
class MyComponent : ComponentResource | ||
{ | ||
public RandomString Child { get; } | ||
|
||
public MyComponent(string name, ComponentResourceOptions? options = null) | ||
: base("my:component:MyComponent", name, options) | ||
{ | ||
this.Child = new RandomString($"{name}-child", | ||
new RandomStringArgs { Length = 5 }, | ||
new CustomResourceOptions {Parent = this, AdditionalSecretOutputs = {"special"} }); | ||
} | ||
} | ||
|
||
// Scenario #5 - cross-resource transformations that inject the output of one resource to the input | ||
// of the other one. | ||
class MyOtherComponent : ComponentResource | ||
{ | ||
public RandomString Child1 { get; } | ||
public RandomString Child2 { get; } | ||
|
||
public MyOtherComponent(string name, ComponentResourceOptions? options = null) | ||
: base("my:component:MyComponent", name, options) | ||
{ | ||
this.Child1 = new RandomString($"{name}-child1", | ||
new RandomStringArgs { Length = 5 }, | ||
new CustomResourceOptions { Parent = this }); | ||
|
||
this.Child2 = new RandomString($"{name}-child2", | ||
new RandomStringArgs { Length = 6 }, | ||
new CustomResourceOptions { Parent = this }); | ||
} | ||
} | ||
|
||
class TransformationsStack : Stack | ||
{ | ||
public TransformationsStack() : base(new StackOptions { ResourceTransforms = {Scenario3} }) | ||
{ | ||
// Scenario #1 - apply a transformation to a CustomResource | ||
var res1 = new RandomString("res1", new RandomStringArgs { Length = 5 }, new CustomResourceOptions | ||
{ | ||
ResourceTransforms = | ||
{ | ||
args => | ||
{ | ||
var options = CustomResourceOptions.Merge( | ||
(CustomResourceOptions)args.Options, | ||
new CustomResourceOptions {AdditionalSecretOutputs = {"length"}}); | ||
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 | ||
{ | ||
ResourceTransforms = | ||
{ | ||
args => | ||
{ | ||
if (args.Resource.GetResourceType() == RandomStringType && args.Args is RandomStringArgs oldArgs) | ||
{ | ||
var resultArgs = new RandomStringArgs {Length = oldArgs.Length, MinUpper = 2}; | ||
var resultOpts = CustomResourceOptions.Merge((CustomResourceOptions)args.Options, | ||
new CustomResourceOptions {AdditionalSecretOutputs = {"length"}}); | ||
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 RandomString("res3", new RandomStringArgs { Length = 5 }); | ||
|
||
// Scenario #4 - transformations 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 | ||
{ | ||
ResourceTransforms = { 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() == RandomStringType && args.Args is RandomStringArgs oldArgs) | ||
{ | ||
var resultArgs = new RandomStringArgs | ||
{ | ||
Length = oldArgs.Length, | ||
MinUpper = oldArgs.MinUpper, | ||
OverrideSpecial = Output.Format($"{oldArgs.OverrideSpecial}stackvalue") | ||
}; | ||
return new ResourceTransformResult(resultArgs, args.Options); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private const string RandomStringType = "random:index/randomString:RandomString"; | ||
} | ||
|
||
class Program | ||
{ | ||
static Task<int> Main(string[] args) => Deployment.RunAsync<TransformationsStack>(); | ||
} |
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 |
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Pulumi.Random" Version="4.8.2" /> | ||
</ItemGroup> | ||
|
||
</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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.