AzureRM Automation DSC Configuration - azure

I'm trying to configure Azure DSC Configuration, but I am running into two issues.
I continue to get this error message
Error = 'invalid character 'c' looking for beginning of value' JSON = 'configuration cdavdtest {}'*
*2. No matter what I do to the resource azurerm_automation_dsc_configuration , it throws this command which is a reference to my last terraform plan / apply that failed. Changing the configuration does nothing, and the old error continues. I appreciate any help. See the cdavdtest in bold compared to the resource also in bold below. Also the name doesn't update it still says dsc_config even though I updated it to dsc_configa.
Error: making Read request on AzureRM Automation Dsc Configuration content "cdavdtest": automation.DscConfigurationClient#GetContent: Failure responding to request: StatusCode=200 -- Original Error: Error occurred unmarshalling
JSON - Error = 'invalid character 'c' looking for beginning of value' JSON = 'configuration cdavdtest {}'
│
│ with azurerm_automation_dsc_configuration.dsc_config,
│ on automationaccount.tf line 17, in resource "azurerm_automation_dsc_configuration" "dsc_config":
│ 17: resource azurerm_automation_dsc_configuration dsc_config {
resource azurerm_automation_account automation_account {
name = "${var.avd.name}-automationaccount"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
sku_name = "Basic"
}
output "end_point" {
value = azurerm_automation_account.automation_account.dsc_server_endpoint
}
output registration_key {
value = azurerm_automation_account.automation_account.dsc_primary_access_key
}
resource azurerm_automation_dsc_configuration dsc_configa {
name = "**test**"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
automation_account_name = azurerm_automation_account.automation_account.name
description = "Configuration node for Azure Virtual Desktop"
content_embedded = "Configuration **test** {}"
log_verbose = true
}
I have tried commenting out the code and I still get the error. I've tried updating the name. I've tried using the <<BODY and writing out the configuration but this still persists.

Tested in my Environment was getting the same error. The error is due to azurerm_automation_dsc_configuration is broken since provider version 2.96.0
I was using the lasted terraform provider version ie 3.0.1
Solution : Would Suggest you to please use the provider version between version = ">=2.10,<=2.30"
Terraform Code
main.tf file
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=2.10,<=2.30"
}
}
}
provider "azurerm" {
features{}
}
data "azurerm_resource_group" "example" {
name = "XXXXXXxXXX"
}
resource "azurerm_automation_account" "example" {
name = "account1"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
sku_name = "Basic"
}
output "end_point" {
value = azurerm_automation_account.example.dsc_server_endpoint
}
output "registration_key" {
value = azurerm_automation_account.example.dsc_primary_access_key
}
resource "azurerm_automation_dsc_configuration" "example" {
name = "test"
resource_group_name = data.azurerm_resource_group.example.name
automation_account_name = azurerm_automation_account.example.name
location = data.azurerm_resource_group.example.location
content_embedded = "configuration test {}"
log_verbose = true
}
OutPut--

Related

Argument "recovery_vault_name" not found while creating the recovery service vault using Terraform

