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

[Question] Multiple Subscriptions.... Why? Need help!!! #493

Closed
marcovanluyk opened this issue Feb 26, 2024 · 10 comments
Closed

[Question] Multiple Subscriptions.... Why? Need help!!! #493

marcovanluyk opened this issue Feb 26, 2024 · 10 comments

Comments

@marcovanluyk
Copy link

Release version

APIOPS 5.1.1

Question Details

Hi all, I am fighting a lot of hours with these problem.

I have 2 Subscriptions: 1 for PROD, and 1 for NonProd. Therefore I have 2 ServiceConnections in DevOps and different variables in my variable group.

Expected behavior

Connection to my Prod Service Connection will be connected to my PROD subscription and the deployment is working fine.

Actual behavior

The Service Connection is connected to 2 Subscritions (PROD and NONPROD). Why? This is the root cause.

Publisher is asking for a subscription-id (set it manually). But if I sent it manually I get the following error: System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/$(AZURE_SUBSCRIPTION_ID)/resourceGroups/API-Management-prod-rg/providers/Microsoft.ApiManagement/service/mxxxx-prod-apim/namedValues/trxxxlity-url?api-version=2022-04-01-preview failed with status code 400. Content is '{"error":{"code":"InvalidSubscriptionId","message":"The provided subscription identifier '$(AZURE_SUBSCRIPTION_ID)' is malformed or invalid."}}'.
at common.HttpPipelineExtensions.Validate(Response response, Uri requestUri)

Reproduction Steps

Start publisher with 2 or more stages with different subscriptions.

Copy link

  Thank you for opening this issue! Please be patient while we will look into it and get back to you as this is an open source project. In the meantime make sure you take a look at the [closed issues](https://github.com/Azure/apiops/issues?q=is%3Aissue+is%3Aclosed) in case your question has already been answered. Don't forget to provide any additional information if needed (e.g. scrubbed logs, detailed feature requests,etc.).
  Whenever it's feasible, please don't hesitate to send a Pull Request (PR) our way. We'd greatly appreciate it, and we'll gladly assess and incorporate your changes.

@vandriot
Copy link
Contributor

Hi @marcovanluyk,

I had the same issue, my apim are in different subscription depending on the environment.
The pipelines provided are just starter pipelines which allow people to modify to meet their specific requirements.

To make ApiOps tool work in my context, I did the following:

  1. Updated the run-publisher-with-env.yaml file to add a new parameter called SERVICE_CONNECTION_NAME_ENV.
    Make sure to report the new parameter to the Set publishing variables task.
    image

  2. Create 2 variables in the apim-automation library, for example SERVICE_CONNECTION_NAME_DEV and SERVICE_CONNECTION_NAME_PRD and put as the value the name of service connection for each environment.

  3. Update the run-publisher.yaml file to set the new parameter SERVICE_CONNECTION_NAME_ENV for both DEV and PRD stages with the variable SERVICE_CONNECTION_NAME_DEV for DEV environment and SERVICE_CONNECTION_NAME_PRD for PRD environment.
    image

Let me know if this solves your issue.

@marcovanluyk
Copy link
Author

marcovanluyk commented Feb 29, 2024

@vandriot Thanks for your reply! I implented your code snippets but I still get the message:

"Multiple subscriptions are accessible. Please set the AZURE_SUBSCRIPTION_ID environment variable manually."

I see in the Set publishing variable section of the PROD deployment that the process is finding 2 subscriptions but I still don't know why. In the first steps of the same pipeline (deploy to Dev and Uat) the pipeline is referencing only 1 subscription....

Here is the code of the publisher pipeline:

image

@waelkdouh
Copy link
Contributor

The powershell script we have causes this. You may have to modify it to adapt to your use case. Our code assumes a single subscription target otherwise it would be confusing.

@marcovanluyk
Copy link
Author

OK! Thanks.... Do you mean the Powershell step....

image

And how can I modify it? Sorry for that question ;-)...

@waelkdouh
Copy link
Contributor

Search the code base for the message you are receiving about setting the subscription manually. This way you will locate the code.

@marcovanluyk
Copy link
Author

Ok. I found it. Thanks....

@vandriot
Copy link
Contributor

@marcovanluyk so it means that your PROD service account has access to more than 1 subscription. You might want to check if it is normal.

I had a similar issue before, I didn't modify the PowerShell script in run-publisher-with-env.yaml.
Instead, I just added the following in my run-publisher.yaml pipeline:

I added a environment variable named AZURE_SUBSCRIPTION_ID and gave it the value of the target subscription.
image

@marcovanluyk marcovanluyk reopened this Feb 29, 2024
@marcovanluyk
Copy link
Author

@vandriot I will check it and give you a feedback.

@guythetechie
Copy link
Contributor

Just for information, the publisher needs to know which subscription ID to use. It gets it from the AZURE_SUBSCRIPTION_ID environment variable.

AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID)

If you've set the AZURE_SUBSCRIPTION_ID variable in your ADO pipeline (either directly in your YAML or in a variable group), the publisher will use it.

If you have not, the publisher will check which subscriptions can be accessed by the pipeline agent. If it can only access one subscription, the publisher will use that subscription. Otherwise, it will throw an error message.

if (-not $env:AZURE_SUBSCRIPTION_ID) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants