Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply succeeds even with "Error parsing JSON: invalid character '$' looking for beginning of value" with template for template_body of azurerm_template_deployment #1025

Closed
ghost opened this issue Mar 23, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Mar 23, 2018

This issue was originally opened by @puttagunta as hashicorp/terraform#17684. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version: 0.11.5

Terraform Configuration Files

scheduler-template/main.tf

data "template_file" "init" {
  template = "${file("${path.module}/scheduler-arm-template.tpl")}"

  vars {
    sch-name             = "${var.sch-name}"
    sch-targetResourceId = "${var.sch-targetResourceId}"
  }
}

scheduler-template/variables.tf

variable "sch-name" {}
variable "sch-targetResourceId" {}

scheduler-template/outputs.tf

output "sch-rendered" {
  value = "${data.template_file.init.rendered}"
}

Usage

module "scheduler-template" {
  source               = "../../modules/scheduler-template"
  sch-name             = "shutdown-computevm-${azurerm_virtual_machine.config.name}"
  sch-targetResourceId = "${azurerm_virtual_machine.config.id}"
}

resource "azurerm_template_deployment" "scheduler" {
  name                = "${azurerm_virtual_machine.config.name}-sch"
  resource_group_name = "${var.resource_group_name}"
  template_body       = "${module.scheduler-template.sch-rendered}"
  deployment_mode = "Incremental"
}

Debug Output

output in the terraform.tfstate
"template_body": "{"$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#\",\"contentVersion\":\"1.0.0.0\",\"resources\":[{\"apiVersion\":\"2016-05-15\",\"location\":\"eastus2\",\"name\":\"shutdown-computevm-sree3-xxx-vm\",\"properties\":{\"dailyRecurrence\":{\"time\":\"1900\"},\"notificationSettings\":{\"status\":\"Disabled\",\"timeInMinutes\":30},\"provisioningState\":\"Succeeded\",\"status\":\"Enabled\",\"targetResourceId\":\"/subscriptions/ce99575f-feda-4aeb-927c-f22b7e07c6d4/resourceGroups/sree3/providers/Microsoft.Compute/virtualMachines/sree3-xxx-vm\",\"taskType\":\"ComputeVmShutdownTask\",\"timeZoneId\":\"Eastern Standard Time"},"scale":null,"type":"microsoft.devtestlab/schedules"}]}"

gists for plan and apply
Plan
https://gist.github.com/puttagunta/fe158c3392401d7e8ad92d50843c6e59
Apply
https://gist.github.com/puttagunta/34f03dc0e31d13b53699182b51058a24

Expected Behavior

If it is a legitimate error

terraform apply

should fail and

terraform plan

should also fail with a valid error message

Actual Behavior

Plan is successfully generated with the following message

Plan: 2 to add, 0 to change, 0 to destroy.
with no clue that there was an error unless, we take a look at the output for that specific resource, which has the following error
template_body: "Error parsing JSON: invalid character '$' looking for beginning of value"
The apply succeeds with all green and the corresponding resource also gets created, with the error in the output of the resource in the console as in the plan.

Steps to Reproduce

do

terraform plan ...
terraform apply ...

References

#5462

@apparentlymart
Copy link
Contributor

I migrated this over from the Core repository because it looked like this was coming from a helper function in this repo:

https://github.com/terraform-providers/terraform-provider-azurerm/blob/ee0156b6c92ab0ac3212246ae75a8a6171eac3c1/azurerm/resource_arm_template_deployment.go#L253-L264

While it's annoying that the normalization can't return an error itself here, this sort of thing has been handled elsewhere by having the normalization produce an empty string and then having separate validation code that detects that and returns an real error. Perhaps a strategy like that could work here too.

@neil-yechenwei
Copy link
Contributor

neil-yechenwei commented Sep 22, 2020

Thanks for opening this issue. After checked, seems azurerm_template_deployment has been added validation function. So I assume the issue has gone and seems I cannot repro it anymore using latest azurerm provider after tested. Could you have a try with latest azurerm provider to check whether the issue still exists? Thanks.

@tombuildsstuff
Copy link
Contributor

Closing since we've not heard back here.

@ghost
Copy link
Author

ghost commented Nov 7, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants