GithubHelp home page GithubHelp logo

azure / aztfexport Goto Github PK

View Code? Open in Web Editor NEW
1.5K 40.0 172.0 7.98 MB

A tool to bring existing Azure resources under Terraform's management

Home Page: https://azure.github.io/aztfexport/

License: Mozilla Public License 2.0

Go 97.59% Makefile 0.16% Shell 2.09% Dockerfile 0.17%
terraform iac azure devops tool terraform-azurerm

aztfexport's Introduction

Microsoft Azure Export for Terraform

A tool to bring your existing Azure resources under the management of Terraform.

Video (v0.12.0)

Video

Goal

Azure Export for Terraform exports supported resources into Terraform state and generate the corresponding Terraform configuration. Both the Terraform state and configuration are expected to be consistent with the resources' remote state, i.e., terraform plan shows no diff. The user then is able to use Terraform to manage these resources.

It supports both the Terraform AzureRM provider and the Terraform AzAPI provider.

Non Goal

The Terraform configurations generated by aztfexport are not meant to be comprehensive and do not ensure that the infrastructure can be fully reproduced from said generated configurations. For details, please see limitations).

Install

From Release

Precompiled binaries and Window MSI are available at Releases.

From Go toolchain

go install github.com/Azure/aztfexport@latest

From Package Manager

Windows

winget install aztfexport

Homebrew (Linux/macOS)

brew install aztfexport

dnf (Linux)

Supported versions:

  • RHEL 8 (amd64, arm64)
  • RHEL 9 (amd64, arm64)
  1. Import the Microsoft repository key:

    rpm --import https://packages.microsoft.com/keys/microsoft.asc
    
  2. Add packages-microsoft-com-prod repository:

    ver=8 # or 9
    dnf install -y https://packages.microsoft.com/config/rhel/${ver}/packages-microsoft-prod.rpm
    
  3. Install:

    dnf install aztfexport
    

apt (Linux)

Supported versions:

  • Ubuntu 20.04 (amd64, arm64)
  • Ubuntu 22.04 (amd64, arm64)
  1. Import the Microsoft repository key:

    curl -sSL https://packages.microsoft.com/keys/microsoft.asc > /etc/apt/trusted.gpg.d/microsoft.asc
    
  2. Add packages-microsoft-com-prod repository:

    ver=20.04 # or 22.04
    apt-add-repository https://packages.microsoft.com/ubuntu/${ver}/prod
    
  3. Install:

    apt-get install aztfexport
    

AUR (Linux)

yay -S aztfexport

Prerequisites

aztfexport requires a terraform executable installed in the $PATH with version >= v0.12.

How it Works

aztfexport leverages aztft to identify the Terraform resource type corresponding to an Azure resource ID. Then it runs terraform import under the hood to import each resource. Afterwards, it runs tfadd to generate the Terraform HCL code for each imported resource.

Usage

Read the Azure Export documentation which covers scenarios and usage.

Config

aztfexport will create a configuration file at $HOME/.aztfexport/config.json. This file is aim to be managed by command aztfexport config [subcommand], which includes following subcommands:

  • get: Get a config item
  • set: Set a config item
  • show: Show the full configuration

Currently, the following config items are supported:

  • installation_id: A UUID created on first run. If there is Azure CLI or Azure Powershell installed on the current machine, the UUID will be the same value among these tools. Otherwise, a new one will be created. This is used as an identifier in the telemetry trace.
  • telemetry_enabled: Enables telemetry. We use telemetry to identify issues and areas for improvement, in order to optimize this tool for better performance, reliability, and user experience. If you wish to disable our telemetry, set this to false.

Limitations

Visit this page on the Azure Export for Terraform documentation that discusses the currently known limitations of the tool.

Additional Resources

  • The aztfexport Github Page: Everything about aztfexport, including comparisons with other existing import solutions.
  • aztft: A Go program and library for identifying the correct Terraform AzureRM provider resource type on the Azure resource id.
  • tfadd: A Go program and library for generating Terraform configuration from Terraform state.

aztfexport's People

Contributors

