Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static hosting using C# - how to enable #444

Closed
shahiddev opened this issue Jan 21, 2020 · 5 comments
Closed

Static hosting using C# - how to enable #444

shahiddev opened this issue Jan 21, 2020 · 5 comments

Comments

@shahiddev
Copy link

@shahiddev shahiddev commented Jan 21, 2020

I'm trying to create some storage accounts which have static hosting enabled. I know this feature isn't available in the ARM api and there is an example in the docs where a custom dynamic provider is used (for the TS example). I can also see that dynamic providers are not supported in .NET at the moment.

My question is how can enable the static hosting using Pulumi and C#?

If I was able to get the name of the storage account I can try doing this in a similar way to the dynamic provider above either via the CLI or via the Storage SDK but I have the issue with Output to string conversion which I know is fundamental to the way resources are created in Pulumi but is there a way at any point to retrieve the value of the resource as string (or convert it to a string)?

Hope that's clear - any help is appreciated!

@mikhailshilkov

This comment has been minimized.

Copy link
Collaborator

@mikhailshilkov mikhailshilkov commented Jan 21, 2020

You could export the storage account name from your Pulumi program, get it with pulumi stack output.

Alternatively, you could run a CLI command from within the same program but inside an Apply call.

Here is a draft for both:

var storageAccount = new Account("sa", new AccountArgs /*...*/);
return new Dictionary<string, object?>
{
   { "name", storageAccount.Name }, // export the name for external consumption
   { "bla", storageAccount.Name.Apply(v => Process.Start($"echo {v}")) } // calling from within Apply
};
@shahiddev

This comment has been minimized.

Copy link
Author

@shahiddev shahiddev commented Jan 21, 2020

Wow, thanks for the super quick response @mikhailshilkov !

I wonder if I can execute the azure storage sdk command in that apply method?

I realised I'll need the static endpoint url for another step managed by Pulumi, that's not exposed in the API, in your TS example you query the CLI to return it but in my case I need to pass that to an app gateway component that is also being provisioned by Pulumi.

This would be so much simpler if the Azure resource manager supported this out of the box!

@mikhailshilkov

This comment has been minimized.

Copy link
Collaborator

@mikhailshilkov mikhailshilkov commented Jan 21, 2020

You should be able to execute any command (or pretty much any C#) in that Apply. The commands need to be idempotent, because they will run on any pulumi up (and on subsequent previews after the storage account is created).

@mikhailshilkov

This comment has been minimized.

Copy link
Collaborator

@mikhailshilkov mikhailshilkov commented Jan 21, 2020

You can also return data from that Apply, and instead of using it inside the outputs dictionary, place it in your body and then use the output value for the next resource:

var storageAccount = new Account("sa", new AccountArgs /*...*/);
var endpoint = storageAccount.Name.Apply(n => { ...; return endpoint; });
@shahiddev

This comment has been minimized.

Copy link
Author

@shahiddev shahiddev commented Jan 21, 2020

Thanks Mikhail! I had reached the same conclusion on the return parameters!

You've been very helpful - really appreciate it.
I'll close this now but may re-open if if I run into an issue with this approach.

@shahiddev shahiddev closed this Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.