silly-smartphone-71988
06/07/2022, 11:46 AMpublic class Sample : ComponentResource
{
private List<Pulumi.AzureNative.RecoveryServices.ProtectionContainer> protectionContainers;
public Sample(ResourceName resourceName, ComponentResourceOptions? options = null) : base(resourceName.Type, resourceName.Name, options)
{
this.protectionContainers = new List<Pulumi.AzureNative.RecoveryServices.ProtectionContainer>();
}
public Create(Output<string> name)
{
var protectionContainer = new RecoveryServices.ProtectionContainer("fooName", new RecoveryServices.ProtectionContainerArgs
{
ContainerName = name,
FabricName = "Azure",
Properties = new Pulumi.AzureNative.RecoveryServices.Inputs.AzureWorkloadContainerArgs
{
[...]
},
ResourceGroupName = this.args.ResourceGroup,
VaultName = this.recoveryServicesVault.Name.Apply(t => t)
}
this.protectionContainers.Add(protectionContainer);
}
public WithBackupFileShare(Output<string> protectedcontainername)
{
var protectionContainer = GetProtectionContainer(protectionContainerName); //always gets null
var _ = new RecoveryServices.ProtectedItem(args.Name, new RecoveryServices.ProtectedItemArgs
{
ContainerName = protectionContainerName,
[...]
},
new CustomResourceOptions { DependsOn = {
protectionContainer //need a Resource descendent here thus why I need a RecoveryServices.ProtectionContainer
}, Parent = protectionContainer });
}
public RecoveryServices.ProtectionContainer? GetProtectionContainer(Output<string> containerName)
{
//how to get back the RecoveryServices.ProtectionContainer from this.protectionContainers?
//when using a for each I have to use item.Name.Apply to compare the name and this returns an Output<> not a RecoveryServices.ProtectionContainer
//i tried to set a local variable from within the apply but it does not work. the variable stays as null
RecoveryServices.ProtectionContainer? protectionContainer = null;
foreach (var item in this.protectionContainers)
{
var test = Output.Tuple<string,string,RecoveryServices.ProtectionContainer>(item.Name, containerName,item).Apply(t =>
{
if (t.Item1 == t.Item2) {
protectionContainer = t.Item3; //does not work protectionContainer stays null
return t.Item3; //
}
else{
return null;
}
});
protectionContainer = test; //does not work because var is of type Output<RecoveryServices.ProtectionContainer>
}
return protectionContainer; //returns null
}
}
public RecoveryServices.ProtectionContainer? GetProtectionContainer(Output<string> containerName)
{
int idx = -1;
int counter = 0;
while (idx == -1 && counter < this.protectionContainers.Count)
{
_ = Output.Tuple(this.protectionContainers[counter].Name, containerName).Apply(t =>
{
if (t.Item1 == t.Item2) {
idx = counter;
return true;
}
else{
return false;
}
});
}
if(idx != -1)
{
return this.protectionContainers[idx];
}
else
{
return null;
}