I am using Terraform Script to create a Recovery Service Vault and need to take the VM backup into that recovery service vault. Below is the terraform script and steps I performed:
Create Recovery Service Vault
Define backup policy
Azure VM protection backup
Terraform Version >= 0.14
Azure rm version= ~>2.0
Main.tf
resource "azurerm_recovery_services_vault" "recovery_vault" {
name = var.recovery_vault_name
location = var.location
resource_group_name = var.resource_group_name
}
resource "azurerm_backup_policy_vm" "ss_vm_backup_policy" {
name = "tfex-recovery-vault-policy"
resource_group_name = var.resource_group_name
recovery_vault_name = azurerm_recovery_services_vault.recovery_vault.name
policy_type = "V1"
backup {
frequency = "Monthly"
time = "23:00"
weekdays = ['Sunday']
}
instant_restore_retention_days = 5
retention_weekly {
count= 12
weekdays = ['Sunday']
}
}
resource "azurerm_backup_protected_vm" "ss_vm_protection_backup" {
resource_group_name = var.resource_group_name
recovery_vault_name = azurerm_recovery_services_vault.recovery_vault.name
source_vm_id = azurerm_windows_virtual_machine.windows_vm[count.index].id
backup_policy_id = azurerm_backup_policy_vm.ss_vm_backup_policy.id
}
Variable.tf
variable resource_group_name {
default = "ss"
}
variable recovery_vault_name {
default = "yy"
}
Referred the above Main.tf in my application specific main.tf file as below:
module "azure_windows_vm" {
source = "git::https://xx.yy.com/ABCD/_git/NBGF/TGFT?ref=master"
vm_name = local.vm_name
location = local.location
resource_group_name = local.resource_group_name
admin_password = "xyz"
num_vms = 2
vnet_name = var.vm_subnet_id
tags=local.tags
}
When I execute the above Terraform script in DevOps pipeline, I am getting below error from line where module "azure_windows_vm" starts
Error: Missing required argument The argument "recovery_vault_name" is
required, but no definition was found
I tried different things to fix this error, but somehow it is not working. Can someone please guide what I am missing here?
Thank You!

Terraform plan getting Error: Failed to decode resource from state

Terraform initialize is working fine but when I do terraform plan getting below error.
Error: Failed to decode resource from state
│
│ Error decoding "azurerm_mssql_database.db" from previous state: unsupported attribute "extended_auditing_policy"
If I comment this particular resource then we start getting error for other resource.
Can some one please help me ?
Error: Failed to decode resource from state
│
│ Error decoding "azurerm_mssql_database.db" from previous state: unsupported attribute "extended_auditing_policy"
I tried in my environment and got below results:
Initially I tried with extended audit policy with new terraform provider version and got the same error:
extended_auditing_policy {
storage_endpoint = module.storageaccount.storage_account.self.primary_blob_endpoint
storage_account_access_key = module.storageaccount.storage_account.self.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = 30
}
This problem occurs when attempting to import data using a provider version that is older than the one that was used to create the current state. The earlier provider version won't be able to decode an unknown attribute while loading the state file during the import if the attribute was added in the newer version of the provider.
I tried with new azurerm_mssql_server_extended_auditing_policy resource to solve this problem.
Terraform.tf
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "vs" {
name = "<rg name>"
location = "West Europe"
}
resource "azurerm_mssql_server" "ex" {
name = "demosqlserver3261"
resource_group_name = azurerm_resource_group.vs.name
location = azurerm_resource_group.vs.location
version = "12.0"
administrator_login = "missadministrator"
administrator_login_password = "AdminPassword123!"
}
resource "azurerm_mssql_database" "ext" {
name = "demodb3261"
server_id = azurerm_mssql_server.ex.id
}
resource "azurerm_storage_account" "vst" {
name = "venkat678"
resource_group_name = azurerm_resource_group.vs.name
location = azurerm_resource_group.vs.location
account_tier = "Standard"
account_replication_type = "GRS"
}
resource "azurerm_mssql_database_extended_auditing_policy" "example" {
database_id = azurerm_mssql_database.ext.id
storage_endpoint = azurerm_storage_account.vst.primary_blob_endpoint
storage_account_access_key = azurerm_storage_account.vst.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = 6
}
Console:
Portal:
Reference:
Import fails with "Error: Invalid resource instance data in state" – HashiCorp Help Center

Why I can't create azurerm_app_service connection?

