Azure / Azure/terraform-provider-azapi
question: ignore read only properties managing MCA Billing Profiles / Invoice Sections
- Dominant language
- Go
- Stars
- 244
- Forks
- 97
- Avg merge
- 5d 9h
- Merged PRs (30d)
- 9
Description
Using my Terraform Module to manage billing profiles, the TF Apply fails with error message:
```
│ RESPONSE 400: 400 Bad Request
│ ERROR CODE UNAVAILABLE
│ --------------------------------------------------------------------------------
│ {
│ "errors": {
│ "Properties.SoldTo": [
│ "The field SoldTo is read-only."
│ ],
│ "Properties.CurrentPaymentTerm": [
│ "The field CurrentPaymentTerm is read-only."
│ ]
│ },
│ "type": "[https://tools.ietf.org/html/rfc9110#section-15.5.1",](https://tools.ietf.org/html/rfc9110#section-15.5.1%22,)
│ "title": "One or more validation errors occurred.",
│ "status": 400,
│ "traceId": "00-XXXXXXXXXXXXXXXXXXXXXXXXX"
│ }
│ --------------------------------------------------------------------------------
```
I have tried multiple ways to ignore the two properties, with no success.
current extract of the module:
```
resource "azapi_resource" "billing_profile" {
depends_on = [random_uuid.billing_profile_uuid]
type = "Microsoft.Billing/billingAccounts/billingProfiles@2024-08-01-preview"
name = var.properties.billing_profile_id == null ? random_uuid.billing_profile_uuid[0].result : var.properties.billing_profile_id
parent_id = "/providers/Microsoft.Billing/billingAccounts/${var.properties.billing_account_id}"
ignore_missing_property = true
ignore_casing = true
schema_validation_enabled = false # ignore schedma validation errors because the API is not aware of latest changes
body = {
properties = {
billTo = {
addressLine1 = var.properties.addressLine1 == "" ? null : var.properties.addressLine1
addressLine2 = var.properties.addressLine2 == "" ? null : var.properties.addressLine2
addressLine3 = var.properties.addressLine3 == "" ? null : var.properties.addressLine3
city = var.properties.city == "" ? null : var.properties.city
companyName = var.properties.companyName == "" ? null : var.properties.companyName
country = var.properties.country == "" ? null : var.properties.country
district = var.properties.district == "" ? null : var.properties.district
email = var.properties.email == "" ? null : var.properties.email
phoneNumber = var.properties.phoneNumber == "" ? null : var.properties.phoneNumber
postalCode = var.properties.postalCode == "" ? null : var.properties.postalCode
region = var.properties.region == "" ? null : var.properties.region
isValidAddress = true
}
displayName = var.properties.displayname == "" ? null : var.properties.displayname
invoiceEmailOptIn = var.properties.invoiceEmailOptIn
invoiceRecipients = var.properties.invoiceRecipients == "" ? null : var.properties.invoiceRecipients
invoiceRecipientContacts = [
for contact in var.properties.invoiceRecipientContacts : {
firstName = contact.firstName == "" ? null : contact.firstName
middleName = contact.middleName == "" ? null : contact.middleName
lastName = contact.lastName == "" ? null : contact.lastName
email = contact.email == "" ? null : contact.email
phoneNumber = contact.phoneNumber == "" ? null : contact.phoneNumber
}
]
poNumber = var.properties.poNumber == "" ? null : var.properties.poNumber
tags = var.properties.tags == "" ? null : var.properties.tags
enabledAzurePlans = [
{
skuDescription = "Microsoft Azure Plan"
skuId = "0001"
},
{
skuDescription = "Microsoft Azure Plan for DevTest"
skuId = "0002"
},
]
SoldTo = {
}
}
}
lifecycle {
ignore_changes = [
name,
body.value.properties.billTo.isValidAddress,
body.value.properties.soldTo,
body.value.properties.currentPaymentTerm,
body.value.properties.enabledAzurePlans
]
}
}
```
different ignore methods I have tried:
```
lifecycle {
ignore_changes = [
name,
body.properties.billTo.isValidAddress,
body.properties.soldTo,
body.properties.currentPaymentTerm,
body.properties.enabledAzurePlans
]
}
```
or
```
lifecycle {
ignore_changes = [
name,
properties.billTo.isValidAddress,
properties.soldTo,
properties.currentPaymentTerm,
properties.enabledAzurePlans
]
}
```
It seems this only started to be an issue with 2.5.0 onwards. With 2.4.0 it worked somehow.
Any idea how I can correctly make sure the api call is only using the writable properties?
Any help is appreciated!
Contributor guide
Research direction
Start by reproducing the posted azapi_resource configuration with provider versions 2.4.0 and 2.5.0, focusing on lifecycle.ignore_changes and the billing profile properties. Compare the generated API request and schema handling for SoldTo and CurrentPaymentTerm. Done means the resource can apply using only writable properties without the read-only-field validation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, terraform
- Domain
- cloud, infrastructure, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100