Setting value of runbook process step dynamically

Im creating a runbook that creates azure infrastructure - step 1 create rg , step 2 create vm using arm . how do i set the name of the rg dynamically created in step 1 in step 2 , where i need to select a rg along with azure account . the deploy a arm template step explicitly needs a rg selected … Please advise. Thank you !

Hi @vinayak.tillu,

Thanks for reaching out.

Depending on how you’re creating the resource group in step 1, you could store the value in an output variable (documentation: https://octopus.com/docs/projects/variables/output-variables), and then in step 2 you could set the value of your resource group to that output variable.

Do you think that will work in your setup?

Please let me know what you think.

Thanks,
Jeremy

Hi Jeremy

Thank you for reaching out. I will look into out-variables

I could perhaps show you whats going on through the screen shots or a shared session

The step where I need to select resource group based on the azure account selected before , requires resource group to exist .

Hi @vinayak.tillu,

If you select the Azure account, then click the bind button to the right, it should allow you to type in a variable in the resource group section, like in this screenshot:

Please let me know if it works on your end and if the test run works with the output variable.

Please let me know if you have any questions.

Thanks,
Jeremy

Thanks Jeremy. That worked for me.
I had another quick question.
While creating dynamic infra I also need to create deployment target and environment in octopus for it.
Could you point me to octopus powershell that helps with it.
Vinayak

Hi @vinayak.tillu,

You’re very welcome! I’m glad to hear it worked.

You can do that via some API calls.

For registering a tentacle, you can check this repository: https://github.com/OctopusDeploy/OctopusDeploy-Api/tree/master/REST/PowerShell/Targets
It has register listening, polling, and SSH target scripts.

I don’t see any example scripts for creating an environment, but what I like to do when I want to do something with an API call is, I will open the Developer Tab on my browser with F12, and go to the Network tab, then finally I will manually do the thing I want to do with an API call within the portal and watch the API calls and look at the headers. So for your case, I would go to the environments page, click add environment, and then hit F12 and watch the API call as you create the environment.

I did it myself and it looks like its a POST call to http://192.168.139.160/api/Spaces-1/environments , with the body of something like:

{
   "Name":"Teeeeest",
   "Description":"",
   "UseGuidedFailure":false,
   "AllowDynamicInfrastructure":false,
   "SortOrder":-1,
   "ExtensionSettings":[
  
   ]
}

Please let me know if that answers your question or if you need more help.

Thanks,
Jeremy

Thank you Jeremy. Environments work. So i create an environment and when i can add the environment detail to ARM templates octopus extension which installs a polling agent , creates a deployment target and also adds it to the environment. Now the only challenge is i have an existing lifecycle and a default phase to which i need to add this environment. I was looking into the api for that but if you could provide some insights, that will be great. Thank you !