adamhancock avatar cedrox avatar crgarcia12 avatar koudaiii avatar magodo avatar microsoft-github-policy-service[bot] avatar ms-henglu avatar mybayern1974 avatar nexxai avatar russellbanks avatar stemamsft avatar testwill avatar wuxu92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aztfexport's Issues

aztfy don't connect to the right Azure subscription

I try to uses aztfy to export and import into teraform files (.tf) the resources of an resource group.

  • Before to launch the aztfy command I executed the below commands to set the right subscription on which the resource group and its resources are located :

az login # to connect to the Azure tenant with an account which have contributor rights to the resource group
az account set --subscription "Shared Infrastructure Dev/Test" # to design the right subscription on default (Id : da2e245c-1da4-409b-9b54-81016ca9ae8f)

We can see that I well connected to the good subscription :

jbouchet@MY-DESKTOP:/mnt/c/_DevOps/aztfy_test_build_tf_files$ az account list --query "[?isDefault]"
[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "XXXX-XXXX-XXXX-XXXX-XXXX",
    "id": "da2e245c-1da4-409b-9b54-81016ca9ae8f",
    "isDefault": true,
    "managedByTenants": [],
    "name": "Shared Infrastructure Dev/Test",
    "state": "Enabled",
    "tenantId": "XXXX-XXXX-XXXX-XXXX-XXXX",
    "user": {
      "name": "[email protected]",
      "type": "user"
    }
  }
]
  • Then I executed the command :

aztfy sandbox-training-zguerrouj-resource-group

  • aztfy returned me the below error message :
 exporting arm template of resource group sandbox-training-zguerrouj-resource-group: POST
  https://management.azure.com/subscriptions/c4869d66-56dd-4ead-a65a-6a07eb7fec22/resourcegroups/sandbox-training-zguerrouj-resource-group/exportTemplate
  --------------------------------------------------------------------------------
  RESPONSE 404: 404 Not Found
  ERROR CODE: SubscriptionNotFound
  --------------------------------------------------------------------------------
  {
    "error": {
      "code": "SubscriptionNotFound",
      "message": "The subscription 'c4869d66-56dd-4ead-a65a-6a07eb7fec22' could not be found."
    }
  }
  --------------------------------------------------------------------------------
  • Question :

Why aztfy don't works ?

And I don't understand why aztfy try to connect to the subscription "c4869d66-56dd-4ead-a65a-6a07eb7fec22", because it's not the subscription where is located my resource group and its resources.
The good subscription id is : da2e245c-1da4-409b-9b54-81016ca9ae8f

Continue if failed to import some resource

Currently, the tool will fail and error out on any error. While, it should be more robust to continue terrafying other resources and give a report on the problematic ones at the end.

Remote state

If running terrafy with remote state, and you run multiple times on different resource groups, will terrafy overwrite the remote state file, or append?

Ability to import multiple resource groups

Adding ability to import multiple resource groups rather than only one.

Currently, we leverage ARM template to list resources inside a resource group and get the inter-resource dependencies. Unfortunately, ARM template only provide dependencies within one resource group, but isn't smart enough to get cross resource group dependencies. This means the generated TF config might has incomplete resource dependencies.

E.g. Using aztfy to import infra provisioned by below cfg, the resulted NIC will only have dependency on azurerm_resource_group.test2, but not on the subnet.

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  name     = "acctestRG-mgd1"
  location = "westus"
}

resource "azurerm_resource_group" "test2" {
  name     = "acctestRG-mgd2"
  location = "westus"
}

resource "azurerm_virtual_network" "test" {
  name                = "acctestvn-321"
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location
  address_space       = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "test" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.test.name
  virtual_network_name = azurerm_virtual_network.test.name
  address_prefixes     = ["10.0.2.0/24"]
}

resource "azurerm_network_interface" "test" {
  name                = "acctestni-321"
  location            = azurerm_resource_group.test2.location
  resource_group_name = azurerm_resource_group.test2.name

  ip_configuration {
    name                          = "primary"
    subnet_id                     = azurerm_subnet.test.id
    private_ip_address_allocation = "Dynamic"
  }
}

cannot register provider