Azurerm provider version
3.35.0
Target resource
azurerm_app_service_connection
Terraform file
write brief
module "app_service" {
source = "../../modules/app_service"
name = var.name
}
resource "azurerm_app_service_connection" "serviceconnector" {
name = "serviceconnector"
app_service_id = module.app_service.id
target_resource_id = data.azurerm_postgresql_flexible_server.db.id
client_type = "django"
authentication {
type = "secret"
name = var.db_uname
secret = data.azurerm_key_vault_secret.secret.value
}
}
data "azurerm_postgresql_flexible_server" "db" {
name = "postgre"
resource_group_name = "rg"
}
Output Error message
Error: creating Scoped Linker (Resource Uri: "/subscriptions/<id>/resourceGroups/app/providers/Microsoft.Web/sites/app_service"
│ Linker Name: "serviceconnector"): performing LinkerCreateOrUpdate: servicelinker.ServiceLinkerClient#LinkerCreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="TargetTypeNotSupported" Message="Target resource type MICROSOFT.DBFORPOSTGRESQL/FLEXIBLESERVERS is not supported."
│
│ with azurerm_app_service_connection.serviceconnector,
│ on app_service.tf line 10, in resource "azurerm_app_service_connection" "serviceconnector":
│ 10: resource "azurerm_app_service_connection" "serviceconnector" {
│
│ creating Scoped Linker (Resource Uri:
│ "/subscriptions/<id>/resourceGroups/app/providers/Microsoft.Web/sites/app_service"
│ Linker Name: "serviceconnector"): performing LinkerCreateOrUpdate:
│ servicelinker.ServiceLinkerClient#LinkerCreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error:
│ Code="TargetTypeNotSupported" Message="Target resource type MICROSOFT.DBFORPOSTGRESQL/FLEXIBLESERVERS is not
│ supported."
I want to ask
I updated azurerm provider to 3.35.0 by see this info.azurerm_app_service_connection: Expected type object but found type string
Why return "TargetTypeNotSupported" this message.
It seems to supported as long as I saw.
azurerm_app_service_connection
It's my fault? or bug?
I have tested this in my local and landed up with error targettypenotsupported.
If we want to create a service connection to postgressql flexible server db with app service then db should be declared using resource block only since as per this terraform documentation we dont have any definition to use datablock to create a connection with existing postgres sql flexible server db as shown in this image
I tried the same github terraform which you added in my environment, with the authentication type as "Secret" and received the same error as shown:
As mentioned here, there appears to be a problem with the "secret authentication type" from the Terraform provider API. As a result, I updated it as follows and it worked for me successfully:
authentication {
type = "systemAssignedIdentity"
}
main.tf:
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.35.0"
}
}
}
provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
resource "azurerm_resource_group" "main" {
name = "xxxxRG"
location = "xxxxx"
}
resource "azurerm_postgresql_server" "main" {
name = "xxxxxserver"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
administrator_login = "xxxxxuser"
administrator_login_password = "<Password of server>"
backup_retention_days = 7 // As per your requirements
sku_name = "GP_Gen5_2"
version = "11"
storage_mb = 5120
public_network_access_enabled = false
ssl_enforcement_enabled = true
ssl_minimal_tls_version_enforced = "TLS1_2"
}
resource "azurerm_postgresql_database" "main" {
name = "xxxxdb"
server_name = azurerm_postgresql_server.main.name
resource_group_name = azurerm_postgresql_server.main.resource_group_name
charset = "utf8"
collation = "und-x-icu"
}
resource "azurerm_service_plan" "main" {
name = "xxxxxserviceplan"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
sku_name = "P1v2"
os_type = "Linux"
}
resource "azurerm_linux_web_app" "main" {
name = "xxxxxwebapp"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
service_plan_id = azurerm_service_plan.main.id
site_config {}
}
resource "azurerm_app_service_connection" "main" {
name = "xxxxxserviceconnector"
app_service_id = azurerm_linux_web_app.main.id
target_resource_id = azurerm_postgresql_database.main.id
client_type = "springBoot"
authentication {
type = "systemAssignedIdentity"
}
}
Output:-
Executed terraform init
Executed terraform plan:
Executed terraform apply:
Alternatively, If the requirement is only with the secret authentication type in your environment then you can create an app service connection by calling API (JSON request).

AKS Cluster | Failed to query available provider packages | Right version of hashicorp

