- terraform.tfstate 是输入文件,packageservicelist.tf.json 是输出文件。
- 两者都转换为地图文件
- 我遍历的数据存储在结果中,我想将数据从结果复制到结果1。
- Will Write 操作在这里有效。如果是 。如何 ?
package main
import (
"fmt"
"io/ioutil"
"encoding/json"
)
func main() {
//File Reading terraform.tfstate
data, err := ioutil.ReadFile("terraform.tfstate")
if err != nil {
//fmt.Println("File reading error", err)
return
}
// Map is save in m
m := make(map[string]interface{})
json.Unmarshal(data, &m)
result:= m["resources"].([]interface{})[0].(map[string]interface{})["instances"].([]interface{})[0].(map[string]interface{})["attributes"].(map[string]interface{})["packaged_service_list"].([]interface{})[0].(map[string]interface{})["package_service"]
fmt.Println(result)
//File Reading packageservicelist.tf.json
data1, err :=ioutil.ReadFile("./linear/packageservicelist.tf.json")
if err != nil {
fmt.Println("File reading error", err)
return
}
m1 := make(map[string]interface{})
json.Unmarshal(data1, &m1)
fmt.Println("\n")
result1:= m1["resource"].(map[string]interface{})["api_packageservicelist"].(map[string]interface{})["packageservicelist"].(map[string]interface{})["packaged_service_list"].(map[string]interface{})["package_service"]
fmt.Println(result1)
}