How do i get the name / resource identifier by the resource display name in ARM template?
I have the user group called "Developer" and unique identifier as "xxxxxxxxxxx" under the resource type "Microsoft.ApiManagement/service/groups"
By the resource display name "Developer", how can i get the identifier (xxxxxxxxxxx) ?
you can use resourceId() function for that:
resourceId('Microsoft.ApiManagement/service/groups', 'ApiManagementName', 'Developer')
Reading: https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-resource#resourceid
Related
I have script to delete all Tags.
I get Tags yet:
Get-AzTag
Name Count
displayName 2
App 1
Department 1
Env 1
Owner 1
I can't find which resource is attached.
Get-AzResource
Any idea?
thanks
Thanks #Gill-Bates, According to SO-thread it says,
A tag or value that is already associated with a resource or resource group cannot be removed. Before using Remove-AzTag, use the Tag parameter of the Set-AzResourceGroup cmdlet to delete the tag or values from the resource or resource group.
Update-AzTag -ResourceId xyz-Tag $tags -Operation Delete
xyz is resource id
Output:
References taken from:
https://github.com/Azure/azure-cli/issues/11761
https://debbiesmspowerbiazureblog.home.blog/2020/04/27/azure-tagging-with-powershell-example/
https://stackoverflow.com/a/54162388
Policy as code - Azure - Terraform
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/policy_definition
The output is an id. This id needs to be used as a variable for a policy assignment.
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group_policy_assignment
How is this written in terraform?
Does the terraform apply need to be separate for each definition and assignment?
You can simply pass the azurerm_policy_definition output to resource azurerm_resource_group_policy_assignment like in the example you find in the DOC
resource "azurerm_resource_group_policy_assignment" "example" {
name = "example"
resource_group_id = azurerm_resource_group.example.id
policy_definition_id = azurerm_policy_definition.example.id # This is the output of azurerm_policy_definition resource
...
...
}
It looks like you are just starting with Terraform, but it's very easy to pass output of one resource to another and Terraform will make sure to deploy policy_definition before resource_group_policy_Assignment.
Assuming the name of the block is called policy as shown in terraform website.
The reference in policy assignment to the ID will look like-
azurerm_policy_definition.policy.id
Please read on the documentation in terraform for reference resources.
https://www.terraform.io/language/expressions/references#resources
https://www.terraform.io/language/expressions/references#references-to-resource-attributes
I use data "azurerm_key_vault_secret" in Terraform to pull data from Azure Vault
Now I want to pull secret of specific version, I tried: version = "719f0d55d1a04c6b862430e00d61b9ae"
but it fails with Error: "version": this field cannot be set:
According to the resource's documentation, version is an exported attribute not an argument. The difference is that attributes are used as resource outputs in other terraform code, e.g. azurerm_key_vault_secret.var2.version, whereas arguments are values that you're allowed to specify as inputs to the resource.
I have almost 20 resources in azure, 4 of them have been given Tags #
{"Office1work"="work"}
{"Office2practice"="Practice"}
{"Office3practice"="Practice"}
{"Office4practice"="Practice"}
Now I want to get the resources whose Tag names start with the keyword "Office".
I know to get a resource by a TagName,for example "hello", I simply use the following command,
get-azureRmResource -TagName "Hello"
How can I use the -Tagname property of get-azurermresource to give me all resources whose tags are starting with the keyword "Office" ?
Or is there any other good method to get all resources whose Tags start with a particular string?
Thanks :)
You can use this code snippet:
$resources = Get-AzureRmResources
$resources.foreach{ if ($PSItem.tags.keys -match '^Office') { $PSItem } }
First you get all the resources in the subscription, then you filter out all the resource whose tags do not match the 'Office' "expression".
as #LotPings points out, it would probably make more sense to filter without saving to a temporary variable:
$resources = Get-AzureRmResources|Where-Object {$_.tags.keys -match "^Office"}
Also, I didnt notice you were asking for a starts with filter, so you should use ^Office as a more strict filter (if you need to).
This is a slightly stupid question! that I can't quite remember the answer to.
if you try to create a new resource group, where one already exists and then don't update it when prompted you get an output like this
ResourceGroupName : DjangoCMS
Location : westeurope
ProvisioningState : Deleting
Tags :
Resources :
Name Type Location
============= =================================== ==========
DJangoCMSnic1 Microsoft.Network/networkInterfaces westeurope
PublicIP1 Microsoft.Network/publicIPAddresses westeurope
DJangoNet Microsoft.Network/virtualNetworks westeurope
ResourceId : /subscriptions/{subscriptionid}/resourceGroups/DjangoCMS
I am sure that there is a cmdlet that gives that output, but I can't for the life of me find it! Can anyone help a clearly ailing memory...
Specifically I am looking for the thing that gives the above output, it may have been an old cmdlet that has changed what it outputs but it would be nice to know. (I'm not going mad)
Find-AzureRmResource -ResourceGroupNameContains TESTNAME works, but the output format is not like what you want. It lists the resources one by one:
Name : derektest
ResourceId : /subscriptions/a679c265-5ef2-48fe-8378-5f435b48536b/resourceGroups/VS-derektest-Group/providers/microsoft.visualstudio/account/derektest
ResourceName : derektest
ResourceType : microsoft.visualstudio/account
ResourceGroupName : VS-derektest-Group
Location : australiaeast
SubscriptionId : a679c265-5ef2-48fe-8378-5f435b48536b
Tags : {}
Name : derektest/TPtest
ResourceId : /subscriptions/a679c265-5ef2-48fe-8378-5f435b48536b/resourceGroups/VS-derektest-Group/providers/microsoft.visualstudio/account/derektest/pro
ject/TPtest
ResourceName : derektest/TPtest
ResourceType : microsoft.visualstudio/account/project
ResourceGroupName : VS-derektest-Group
Location : northcentralus
SubscriptionId : a679c265-5ef2-48fe-8378-5f435b48536b
As for Get-AzureRmResource, it worked fine in previous build, but not working currently. Maybe it's an issue needs to be fixed. See details here.
I believe you are looking for:
Find-AzureRmResource -ResourceGroupNameContains TESTNAME
Doc for it is here.