Original Error: Cannnot register providers: Microsoft.RecoveryServices, Microsoft.DBforMariaDB, Microsoft.SecurityInsights, Microsoft.DataLakeAnalytics, Microsoft.DesktopVirtualization, Microsoft.HealthcareApis, Microsoft.TimeSeriesInsights, Microsoft.NotificationHubs,
  Microsoft.ManagedServices, Microsoft.StoragePool, Microsoft.DevTestLab, Microsoft.Maps, Microsoft.DataProtection, Microsoft.DataLakeStore, Microsoft.DataMigration, Microsoft.StreamAnalytics, Microsoft.AppPlatform, Microsoft.AVS, Microsoft.ServiceFabric, Microsoft.Relay,
  Microsoft.MixedReality, Microsoft.CustomProviders, Microsoft.ServiceFabricMesh. Errors were: Cannot register provider Microsoft.RecoveryServices with Azure Resource Manager: resources.ProvidersClient#Register: Failure responding to request: StatusCode=403 -- Original
  Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client 'XXXXXXXXXXX' with object id 'XXXXXXXXXXX' does not have authorization to perform action
  'Microsoft.RecoveryServices/register/action' over scope '/subscriptions/XXXXXXXXXXX' or the scope is invalid. If access was recently granted, please refresh your credentials.".

Aztfy also not able to get the correct client id from the env

output in doc

Hello,
Possible to update the readme with the output folder ?
Thanks

Cant install aztfy

Tried to install aztfy via the go toolchain as per recommended in the readme file.

go install github.com/Azure/aztfy@latest

However, got the following error

go: downloading github.com/Azure/aztfy v0.2.1-0.20220501011900-25cfa4857d8b
go: github.com/Azure/aztfy@main (in github.com/Azure/[email protected]):
	The go.mod file for the module providing named packages contains one or
	more replace directives. It must not contain directives that would cause
	it to be interpreted differently than if it were the main module.

I have azcli and terraform installed, and I am using a MacOS with iTerm2

Resource mapping file - bug?

Hi,

I am currently working on creating a shell in Terraform of an APIM for a new environment / subscription based off one that was manually created and configured in another, when I run aztfy on the resource group there are more than 1000 resources as there are a lot of API's deployed through it ect.

I have managed to filter this down in the resource mapping file to 22 resources we want Terraform to create apart of this shell, when I input that file to aztfy it still marks to import all the resources it could automatically map but I can see that a few resources I needed to manually map such as identity providers are now mapped. I though the resource mapping file would be explicit to the only resources aztfy would go to import, is this expected behavior?

For now I will work through the list removing the mapped entries for the resources we don't want to import, also as some possible enhancements from my use so far of aztfy which looks like a great tool in its early stages:

  1. DEL key : remove the generated mapping for a selected resource, i.e skipping it. This would make it a lot easier going through the list and marking resources to be skipped.
  2. Be able to filter on the mapped names, i.e filter down to resources that are mapped to a azurerm_resource_group.

Error Parsing Keyvault Nested Item

Hi! It appears that there's an issue parsing more than 2-3 segments of the keyvault arm template (AFAIK). Let me know if you need more context or logs.

image

Importing Application Gateway with Custom WAF Rules does not work

If you have an Azure Application Gateway in WAF_V2 SKU, it imports fine using the inbuilt WAF rules on the Application Gateway.

However, if you use a separate WAF policy and assign these to specific HTTP Listeners on the Application Gateway, these are not recognized or imported.

These would need to go into each specific HTTP Listener block such as the below

  http_listener {
    name   = "listener-web-public-443"
    frontend_ip_configuration_name   = "public_ipconfig"
    frontend_port_name   = "443"
    protocol   = "Https"
    require_sni   = true
    host_name   = "www.mytestwebsite.com"
    ssl_certificate_name   = "my_public_cert"
    firewall_policy_id   = "/subscriptions/xxxxx-xxxxx-xxxxx-xxxxx-xxxx/resourceGroups/rg-my-appgw/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/waf-appgw-block"
  }

Only resource group is imported

