Hi, We are evaluating Pulumi and we wonder if the ...
# getting-started
b
Hi, We are evaluating Pulumi and we wonder if the stack references are available when you are working with an Azure blob storage backend? If so, how do you create your stack and reference it? I guess there is no organization available? cfr: https://www.pulumi.com/learn/building-with-pulumi/stack-references/
e
Stack references for the filestate backend are currently just a name so just:
Copy code
const stackRef = new pulumi.StackReference(`${stack}`)
Keep in mind these need to be from the same backend login url. If you login to different filestate urls you can't currently get a stack reference from one while logged into another.
b
Ok thanks I created a shared stack which i would like to reference in the other one. This one is created successfully.
Now when I reference it, is doesn't seem to work
I created an organisation in the pulumi config although.
@echoing-dinner-19531 Do you have an idea at first sight what is wrong here?
e
Hmm gimme a sec to check something
Does
pulumi stack ls --all
show that shared stack?
b
@echoing-dinner-19531 this only shows develop
e
I created an organisation in the pulumi config although.
What do you mean by this?
Also did you use the same
pulumi login
for both of these stacks?
b
I created an organisation in the pulumi config although.
pulumi config set org OrgName
e
organisations aren't supported for the blog storage backend, but that command shouldn't of really affected anything
Actually that
ls
call is really odd. Your develop stack in your screenshot is pulumi-poc-specific-develop, not just develop.
b
ok let me check if i can restart for example
@echoing-dinner-19531 I cant get this working, do you have a working example? using a separate git repository per stack ?
e
I'll see about adding one to the examples repo, bit suspect that this isn't just working so worth me checking if there's a bug here
Well we have https://github.com/pulumi/examples/tree/master/aws-ts-stackreference already, and I just went through that using the filestate backend and it worked. So either we have an azblob specific bug (I'd hope unlikely given we use gocloud.dev/blob for all the different filesystems) or there's something off with your setup.
You could try following that examples readme yourself to sanity check. The only difference you'll have to make for the file backend is that each stack needs a unique name, so I used "dev" for the company stack, "dev-dept" for the department stack and "dev-team" for the team stack that the README tell you to make, and then for setting the config for the team stack the readme says to do:
Copy code
$ pulumi config set companyStack YOUR_ORG/aws-ts-stackreference-company/dev
$ pulumi config set departmentStack YOUR_ORG/aws-ts-stackreference-department/dev
But I did:
Copy code
$ pulumi config set companyStack dev
$ pulumi config set departmentStack dev-dept
because filestate doens't have orgs or projects
b
Maybe a stupid question, is it required that the folder structure is the same ? I splitted the stacks into different repos, maybe that is the issue ?
e
What do you mean repos?
Stacks don't even need to be in a git repo, so that has nothing to do with it. But if your file state is in different folders that won't work.
b
okay thanks! i am getting some errors further 😉
Copy code
pulumi:pulumi:Stack (specific-hohr.specific-dev):
    error: Running program 'C:\work\temp\pulumi-nested\specific\bin\Debug\netcoreapp3.1\specific.dll' failed with an unhandled exception:
    Grpc.Core.RpcException: Status(StatusCode="Unknown", Detail="invocation of pulumi:pulumi:getResource returned an error: unknown resource urn:pulumi:hohr.shared-dev::shared::azure-native:web:AppServicePlan::HoHr.Shared.AppServicePlan", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1646055774.763000000","description":"Error received from peer ipv4:127.0.0.1:53276","file":"..\..\..\src\core\lib\surface\<http://call.cc|call.cc>","file_line":1068,"grpc_message":"invocation of pulumi:pulumi:getResource returned an error: unknown resource urn:pulumi:hohr.shared-dev::shared::azure-native:web:AppServicePlan::HoHr.Shared.AppServicePlan","grpc_status":2}")
       at async Task<InvokeResponse> Pulumi.GrpcMonitor.InvokeAsync(InvokeRequest request)
       at async Task<SerializationResult> Pulumi.Deployment.InvokeRawAsync(string token, SerializationResult argsSerializationResult, InvokeOptions options) x 2
       at async Task<(string urn, string id, Struct data, ImmutableDictionary<string, ImmutableHashSet<Resource>> dependencies)> Pulumi.Deployment.ReadOrRegisterResourceAsync(Resource resource, bool remote, Func<string, Resource> newDependency, ResourceArgs args, ResourceOptions options)
       at async Task Pulumi.Deployment.CompleteResourceAsync(Resource resource, bool remote, Func<string, Resource> newDependency, ResourceArgs args, ResourceOptions options, ImmutableDictionary<string, IOutputCompletionSource> completionSources)
       at async Task<T> Pulumi.Output<T>.GetValueAsync(T whenUnknown)
       at async Task<string> Pulumi.Deployment+EngineLogger.TryGetResourceUrnAsync(Resource resource)
    error: Running program 'C:\work\temp\pulumi-nested\specific\bin\Debug\netcoreapp3.1\specific.dll' failed with an unhandled exception:
    Grpc.Core.RpcException: Status(StatusCode="Unknown", Detail="invocation of pulumi:pulumi:getResource returned an error: unknown resource urn:pulumi:hohr.shared-dev::shared::azure-native:resources:ResourceGroup::HoHr.Shared", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1646055774.771000000","description":"Error received from peer ipv4:127.0.0.1:53276","file":"..\..\..\src\core\lib\surface\<http://call.cc|call.cc>","file_line":1068,"grpc_message":"invocation of pulumi:pulumi:getResource returned an error: unknown resource urn:pulumi:hohr.shared-dev::shared::azure-native:resources:ResourceGroup::HoHr.Shared","grpc_status":2}")
       at async Task<InvokeResponse> Pulumi.GrpcMonitor.InvokeAsync(InvokeRequest request)
       at async Task<SerializationResult> Pulumi.Deployment.InvokeRawAsync(string token, SerializationResult argsSerializationResult, InvokeOptions options) x 2
       at async Task<(string urn, string id, Struct data, ImmutableDictionary<string, ImmutableHashSet<Resource>> dependencies)> Pulumi.Deployment.ReadOrRegisterResourceAsync(Resource resource, bool remote, Func<string, Resource> newDependency, ResourceArgs args, ResourceOptions options)
       at async Task Pulumi.Deployment.CompleteResourceAsync(Resource resource, bool remote, Func<string, Resource> newDependency, ResourceArgs args, ResourceOptions options, ImmutableDictionary<string, IOutputCompletionSource> completionSources)
       at async Task<T> Pulumi.Output<T>.GetValueAsync(T whenUnknown)
       at async Task<string> Pulumi.Deployment+EngineLogger.TryGetResourceUrnAsync(Resource resource)
I created an appserviceplan in a 'shared' stack and trying to create an Azure Webapp in a specific stack , at first sight it goes ine but at runtime some errors occured..
It seems to be able to access the StackReference, as i am able to print the output AppServicePlanId
but I am not able to use it
e
How are you trying to use it? With
Plan.Get
?
b
No, i use the output from the stackreference
this is how it seems to be described on https://www.pulumi.com/docs/intro/concepts/stack/#stackreferences or am I missing something ?
e
Bit of an odd way to write it but that should pretty much work
Copy code
var sharedStack = new Pulumi.StackReference("hohr.shared-dev");
var sharedPlanId = sharedStack.RequireOutput("SharedPlanId");
var resourceGroup = new ResourceGroup("Robtest");
var appService = new Pulumi.AzureNative.Web.WebApp("RobsSpecificApp", new Pulumi.AzureNative.Web.WebAppArgs
{
	ServerFarmId = sharedPlanId,
	ResourceGroupName = resourceGroup.Name
});
Just written up quickly in NPP so might have a typo, but that's a more common way of writing it
b
Yeah, but without the apply method the compiler is nagging about
Cannot implicitly convert type 'Pulumi.Output<object>' to 'Pulumi.Input<string>
i do not like it either 😞
Copy code
var sharedStack = new Pulumi.StackReference("hohr.shared-dev");
        var sharedPlanId = sharedStack.RequireOutput("SharedPlanId").Apply(sharedPlanId => (string)sharedPlanId);

        System.Console.WriteLine(sharedPlanId.ToString());
        var resourceGroup = new ResourceGroup("Robtest");
        var appService = new Pulumi.AzureNative.Web.WebApp("RobsSpecificApp", new Pulumi.AzureNative.Web.WebAppArgs
        {
            ServerFarmId = sharedPlanId,
            ResourceGroupName = resourceGroup.Name
        });
        AppServiceId = appService.Id;
this compiles, but when running the same error applies
I am doubting if it is actually possible
e
That WriteLine won't print anything useful becuase sharedPlanId is an
Output<T>
at that point, but it should work as an input to
ServerFarmId
b
hmmm, am I doing something completely wrong than?
seems like an easy thing but already stuck since friday 😅
e
No I mean leave the
.Apply(id => (string)id)
thats needed because RequireOutput doesn't know what the remote type is. But the
WriteLine(sharedPlanId)
won't print anything useful because
sharedPlanId
is an Output<string> and ToString on an output just prints a warning message.
If you want to print the Id you need to do
sharedPlandId.Apply(id => WriteLine(id))
b
do you have an idea where i might find more information about the related errors
e
b
https://github.com/pulumi/pulumi/issues/9066 i created this one. I already found a related one which was in azure native and they closed it as it was not really meant to be there.