'Terraform file for gcp, how to input path for json key

I am studying trying to learning how to deploy using Terraform in gcp. Would anyone know how to write the path for the json key in the configuration file mentioned in the template bellow.

I am getting an error in line 11

 credentials = file("C:\\Users\Administrator\\Desktop\\Terraform\\mykey.json")

output:

│ Error: Invalid escape sequence
│
│   on main.tf line 11, in provider "google":
│   11:   credentials = file("C:\Users\Administrator\Desktop\Terraform\mykey.json")
│
│ The symbol "l" is not a valid escape sequence selector.

template example:

terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
      version = "3.5.0"
    }
  }
}

provider "google" {
  credentials = file("<NAME>.json")

  project = "<PROJECT_ID>"
  region  = "us-central1"
  zone    = "us-central1-c"
}

resource "google_compute_network" "vpc_network" {
  name = "terraform-network"
}



Solution 1:[1]

The character \ is often an escape character and is combined with the next character.

Specify the credentials file:

credentials = file("C:\\Users\\Administrator\\Desktop\\Terraform\\mykey.json")

or like this - file() is not necessary:

credentials = "C:\\Users\\Administrator\\Desktop\\Terraform\\mykey.json"

or use Unix path syntax:

credentials = "C:/Users/Administrator/Desktop/Terraform/mykey.json"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Hanley