aztfy version: 0.20.0
terraform version: 0.13.5

  • I created a resource group with bunch of storage accounts and ran aztfy - worked successfully.
  • Later I decided to delete the code directory and ran import again - now only resource group is imported.

Not sure state is being cached somewhere else, because along with code I delete local state file as well.

Error importing frontdoor

When importing an Azure Front Door instance, the following error is thrown:

exit status 1

  Error: parsing Resource ID "/subscriptions/[redacted]/resourceGroups/[redacted]/providers/Microsoft.Network/frontdoors/[redacted]": parsing
  "/subscriptions/[redacted]/resourceGroups/hlbi-profisee-mdm-dev/providers/Microsoft.Network/frontdoors/[redacted]": parsing segment "staticFrontDoors": expected the segment
  "frontdoors" to be "frontDoors"

aztfy bug #2

The tool appears to create the subnets without defining the subnet address space within the subnet.

This in turn when attempting to use the TF code generates the following error.

AddressPrefixStringCannotBeNullOrEmpty

Haq

aztfty unable to export resource group more that 200 templates

Hello,

i have following error when doing an import :

aztfy XXXX
exporting arm template of resource group XXXXX: resources.GroupsClient#ExportTemplate: Failure sending request: StatusCode=0 -- Original
Error: autorest/azure: Service returned an error. Status= Code="ExportTemplateResourcesLimitExceeded" Message="Export template is not supported
for resource groups that have more than '200' resources."
<<<

Please help. Thank you

Split output into multiple files

A ressource group with hundreds of ressources in will lead to a "big" unclear main.tf.

To make the exported terraform configuration more clearer, I would suggest to split the write out into multiple output files.
As a seperator the ressource type could be used which can also be used as the name for the output file.

Examples:

  • azurerm_subnet will be written to azurerm_subnet.tf
  • azurerm_network_security_rule will be written to azurerm_network_security_rule
  • ...

To make that behavior optional, an parameter like --split_configuration can be introduced.
As an "extension" of that feature, an user based "grouping" could be imagine so that the user is able to say

I want to put azurerm_subnet, azurerm_virtual_network, ... into the file network.tf

Support data disks

Hi,
currently it does not seem to be able to recognize azurerm_managed_disk and azurerm_virtual_machine_data_disk_attachment resources in azure

Greetings
Klaas

Update Azure Service Template

  • Update Azure Service Template to align with Foundation update.
  • remove Warning N-Tier Application Patterns IaaS and PaaS

Error while importing Key Vault: malformed resource address: azurerm_key_vault

Running aztfy 0.4.0 and importing a RG containing a key vault (with one secret) and a VM.

Key Vault resource type was not recognized so trying to manually select the resource type.
Selected azurerm_key_vault (through auto completion) and got this error:

image

Same error when trying to map the secret, selected azurerm_key_vault_secret and got the same error

Imported properties fails validation on terraform plan because of case sensitivity.

azurerm_network_security_rule seams to import properties from Azure without any regard of case sensitivity.

"azurerm_network_security_rule": /SUBSCRIPTIONS/{}/RESOURCEGROUPS/{}/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/{}/SECURITYRULES/{}",

Reference
A NSG rule in Azure;

"properties": {
                "securityRules": [
                    {
                        "name": "SMB",
                        "properties": {
                            "protocol": "TCP", // upper case
                            "sourcePortRange": "*",
                            "destinationPortRange": "445",
                            "sourceAddressPrefix": "*",
                            "destinationAddressPrefix": "*",
                            "access": "Allow",
                            "priority": 310,
                            "direction": "Inbound",
                            "sourcePortRanges": [],
                            "destinationPortRanges": [],
                            "sourceAddressPrefixes": [],
                            "destinationAddressPrefixes": []
                        }
                    }
                ]
            }
        },

At ‘terraform plan’ the validation fails at wrong protocol; “

Error: expected protocol to be one of [* Tcp Udp Icmp Ah Esp], got TCP”

Reference

Import of insights webtests fail

aztfy v0.3.0(b1fe27d)
Terraform v1.1.9
on darwin_amd64
provider registry.terraform.io/hashicorp/azurerm v3.5.0

Import in batch mode:

aztfy -b -f -k -m ../mapping.file my-rg

