Hi @apparentlymart,
Exactly, what you said is right. I tried to create a json template for terraform and zipped it using golang. Then I pushed it to terraform cloud api using go-tfe. After I pushed, it started the run and said the syntax for tf is wrong.
The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
Error: Argument or block definition required
on main.tf line 1:
1: {
An argument or block definition is required here.`An argument or block definition is required here.
I am putting my code right here,
{
"module": {
"azureVM": {
"admin_password": "Password@2020",
"admin_username": "winuser",
"location": "westeurope",
"os_data_disk_size_in_gb": 0,
"resource_group_name": "Testing",
"source": "",
"storage_data_disks": [
{
"CreateOption": "Empty",
"Lun": 0,
"Name": "datadisk1",
"DataDiskSizeInGB": 0
}
],
"subnet_name": "subnet001",
"version": "1.0.4",
"vm_name": "euwmvm01",
"vm_size": "Standard_DS1_v2",
"vm_sku": "2016-Datacenter",
"vnet_name": "vnet001"
}
},
"provider": {
"azurerm": {
"client_id": "${var.client_id}",
"client_secret": "${var.client_secret}",
"features": {},
"subscription_id": "${var.subscription_id}",
"tenant_id": "${var.tenant_id}",
"version": "=2.4.0"
}
},
"variable": {
"client_id": {
"type": "string"
},
"client_secret": {
"type": "string"
},
"subscription_id": {
"type": "string"
},
"tenant_id": {
"type": "string"
}
}
}
The go lang code to convert into tar.gz is below,
package main
import (
"bufio"
"compress/gzip"
"fmt"
"io/ioutil"
"os"
"strings"
)
func main() {
// Open file on disk.
name := "main.tf.json"
f, _ := os.Open("C:\\Users\\xxxx\\go\\src\\terracloud\\ws-jBf7St7V2Sa7fLRZ\\" + name)
// Create a Reader and use ReadAll to get all the bytes from the file.
reader := bufio.NewReader(f)
content, _ := ioutil.ReadAll(reader)
// Replace txt extension with gz extension.
name = strings.Replace(name, ".tf.json", ".tar.gz", -1)
// Open file for writing.
f, _ = os.Create("C:\\Users\\LK757HL\\go\\src\\terracloud\\ws-jBf7St7V2Sa7fLRZ\\" + name)
// Write compressed data.
w := gzip.NewWriter(f)
w.Write(content)
w.Close()
// Done.
fmt.Println("DONE")
}
Could you please help me out here.