I am trying to figure out if I can connect multiple tenants to a single project though the cli or if I will need to script this out with powershell. Does anyone know if this is possible?
This would be very helpful as I have over 1000 tenants that will need to be individually connected to two different projects. I really dont want to manually click through all of them in the web gui.
Yes, that is absolutely possible with the Octopus Deploy Rest API. I need to whip up a quick script as a sample you can modify to fit your needs, but I should have something for you tomorrow.
Question: is it all of your tenants, or a subset of them? Are they grouped via tenant tag?
Thanks so much for your fast response!!! I really appreciate your offer to help me find my way along the right path here!
We have all of our customers tagged as tenant type Customer so that would be amazing if I could connect all of those tags to the 2 projects I need to connect them to!
The syntax for tenant tag is [Tenant Tag Set Name]/[Tenant Tag Name], for example Tenant Type/Customer.
It has a what-if switch, you can set that to true to test out anything. It won’t save to your instance.
It has a max number of tenants to change. Set that to 10-15 to test things out for a small handful of tenants before letting it rip.
It prints out a changelog of what it would’ve done (when it what if mode) or what it did (when not in what-if mode)
It will ensure all the environments specified are assigned to the project/tenant relationship. If you specified 2 environments and had a pre-existing tenant/project relationship with only 1 environment it will add the second environment.
It doesn’t take into account variables because…yikes! (The scripts to change tenant variables is quite…complex to write)
Wow!! This is amazing! Thank you so much for putting that together for us! I will test it out in our lab environment later today but this will be so helpful! Thank you so much!!!
You are welcome! It actually triggered an internal conversation within in the team. I think we are going to add more bulk functionality examples like this in our docs. I do think we need to ad it to the UI, but this will be a good alternative until then.
I would recommend running it for 25-50 tenants at a time instead of the full 1000, just to be safe (easier to undo 25-50 tenants vs 1000)
Late addition to this thread, but there may be a small issue in the C# code that is referenced in the link.
In the case where a tenant is already connected to some projects (tenant.ProjectEnvironments count > 0), a null reference is hit when looping through the environments to add the project.
The fix appears to be simple: just call
ConnectToProjectAndEnvironments
in an if block that checks for an empty projectEnvironments similar to the way that the empty tenant.ProjectEnvironments case is handled.