mapping.file

{
    "/subscriptions/000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/microsoft.insights/webtests/testing my-webpage": "azurerm_application_insights_web_test.my_webpage"
}

Output:

[ERROR] Failed to import /subscriptions/000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/microsoft.insights/webtests/testing my-webpage as azurerm_application_insights_web_test.my_webpage: exit status 1

Error: parsing Resource ID "/subscriptions/000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/microsoft.insights/webtests/testing my-webpage": ID was missing the `webTests` element

It looks like there is confusion if it is webtests vs webTests

new_mapping.file

{
    "/subscriptions/000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/microsoft.insights/webTests/testing my-webpage": "azurerm_application_insights_web_test.my_webpage"
}

Output:

[WARN] No mapping information for resource: /subscriptions/000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/microsoft.insights/webtests/testing my-webpage as azurerm_application_insights_web_test.my_webpage, skip it

I am not sure if this is aztfy eller terraform/azurerm.

terraform import works with webTests, but not with webtests:

terraform import azurerm_application_insights_web_test.my_webpage '/subscriptions/000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/microsoft.insights/webTests/testing my-webpage'

aztfy some resources skipped

When using aztfy the keyvault resource always gets skipped, is this resource type not supported to be imported ?

/subscriptions/000000-0000-0000-000000000/resourceGroups/testrg1/providers/Microsoft.KeyVault/vaults/new-vm-kv01
│ (Skip)
💡/subscriptions/000000-0000-0000-000000000/resourceGroups/testrg1/providers/Microsoft.Network/virtualNetworks/test-vm-vnet
azurerm_virtual_network.res-1

💡/subscriptions/000000-0000-0000-000000000/resourceGroups/testrg1/providers/Microsoft.Network/virtualNetworks/test-vm-vnet/subnets/applica
azurerm_subnet.res-2

💡/subscriptions/000000-0000-0000-000000000/resourceGroups/testrg1

aztfyResourceMapping.json only saves resources it mapped propperly

aztfy version: 0.3.0
terraform version: 1.1.9

After running a scan against a resource group, I have a large number of resources that didn't map correctly. Pressed S to save, which created the aztfyResourceMapping.json file, however it is only populated with the few resources that mapped correctly, as opposed to all resources.

Documentation enhancement

Need to do some kind of matrix to help to choose between multiple product. Among others :

  • terraformer
  • terracognita

Code refactoring

Hi, tool is working great in this early stage but I had to wonder if the team is planning to introduce code refactoring? Import is being made in very raw format, plain values are all imported into main.tf file which as a result forces you to refactor the code by yourself and manually cut/copy/paste values into variables.tf, terraform.tfvars, output.tf or other .tf files that you have to create by yourself.

Assuming that future development of the tool would introduce import scope on the subscription level, couple of different approaches to refactoring could be offered in the aztfy command which will create module/subfolder structure based on the chosen refactoring style.

I assume that this would also need some Azure CAF based schema file for the resource naming convention that will be used during the import (prefixes, numbering, etc.), so maybe some .json template file could be offered for the download. For example, mentioned .json file could contain variable definition for each resource type like the prefix, middle sections, suffix, incremental sections and separators. Maybe in this definition we could also have at disposal some imported variables from the current AZ Context like subscription name, resource group name, etc.

Unable to import App Services

aztfy v0.3.0
terraform v1.1.9

I have a resource group with an App Service Plan and 3 App Services, as well as some other resources. The App Services are recognized on the initial import:

app-service-not-imported

and pressing r will even provide some suggested resource types. However then generated .aztfyResourceMapping.json doesn't include the resources.

Is there any further information that may point to the issue?

Azure Terrafy long pathname is cut off

When Azure Terrafy is initialising, long path names are cut off so you can't see the resource type or name to enter it.

For example:
_/subscriptions/0000000000-000000000-00000000/resourceGroups/rg-core-infra/providers/Microsoft.Automation/automationAccounts/CoreInfraAutomationAC/connectionTypes/AzureClassicCertif ..

