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

nextstagepropertiesjson is not working as expected #2

Closed
spotakash opened this issue Oct 24, 2023 · 9 comments
Closed

nextstagepropertiesjson is not working as expected #2

spotakash opened this issue Oct 24, 2023 · 9 comments
Assignees

Comments

@spotakash
Copy link

I followed all instructions and have prerequisites. But, it did not work with following exception.
image

It seems like there is dependency of Az.ResourceGraph for 5.1 while module in automation account is only available for 7.2

If I tried to import 5.1, it throwa dependencies error of Az.Accounts should be > 2.9.1
image
while it is only available for 2.8.0
image

@Wiszanyel Wiszanyel self-assigned this Oct 24, 2023
@Wiszanyel
Copy link
Collaborator

Hi @spotakash, import first the module Az.Accounts, after that import the module Az.ResourceGraph. Both with Runtime version 5.1:
image

Let me know the results.

@spotakash
Copy link
Author

@Wiszanyel I allowed me to import module with 5.1 following sequence suggested by you. But configuration still fails (with new error) You cannot call a method on a null-valued expression. (You cannot call a method on a null-valued expression.)

My nextstagepropertiesjson is as follows.

[

    {
        "stageName": "ubuntu22-preprod",
        "offsetDays": 2,
        "scope": [
            "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        ],
        "filter": {
            "resourceTypes": [
                "microsoft.compute/virtualmachines",
                "microsoft.hybridcompute/machines"
            ],
            "resourceGroups": [
            ],
            "tagSettings": {
                "tags": {
                    "aum-stage": [
                        "preprod"
                    ],
                    "os-name": [
                        "ubuntu22"
                    ]
                },
                "filterOperator": "All"
            },
            "locations": [],
            "osTypes": [
                "Linux"
            ]
        }
    },
    {
        "stageName": "ubuntu22-prod",
        "offsetDays": 4,
        "scope": [
            "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        ],
        "filter": {
            "resourceTypes": [
                "microsoft.compute/virtualmachines",
                "microsoft.hybridcompute/machines"
            ],
            "resourceGroups": [
            ],
            "tagSettings": {
                "tags": {
                    "aum-stage": [
                        "prod"
                    ],
                    "os-name": [
                        "ubuntu22"
                    ]
                },
                "filterOperator": "All"
            },
            "locations": [],
            "osTypes": [
                "Linux"
            ]
        }
    }
]

@helderpinto
Copy link
Owner

@spotakash , can you double check if the MaintenanceConfigurationId runbook parameter was set to a valid Resource ID of an existing Maintenance Configuration (the base one used for dev/test machines)? The resource ID must be in the following format: /subscriptions/<subscription id>/resourcegroups/<resource group name>/providers/microsoft.maintenance/maintenanceconfigurations/<maintenance configuration name>

@spotakash
Copy link
Author

spotakash commented Oct 26, 2023

@helderpinto it is still throwing same error when schedule comes to trigger.
Interestingly, when I test this runbook in test mode, using same parameter it works fine.
I sense, runbook is not able to pick up parameter correctly which were linked as part of schedule. Please note that I am not add ing " " by myself but automatically getting added. Same json works fine when test runbook by same parameters
image

Only this error is available
image

@helderpinto
Copy link
Owner

helderpinto commented Oct 26, 2023

Thank you for reporting this, @spotakash. There were some recent ARG API changes in the query response payload which broke the script. There was also a problem with the script not dealing well with Maintenance Configuration IDs which were not lower-cased. The most recent commit of the Create-StagedMaintenanceConfiguration.ps1 script fixed both issues. Can you please test it and report how it went?

@spotakash
Copy link
Author

spotakash commented Oct 27, 2023

Thanks @helderpinto it moved but throw error as it detects existing maintenance configuration. It seems you may need to fix logic so that it updates existing pre-prod or prod (existing) maintenance configuration with new parameters.
Dev- We trigger but PrePod/Prod will be updated based upon Dev.

Error Message below

Failed
The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: 2:02:34 AM - Error: Code=InvalidResourceLocation; Message=The resource 'ubuntu22-preprod' already exists in location 'eastus' in resource group 'xxx'. A resource with the same name cannot be created in location 'eastus'. Please select a new resource name.

@helderpinto
Copy link
Owner

The logic is prepared to update existing maintenance configurations. It is based on an idempotent ARM template deployment. It seems the ubuntu22-preprod maintenance configuration is being updated with a location property that is different from the one it was created with. Can you please check the deployment details in the resource group where the base maintenance configuration is and validate whether the latest ARM deployment properties eventually conflicted?

image

@spotakash
Copy link
Author

No new deployment were being triggered
image

@spotakash
Copy link
Author

@helderpinto I have resolved the issue by following a workaround. I deleted my previous maintenance configuration and ran the runbook again. It worked as expected and did not show any errors. I think the problem was caused by some intermittent caching issue that made my preprod and prod maintenance configuration appear in a different region than the base maintenance configuration. I verified that the runbook works fine with different parameters as well. You can close this issue now.
Thank you for your guidance here and for fixing the script.

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

3 participants