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
1 parent
1a6897b
commit 07c0f86
Showing
11 changed files
with
286 additions
and
5 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
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
8 changes: 8 additions & 0 deletions
8
tests/integration/aliases/dotnet/adopt_into_component/step1/Aliases.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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
72 changes: 72 additions & 0 deletions
72
tests/integration/aliases/dotnet/adopt_into_component/step1/Program.cs
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,72 @@ | ||
// Copyright 2016-2019, Pulumi Corporation. All rights reserved. | ||
|
||
using System.Threading.Tasks; | ||
using Pulumi; | ||
|
||
class Resource : ComponentResource | ||
{ | ||
public Resource(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Resource", name, options) | ||
{ | ||
} | ||
} | ||
|
||
// Scenario #2 - adopt a resource into a component | ||
class Component : ComponentResource | ||
{ | ||
public Component(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Component", name, options) | ||
{ | ||
} | ||
} | ||
|
||
// Scenario 3: adopt this resource into a new parent. | ||
class Component2 : ComponentResource | ||
{ | ||
public Component2(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Component2", name, options) | ||
{ | ||
} | ||
} | ||
|
||
// Scenario 4: Make a child resource that is parented by opts instead of 'this'. Fix | ||
// in the next step to be parented by this. Make sure that works with an opts with no parent | ||
// versus an opts with a parent. | ||
|
||
class Component3 : ComponentResource | ||
{ | ||
public Component3(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Component3", name, options) | ||
{ | ||
new Component2(name + "-child", options); | ||
} | ||
} | ||
|
||
// Scenario 5: Allow multiple aliases to the same resource. | ||
class Component4 : ComponentResource | ||
{ | ||
public Component4(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Component4", name, options) | ||
{ | ||
} | ||
} | ||
|
||
|
||
class Program | ||
{ | ||
static Task<int> Main(string[] args) | ||
{ | ||
return Deployment.RunAsync(() => | ||
{ | ||
var res2 = new Resource("res2"); | ||
var comp2 = new Component("comp2"); | ||
new Component2("unparented"); | ||
new Component3("parentedbystack"); | ||
new Component3("parentedbycomponent", new ComponentResourceOptions { Parent = comp2 }); | ||
new Component4("duplicateAliases", new ComponentResourceOptions { Parent = comp2 }); | ||
}); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/integration/aliases/dotnet/adopt_into_component/step1/Pulumi.yaml
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: aliases_adopt_into_component | ||
description: A program that replaces a resource with a new name and alias. | ||
runtime: dotnet |
114 changes: 114 additions & 0 deletions
114
tests/integration/aliases/dotnet/adopt_into_component/step2/Program.cs
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,114 @@ | ||
// Copyright 2016-2019, Pulumi Corporation. All rights reserved. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Pulumi; | ||
|
||
class Resource : ComponentResource | ||
{ | ||
public Resource(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Resource", name, options) | ||
{ | ||
} | ||
} | ||
|
||
// Scenario #2 - adopt a resource into a component. The component author is the same as the component user, and changes | ||
// the component to be able to adopt the resource that was previously defined separately... | ||
class Component : ComponentResource | ||
{ | ||
private Resource resource; | ||
|
||
public Component(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Component", name, options) | ||
{ | ||
// The resource creation was moved from top level to inside the component. | ||
this.resource = new Resource($"{name}-child", | ||
new ComponentResourceOptions | ||
{ | ||
// With a new parent | ||
Parent = this, | ||
// But with an alias provided based on knowing where the resource existing before - in this case at top | ||
// level. We use an absolute URN instead of a relative `Alias` because we are referencing a fixed resource | ||
// that was in some arbitrary other location in the hierarchy prior to being adopted into this component. | ||
Aliases = { new Alias { Urn = "my:module:Resource::res2" } }, | ||
}); | ||
} | ||
} | ||
|
||
// Scenario 3: adopt this resource into a new parent. | ||
class Component2 : ComponentResource | ||
{ | ||
public Component2(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Component2", name, options) | ||
{ | ||
} | ||
} | ||
|
||
|
||
// Scenario 4: Make a child resource that is parented by opts instead of 'this'. Fix | ||
// in the next step to be parented by this. Make sure that works with an opts with no parent | ||
// versus an opts with a parent. | ||
|
||
class Component3 : ComponentResource | ||
{ | ||
public Component3(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Component3", name, options) | ||
{ | ||
new Component2(name + "-child", | ||
new ComponentResourceOptions | ||
{ | ||
Aliases = { new Alias { Parent = options?.Parent, NoParent = options?.Parent == null } }, | ||
Parent = this | ||
}); | ||
} | ||
} | ||
|
||
// Scenario 5: Allow multiple aliases to the same resource. | ||
class Component4 : ComponentResource | ||
{ | ||
public Component4(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Component4", name, | ||
ComponentResourceOptions.Merge( | ||
new ComponentResourceOptions | ||
{ | ||
Aliases = | ||
{ | ||
new Alias { NoParent = true }, | ||
new Alias { NoParent = true } | ||
}, | ||
}, | ||
options)) | ||
{ | ||
} | ||
} | ||
|
||
class Program | ||
{ | ||
static Task<int> Main(string[] args) | ||
{ | ||
return Deployment.RunAsync(() => | ||
{ | ||
// The creation of the component is unchanged. | ||
var comp2 = new Component("comp2"); | ||
// validate that "parent: undefined" means "i didn't have a parent previously" | ||
new Component2("unparented", | ||
new ComponentResourceOptions | ||
{ | ||
Aliases = { new Alias { NoParent = true } }, | ||
Parent = comp2, | ||
}); | ||
new Component3("parentedbystack"); | ||
new Component3("parentedbycomponent", new ComponentResourceOptions { Parent = comp2 }); | ||
new Component4("duplicateAliases", new ComponentResourceOptions { Parent = comp2 }); | ||
}); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
//new Component4("duplicateAliases", { parent: comp2 }); |
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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2016-2019, Pulumi Corporation. All rights reserved. | ||
|
||
using System.Threading.Tasks; | ||
using Pulumi; | ||
|
||
class Resource : ComponentResource | ||
{ | ||
public Resource(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Resource", name, options) | ||
{ | ||
} | ||
} | ||
|
||
class Program | ||
{ | ||
static Task<int> Main(string[] args) | ||
{ | ||
return Deployment.RunAsync(() => | ||
{ | ||
// Scenario #1 - rename a resource | ||
var res1 = new Resource("res1"); | ||
}); | ||
} | ||
} |
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: aliases_rename | ||
description: A program that replaces a resource with a new name and alias. | ||
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-2019, Pulumi Corporation. All rights reserved. | ||
|
||
using System.Threading.Tasks; | ||
using Pulumi; | ||
|
||
class Resource : ComponentResource | ||
{ | ||
public Resource(string name, ComponentResourceOptions options = null) | ||
: base("my:module:Resource", name, options) | ||
{ | ||
} | ||
} | ||
|
||
class Program | ||
{ | ||
static Task<int> Main(string[] args) | ||
{ | ||
return Deployment.RunAsync(() => | ||
{ | ||
// Scenario #1 - rename a resource | ||
// This resource was previously named `res1`, we'll alias to the old name. | ||
var res1 = new Resource("newres1", | ||
new ComponentResourceOptions | ||
{ | ||
Aliases = { new Alias { Name = "res1" } }, | ||
}); | ||
}); | ||
} | ||
} |