Azure : ResourceNotFound from az cli but resource exist in Portal - azure

Facing this "ResourceNotFound" issue (JPG-1), but I can see the logicapp resource in Azure portal(JPG-2)
(ResourceNotFound) The Resource 'Microsoft.Web/sites/us-analytics-dev-dsvm-auto-deletion-logicapp-eastus2' under resource group 'us-analytics-dev-dsvm-auto-deletion-eastus2' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Code: ResourceNotFound
Message: The Resource 'Microsoft.Web/sites/us-analytics-dev-dsvm-auto-deletion-logicapp-eastus2' under resource group 'us-analytics-dev-dsvm-auto-deletion-eastus2' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Note :
Already configured (us-analytics-dev) as default subscription in
cli.
Logicapp resource created through Terraform (Code below : code-1)
Code-1 :(edited)
resource "azurerm_resource_group" "dsvm_auto_deletion_resource_group" {
name = "us-analytics-dev-dsvm-auto-deletion-logicapp-eastus2"
location = "East US 2"
}
resource "azurerm_logic_app_workflow" "dsvm_auto_deletion_logicapp" {
name = "us-analytics-dev-dsvm-auto-deletion-logicapp-eastus2"
location = "East US 2"
resource_group_name = "us-analytics-dev-dsvm-auto-deletion-eastus2"
}

First note I noticed your azurerm_resource_group resource name is the same as your azurerm_logic_app_workflow resource name but I think it is just a typo :)
I tried the same command as you and it didn't work for me, it kept returning empty list, I think something is wrong with the az logicapp command.
After some research I found that there is a package in preview that can be used instead which is logic workflow.
Just past in the following command and install the package and it should work, so for your case it would be something like :
az logic workflow show -g us-analytics-dev-dsvm-auto-deletion-eastus2 --name us-analytics-dev-dsvm-auto-deletion-logicapp-eastus2

Related

How to manage existing resource group in azure with terraform

I am having my azure infrastructure created using terraform.
Now I want to add few resources to existing resource group.
When I did same it is giving error like resources group is already exists.
How can I refer existing resource and no changes to existing resources and tfstate file.
There is a couple of ways to refer existing resource in Azure without making changes.
Use Terraform import
Use Terraform data resource
Terraform import example:
resource "azurerm_resource_group" "example" {
# ...instance configuration...
name = "MyResourceGroup"
}
Run command: terraform import azurerm_resource_group.example \ /subscriptions/MySubscriptionNumber/resourceGroups/MyResourceGroup
Terraform data resource example:
data "azurerm_resource_group" "example" {
name = "MyResourceGroup"
}

Deploy azure resource in prebuilt resource group using terraform

I am having one resource group in my azure subscription name "demoterraform"
Now I would like to create one windows VM in this resource group, So I don't deploy new VM in existing resource group.
Use the azurerm_resource_group data source.
data "azurerm_resource_group" "demo" {
name = "demoterraform"
}
in the rest of the code you can refer to it with a similar expression data.azurerm_resource_group.demo.id.

How can I update ip_configuration of an azurerm_network_interface to add azurerm_public_ip?

I have created an HDInsight cluster with kafka using azurerm_hdinsight_kafka_cluster on a VNet (azurerm_virtual_network) with terraform. Due to which I get instances of Azure's network interface created implicitly by Azure Management Service.
I have also created azurerm_public_ip resources which I intend to associate with the network interfaces which are created implicitly as mentioned above.
This means, I need to update the implicitly created azurerm_network_interface resource with the azurerm_public_ip IP address via public_ip_address_id attribute.
I searched online for any documentation on updating the ip_configuration nested attribute of azurerm_network_interface (created implicitly), but unfortunately, did not find any.
Could anyone help me on this? I have not found any other resource in azurerm as well which might help me achieve this.
I would appreciate if someone could point me to an azurerm resource by which i can associate this or any other way possible.
Thanks in advance :)
How can I update ip_configuration of an azurerm_network_interface to add azurerm_public_ip?
I probably found a solution:
Using a null_resource from terraform for execute a local_exec with an Azure CLI command should do the trick.
Note: Make sure the local system has azure cli installed as prequisite.
e.g.:
resource "null_resource" "foo" {
count = 3
provisioner "local-exec" {
command = <<EOT
az --service-principal -u <USERNAME> -p '<PASSWORD>' --tenant <TENANT-ID>
az network nic ip-config update --resource-group ${azurerm_resource_group.foo.name} --name ${azurerm_network_interface.foo[count.index].ip_configuration[0].name} --nic-name ${azurerm_network_interface.foo[count.index].name} --public-ip-address ${azurerm_public_ip.foo[count.index].id}
EOT
}
}
The command can be referred from the Azure documentation here.

