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 #17684

Closed
puttagunta opened this issue Mar 23, 2018 · 5 comments

Comments

@puttagunta
Copy link

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

Hi @puttagunta! Sorry for this issue and thanks for reporting it.

This seems to be an issue in the azurerm provider in particular, in its normalizeJson helper function: https://github.com/terraform-providers/terraform-provider-azurerm/blob/ee0156b6c92ab0ac3212246ae75a8a6171eac3c1/azurerm/resource_arm_template_deployment.go#L253-L264

Therefore I'm going to have our bot move this issue over the repository for that provider. Thanks again for reporting this.

@puttagunta
Copy link
Author

puttagunta commented Mar 23, 2018 via email

@ghost
Copy link

ghost commented Mar 23, 2018

This issue has been automatically migrated to hashicorp/terraform-provider-azurerm#1025 because it looks like an issue with that provider. If you believe this is not an issue with the provider, please reply to hashicorp/terraform-provider-azurerm#1025.

@apparentlymart
Copy link
Contributor

No worries @puttagunta! It's not always easy to tell. (I had to go read the source code myself to decide!)

@ghost
Copy link

ghost commented Apr 4, 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
This issue was closed.
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

2 participants