I'm currently building my terraform plan and it seems that I'm running into issues as soon as I run the following command:
terraform init
The current main.tf contains this:
terraform {
backend "azurerm"{
resource_group_name = "test"
storage_account_name = "testaccount"
container_name = "testc"
key = "testc.state"
}
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "2.46.0"
}
}
}
# Configure the Microsoft Azure Provider
provider "azurerm" {
features {}
}
data "azurerm_key_vault" "keyVaultClientID" {
name = "AKSClientID"
key = var.keyvaultID
}
data "azure_key_vault_secret" "keyVaultClientSecret" {
name = "AKSClientSecret"
key_vault_id = var.keyvaultID
}
resource "azurerm_kubernetes_cluster" "test_cluster" {
name = var.name
location = var.location
resource_group_name = var.resourceGroup
dns_prefix = ""
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2_v2"
}
service_principal {
client_id = data.azurerm_key_vault_secret.keyVaultClientID.value
client_secret = data.azurerm_key_vault_secret.keyVaultClientSecret.value
}
tags = {
"Environment" = "Development"
}
}
The error message that I get is the following:
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/azure: provider
│ registry registry.terraform.io does not have a provider named
│ registry.terraform.io/hashicorp/azure
I'm looking at the documentation, and I'm changing the version, but I'm not getting any luck. Does anyone knows what else I can do or what should I change on my main.tf?
The solve this issue, you will have to add the following inside of the main terraform plan:
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.75.0"
}
If you add it, the issue will never appear again. Also, you might have to run the upgrade command to make sure terraform will be able to handle the new version.

Azure Terraform An invalid parameter NetworkMappingName was passed.","possibleCauses":"Parameter value is not correct for this action."

I am trying to mapping network for site recovery but facing following issue.
Error: Error checking for presence of existing site recovery network mapping recovery-network-mapping (vault recovery-vault-360f): siterecovery.ReplicationNetworkMappingsClient#Get: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="An invalid parameter NetworkMappingName was passed." Details=[{"activityId":"xxxxxxxxxxxxxxxxx","clientRequestId":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx","code":"InvalidParameter","message":"An invalid parameter NetworkMappingName was passed.","possibleCauses":"Parameter value is not correct for this action.","recommendedAction":"Correct the parameter value and retry the last action. If the issue persists, contact Support."}]
on modules/site_recovery/main.tf line 78, in resource "azurerm_site_recovery_network_mapping" "mapping":
78: resource "azurerm_site_recovery_network_mapping" "mapping" {
main.tf file:
#Create Virtual Network in Primary Resource Group
resource "azurerm_virtual_network" "primary" {
name = var.virtual_network
resource_group_name = var.resource_group_name
location = var.location
address_space = var.address_space
depends_on = [var.resource_group_name]
tags = {
environment = "Test"
}
}
#Create Subnet in Virtual Network
resource "azurerm_subnet" "primary1" {
name = var.subnet1
virtual_network_name = azurerm_virtual_network.primary.name
resource_group_name = var.resource_group_name
address_prefix = var.address_prefix1
}
output "vnet_id1" {
value = "${azurerm_virtual_network.primary.id}"
}
Site recovery module root main.tf file:
main.tf file:
module "site_recovery" {
-----------
-----------
network_mapping = "recovery-network-mapping"
vnet_id1 = "${module.network.vnet_id1}"
-----------
-----------
}
Site recovery module:
resource "azurerm_site_recovery_network_mapping" "mapping" {
name = var.network_mapping
resource_group_name = var.sec_resource_group
recovery_vault_name = azurerm_recovery_services_vault.vault.name
source_recovery_fabric_name = var.primary_fabric
target_recovery_fabric_name = var.seconday_fabric
source_network_id = var.vnet_id1
target_network_id = azurerm_virtual_network.secondary.id
depends_on = [var.vnet_id1, azurerm_virtual_network.secondary]
}
site_recovery variable.tf:
variable "vnet_id1" {
description = "The name of Primary VNET"
}
variable "network_mapping" {
description = "The name of Recovery Protection network_mapping"
}
I am getting mapping name parameters Invalid.
It looks like a bug. I also face the same issue when tried it with terraform document. Also, there is a similar open issue on GitHub.

Resources