│ /subscriptions/0000000000-000000000-00000000//resourceGroups/rg-core-infra/providers/Microsoft.Automation/automationAccounts/CoreInfraAutomationAC/connectionTypes/AzureServicePrinci..._

I can't see the full path, and as such, don't know what to enter for resource_provider_name.resource_name
My only option is to skip those resources which means a large portion of the config is not documented.

DNS and Private DNS unable to export SOA

I'm getting the following error message while trying to export the SOA record for DNS and Private DNS. Any help is really appreciated.

❗️/subscriptions/93341713-b89f-4e20-8627-8927c7269259/resourceGroups/az104-04-rg1/providers/Microsoft.Network/dnszones/fxcloud.ca/SOA/@
azurerm_dns_zone.res-11

❗️/subscriptions/93341713-b89f-4e20-8627-8927c7269259/resourceGroups/az104-04-rg1/providers/Microsoft.Network/privateDnsZones/contoso.org/SOA/@
│ azurerm_private_dns_zone.res-13

TF resource recommendation

Currently, this tool asks users to manually input the tf resource mapped to an Azure resource ID. This brings complexity to users who are not familiar with TF. Propose to make the interactive phase more user friendly. E.g. we can guess a best match based on some knowledge (e.g. by static code analyzing the provider codebase to get those mappings).

Odd issue while exporting the resource group

Not sure if this is an issue with my local setup, but Azure CLI seems to be working fine, so writing here:

I have logged in using az login and then set the subscription context with az account set --subscription="id here". I have confirmed that the context is correct after this one with az account show, so I assume that Azure CLI is fine.

Then I try to run aztfy resourcegroupname, and it tries to fetch the resources, and I get this error message:

exporting arm template of resource group resourcegroupname: DefaultAzureCredential: failed to acquire a token. Attempted credentials: EnvironmentCredential: missing environment variable AZURE_TENANT_ID ManagedIdentityCredential: IMDS token request timed out AzureCLICredential: exec: "cmd.exe": executable file not found in %PATH%

Is there a way to run this in debug mode? I assume some REST API calls drop with tenant ID missing, but Azure CLI seems to be okay.

E: Also, rgp ARM export works with Azure CLI fine in the same session.

Option to only create terraform configuration without direct state import

Hey there,
I wthink it would be helpfull to split the creation of the configuration from the import into the status.

So the "switch" should lead tothat

  • main.tf is created
  • terraform import script is created to run all the imports manually

That would help to

  • just get the configuration of of running azure environment to terraform
  • review the terrafrom configuration for example by checkov/tflint etc
  • update the configuration manually on the names in the main.tf file
  • replace genereiv name on the import filr by search/replace with the correct naming

What do you think?
Joerg

Persistent "resource group does not exist" error

Using the latest version 0.1.1:

aztfy -v
0.1.1(5654025)

I keep on running into an error suggesting the resource group does not exist. I did double check that:

  • I am logged into az cli ✅
  • The subscription containing the resource group is set and default ✅
  • the resource group exists ✅

But I keep on getting the error that the resource group does not exist:

Azure Terrafy 
  
  exporting arm template of resource group jdb-test-rg: resources.GroupsClient#ExportTemplate: Failure sending request: StatusCode=0 -- Original Error: Code="ResourceGroupNotFound" Message="Resource
  group 'jdb-test-rg' could not be found." 

I am running this from the Terraform supplied docker image:

ARG   TERRAFORM_VERSION=1.1.7
FROM  hashicorp/terraform:${TERRAFORM_VERSION}
ARG   AZTFY_VERSION=0.1.1
...
...
...
# add the aztfy binary
RUN curl -L https://github.com/Azure/aztfy/releases/download/v${AZTFY_VERSION}/aztfy_v${AZTFY_VERSION}_linux_amd64.zip -o /tmp/aztfy.zip && \
    unzip /tmp/aztfy.zip -d /usr/local/bin && \
    chmod +x /usr/local/bin/aztfy

This is the underlying OS of the Terrform image:

# cat /etc/os-release 
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.15.0
PRETTY_NAME="Alpine Linux v3.15"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"

Any ideas why it keeps on telling me the resource group does not exist?

Error when try to build from source