Fetch Azure Resources using Terraform

I want to get a list of Azure resources, example, we have the command Get-AzResourceGroup to get list of resources. Or Get-AzSqlServer -ResourceGroupName "ResourceGroup01" to list SQL Servers from a particular Resource Group. How can we do this in Terraform ?
Actually, you can use the data source:azurerm_resources to list the resources with the type in Azure as you want. But as I test, when I add the resource group, it only returns an empty list. I'm not sure if there is something wrong with my code. If it works as it shows, then it's the thing which you want and the example would like this:
data "azurerm_resources" "example" {
resource_group_name = "example-resources"
type = "Microsoft.Sql/servers"
}
You could authenticate with Azure CLI with terraform and then use the CLI command to get the resources.
az resource list [--location]
[--name]
[--namespace]
[--resource-group]
[--resource-type]
[--subscription]
[--tag]

Terraform - Azure as a provider and limited access account

I want to deploy some resources on Azure with Terraform.
On Azure, I have an account with "Owner rights" on one Resource Group only(RGName). Not at the subscription level.
From my linux server, I installed "az cli" and I did "az login". At this step, everything is OK.
The problem appears when I want to execute terraform to create one resource.
Content of provider.tf (the only one .tf file for now) :
provider "azurerm" {
}
If I do a "terraform plan", it works.
If I add the following line, it fails. Please see the error at the end :
resource "azurerm_virtual_network" "myterraformnetwork" {
name = "myVnet"
address_space = ["10.0.0.0/16"]
location = "eastus"
resource_group_name = "RGName"
tags = {
environment = "Terraform Demo"
}
}
I do not have right on subscription level but I do not need to.
With the Azure WebUI I can create resource on this Resource Group without problem.
The error :
Error: Error ensuring Resource Providers are registered: Cannot register provider Microsoft.DevSpaces with Azure Resource Manager: resources.ProvidersClient#Register: Failure responding to request: StatusCode=403 -- Original Error: autor
est/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client 'accountName' with object id 'IDaccountName' does not have authorization to perform action 'Microsoft.DevSpaces/r
egister/action' over scope '/subscriptions/subscriptionID' or the scope is invalid. If access was recently granted, please refresh your credentials.".
on provider.tf line 1, in provider "azurerm":
1: provider "azurerm" {
Thank you all !
If anyone else has this issue in a corporate (restricted) Azure environment, and doesn't have the patience to register the provider (which may not be necessary if you don't use the specified terraform resource) - have a look at https://github.com/terraform-providers/terraform-provider-azurerm/issues/4440
Specifically, this may help:
provider "azurerm" {
skip_provider_registration = "true"
It obviously won't help if you actually need the resource that fails to get registered (in our case it was Cannot register provider Microsoft.DevSpaces with Azure Resource Manager, but the resource will be variable depending on your environment and what Terraform decides to support)
For your issue, when you have the Owner role of the resource group, you can create new resources or manage the existing resources as you want. So permission is no problem. With the test on my side, it works well using a user has the Owner role of the resource group.
As the error shows, I think the possible reason is that you have multiple subscriptions in the tenant and the current subscription is not the right one which the user has the right permission. You can try to take a check and set the right subscription via the command:
az account set --subscription subscription_id
Thank you for your answer.
I got this when I execute "az account list" :
"cloudName": "AzureCloud",
"id": "***********0d43",
"isDefault": true,
"name": "BU*******",
"state": "Enabled",
"tenantId": "TENANTID",
"user": {
"name": "LOGINNAME",
"type": "user"
I do not have rights on this subscription but it is the only one that I know.
On Azure WebUI I can see that the RGName is on the same subscription.
This is a capture from Azure WebUI on the RGName :
Azure WebUI
Thank you
You may need to register the Resource provider by clicking on register as shown in below screenshot under subscription id.

Resources