Package: idem-azure
Idem plugin to manage Azure cloud resourcesAboutidem-azurehelps manage Azure withidem.idem-azure source codeidem-azure documentationWhat is POP?This project is built withpop, a Python-based
implementation ofPlugin Oriented Programming (POP). POP seeks to bring
together concepts and wisdom from the history of computing in new ways to solve
modern computing problems.For more information:Intro to Plugin Oriented Programming (POP)pop-awesomepop-createWhat is Idem?This project is built withidem, an idempotent,
imperatively executed, declarative programming language written in Python. This project extends
idem!For more information:Idem Project WebsiteIdem Project docs portalGetting StartedPrerequisitesPython 3.8+git(if installing from source, or contributing to the project)IdemNoteIt is recommended that you install Idem using Poetry. Poetry is a tool for virtual environment and dependency management. See theIdem Getting Started guidefor more information.InstallationInstall from PyPIYou can installidem-azurefrom PyPI, a source repository, or a local directory.Before you installidem-azure, ensure that you are in the same directory as yourpyproject.tomlfile. Optionally, you can specify the directory containing yourpyproject.tomlfile by using the--directory=DIRECTORY(-C)option.Install from PyPITo installidem-azurefrom PyPI, run the following command:poetryaddidem-azureInstall from sourceYou can also installidem-azuredirectly from the source repository:poetryaddgit+https://gitlab.com/vmware/idem/idem-azure.gitIf you don’t specify a branch, Poetry uses the latest commit on themasterbranch.Install from a local directoryClone theidem-zurerepository. Then run the following command to install from the cloned directory:poetryadd~/path/to/idem-azureUsageCredentials SetupAfter installation, the Azure Idem execution and state modules will be accessible to the pophub.
In order to use them, we need to set up our credentials.Create a new file calledcredentials.yamland populate it with credentials.
Thedefaultprofile will be picked up automatically byidem.There are multiple authentication backends foridem-azurewhich each have their own unique set of parameters.
The following examples show the parameters that can be used to define credential profiles.credentials.yaml:azure:default:client_id:"12345678-1234-1234-1234-aaabc1234aaa"secret:"76543210-4321-4321-4321-bbbb3333aaaa"subscription_id:"ZzxxxXXXX11xx-aaaaabbbb-k3xxxxxx"tenant:"bbbbbca-3333-4444-aaaa-cddddddd6666"Next step is to encrypt the credentials file, and add the encryption key and encrypted file
path to the ENVIRONMENT.Encrypt the credential file:Idemencryptcredentials.yamlThis will generate a credentials.yaml.fernet file and a command line output token:-AXFSEFSSEjsfdG_lb333kVhCVSCDyOFH4eABCDEFNwI=Add these to your environment:exportACCT_KEY="-AXFSEFSSEjsfdG_lb333kVhCVSCDyOFH4eABCDEFNwI="exportACCT_FILE=$PWD/credentials.yaml.fernetYou are ready to use idem-azure!!!STATESIdem states are used to make sure resources are in a desired state.
The desired state of a resource can be specified in sls file.
In Idem-azure, three states are supported:present,absent,describepresent statepresentstate makes sure a resource exists in a desired state. If a resource does
not exist, runningpresentwill create the resource on the provider. If a resource
exists, runningpresentwill update the resource on the provider. (Only the values
that the Azure REST api supports can be updated.)absent stateabsentstate makes sure a resource does not exist. If a resource exits, runningabsentwill delete the resource. If a resource does not exist, runningabsentis a no-operation.describe statedescribestate lists all the current resources of the same resource type
under the subscription id specified in the credential profile.States can be accessed by their relative location inidem-azure/idem_azure/states.
For example, in the state sls yaml file below, Azure resource group state can be created with thepresentfunction.my_resource_group_state.sls:my-azure-resource-group:azure.resource_management.resource_groups.present:-resource_group_name:my-azure-resource-group-location:eastusThe state sls file can be executed with:idemstate$PWD/my_resource_group_state.slsExample of creating an Azure virtual network:my-virtual-network:azure.network.virtual_networks.present:-resource_group_name:my-azure-resource-group-virtual_network_name:my-virtual-network-location:eastus-address_space:-10.0.0.0/16The resource parameters in an sls yaml file follow the exact structure as
what’s in theAzure REST api doc. URI Parameters
should be specified in snake case with “- “ in front. All parameters of the api request body
should be specified in exactly the same way as what’s in the Azure REST api.Current Supported Resources statesauthorizationrole_definitions, role_assignmentsresource_managementresource_groupspolicypolicy_definitions, policy_assignmentsmanagement_groupsmanagement_groupssubscriptionsubscriptionnetworkfirewall, firewall_policies, network_interfaces, network_security_groups, public_ip_addresses, route_tables, routes, security_rules, subnets, virtual_networkscomputevirtual_machines, log_analytics_workspacestorage_resource_providerstorage_accounts