Maybe a mis use on my side...
Does it soon familiar to you ?
Since the 0.4, I have this when building

/mnt/c/Users/cedric/aztfy$ go build -gcflags=all="-N -l"
github.com/magodo/aztfy/internal/meta
internal/meta/meta_impl.go:163:12: undefined: os.WriteFile
internal/meta/meta_impl.go:206:12: undefined: os.WriteFile
internal/meta/meta_impl.go:347:12: undefined: os.WriteFile
note: module requires Go 1.16

Also some basic clarification about config var management should be interesting :

  • Logfile
  • Debug
  • MockClient

unattended usage of aztfy

We are aware of the fact, that we can use batch mode with an preexisting .aztfyResourceMapping.json, but that doesn't really help.

We have to export round about 100 resource groups with up to several hundreds of resources, which is taking really long time.
We have started locally to extended the mapping_gen.go to get more ressources mapped automatically, that works quite fine.

It would be really helpfull for export automation to just call aztfy with some parameters like filter (to ignore some of the identified resources automatically) and aztfy runs without any interaction or predefing mapping file to create the configuration.

Refresh to apply the dependencies into state after run

Though the generated configuration contains the dependencies, while the state doesn't. This means if we don't refresh to apply the dependencies into state after running this tool, the generated state and config can't be directly used for terraform destroy.

Aztfy not importing VM

Is there any special reason why Azure resources like Virtual Machines are not imported? Googled around and found more people with the same issue. There's even an automatically generated comment in the created code, example:

...
depends_on = [
# Depending on "/subscriptions/xxxxxxxxx/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm", which is not imported by Terraform.
]
...

[Windows FunctionApp] exit status 1 - ".../Microsoft.Web/sites/sandbox-training-zguerrouj-func/config/web": ID was missing the slots element

Versions used :

  1. aztfy version : 0.4.0 (cd5e46e)
  2. azurerm provider version : 3.7.0

Constats :

I try to import and built terraform files for an windows FunctionApp resource.

  • Aztfy detects well the Windows FunctionApp resource (azurerm_windows_function_app on Terraform view) and I successed to build the terraform file main.tf :

/subscriptions/da2e245c-1da4-409b-9b54-81016ca9ae8f/resourceGroups/sandbox-training-zguerrouj-resource-group/providers/Microsoft.Web/sites/sandbox-training-zguerrouj-func

  • Also Aztfy detects as a new resource such as below :

/subscriptions/da2e245c-1da4-409b-9b54-81016ca9ae8f/resourceGroups/sandbox-training-zguerrouj-resource-group/providers/Microsoft.Web/sites/sandbox-training-zguerrouj-func/config/web

Normally that should concern an Windows FunctionApp slot resource (azurerm_windows_function_app_slot on Terraform view : https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_function_app_slot).

Error encountered :

So with aztfy I tried to declare it with azurerm_windows_function_app_slot.resourcenametest but I encounters the error :

exit status 1 Error: parsing Resource ID "/subscriptions/da2e245c-1da4-409b-9b54-81016ca9ae8f/resourceGroups/sandbox-training-zguerrouj-resource-group/providers/Microsoft.Web/sites/sandbox-training-zguerrouj-func/config/web": ID was missing the slots element

Needs :

Is anyone already encountered this behaviour ?
Please is anyone already fixed this error to import an Windows FunctionApp with aztfy ?

filter does not work as expected

Hi,

When I import a resource group,I would like to filter what I import. So I use the '/' key.
Let say I want to import all resources who contains 'dev-'.
I type 'dev-'
BUT it filters any resource that contain d, e, v and - anywhere in the id

aztfy Bug

when converting NSGs the argument protocol terraform expects to receive is case sensitive, however aztfy creates this in all upper case which causes terraform error as follows.

Error: expected protocol to be one of [* Tcp Udp Icmp Ah Esp], got TCP

Easy fix within the TF code to change to Tcp instead of TCP but just wanted to highlight this as a bug.

Linux Installation

Hello

Are you able to provide instructions on how to deploy aztfy into ubuntu or fedora packages?

This would also be beneficial for installation for WSL :)

Thanks

Kevin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.