├── .gitignore ├── LICENSE ├── README.md ├── cloudasset ├── cloudasset.go ├── cloudasset_test.go └── templates │ ├── backend.tf.tmpl │ ├── import.sh.tmpl │ ├── provider.tf.tmpl │ └── resource.tf.tmpl ├── cmd ├── create.go ├── list.go ├── plan.go └── root.go ├── go.mod ├── go.sum ├── main.go ├── resources ├── resource.go ├── resource_google_compute_autoscaler.go ├── resource_google_compute_backend_bucket.go ├── resource_google_compute_backend_service.go ├── resource_google_compute_disk.go ├── resource_google_compute_firewall.go ├── resource_google_compute_forwarding_rule.go ├── resource_google_compute_global_forwarding_rule.go ├── resource_google_compute_health_check.go ├── resource_google_compute_http_health_check.go ├── resource_google_compute_image.go ├── resource_google_compute_instance.go ├── resource_google_compute_instance_group.go ├── resource_google_compute_instance_group_manager.go ├── resource_google_compute_instance_template.go ├── resource_google_compute_network.go ├── resource_google_compute_route.go ├── resource_google_compute_snapshot.go ├── resource_google_compute_ssl_certificate.go ├── resource_google_compute_subnetwork.go ├── resource_google_compute_target_http_proxy.go ├── resource_google_compute_target_https_proxy.go ├── resource_google_compute_target_pool.go ├── resource_google_compute_url_map.go ├── resource_google_container_cluster.go ├── resource_google_dns_managed_zone.go ├── resource_google_dns_policy.go ├── resource_google_kms_crypto_key.go ├── resource_google_kms_key_ring.go ├── resource_google_project.go ├── resource_google_pubsub_subscription.go ├── resource_google_pubsub_topic.go ├── resource_google_service_account.go ├── resource_google_sql_database_instance.go ├── resource_google_storage_bucket.go └── templates │ ├── google_compute_autoscaler.tf.tmpl │ ├── google_compute_backend_bucket.tf.tmpl │ ├── google_compute_backend_service.tf.tmpl │ ├── google_compute_disk.tf.tmpl │ ├── google_compute_firewall.tf.tmpl │ ├── google_compute_forwarding_rule.tf.tmpl │ ├── google_compute_global_forwarding_rule.tf.tmpl │ ├── google_compute_health_check.tf.tmpl │ ├── google_compute_http_health_check.tf.tmpl │ ├── google_compute_image.tf.tmpl │ ├── google_compute_instance.tf.tmpl │ ├── google_compute_instance_group.tf.tmpl │ ├── google_compute_instance_group_manager.tf.tmpl │ ├── google_compute_instance_template.tf.tmpl │ ├── google_compute_network.tf.tmpl │ ├── google_compute_route.tf.tmpl │ ├── google_compute_snapshot.tf.tmpl │ ├── google_compute_ssl_certificate.tf.tmpl │ ├── google_compute_subnetwork.tf.tmpl │ ├── google_compute_target_http_proxy.tf.tmpl │ ├── google_compute_target_https_proxy.tf.tmpl │ ├── google_compute_target_pool.tf.tmpl │ ├── google_compute_url_map.tf.tmpl │ ├── google_container_cluster.tf.tmpl │ ├── google_dns_managed_zone.tf.tmpl │ ├── google_dns_policy.tf.tmpl │ ├── google_kms_crypto_key.tf.tmpl │ ├── google_kms_key_ring.tf.tmpl │ ├── google_project.tf.tmpl │ ├── google_pubsub_subscription.tf.tmpl │ ├── google_pubsub_topic.tf.tmpl │ ├── google_service_account.tf.tmpl │ ├── google_sql_database_instance.tf.tmpl │ └── google_storage_bucket.tf.tmpl ├── terraformUtil └── terraformUtil.go └── utils ├── cmn.go └── cmn_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | .terraform 14 | terraform.tfstate* 15 | CloudAsset-* 16 | terrafomit-gcp-import.sh* 17 | terrafomit-gcp-provider.tf* 18 | terrafomit-gcp.tf* 19 | .terrafomit-gcp.yaml 20 | terraform.tfstate.d* 21 | terrafomit-gcp-resource.tf 22 | client_secret* 23 | terrafomit-gcp 24 | .terraformit-gcp.yaml 25 | -------------------------------------------------------------------------------- /cloudasset/cloudasset_test.go: -------------------------------------------------------------------------------- 1 | package cloudasset 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "os" 7 | "strings" 8 | "testing" 9 | ) 10 | 11 | var ( 12 | metadataFile = "testdata/CloudAsset-metadata.golden" 13 | metadataAssetType = "cloudresourcemanager.googleapis.com/Project" 14 | metaByteSlice [][]byte 15 | subcommands = []string{"provider", "import", "resource"} 16 | ) 17 | 18 | func TestReadMetaFile(t *testing.T) { 19 | t.Helper() 20 | 21 | meta_strings, err := ReadMetaFile(metadataFile) 22 | if err != nil { 23 | t.Fatalf("failed to call ReadMetaFile(): %v", err) 24 | } 25 | 26 | if meta_strings == nil { 27 | t.Fatalf("the result is not an expected value: nil") 28 | } 29 | 30 | } 31 | 32 | func TestMetaStringToStruct(t *testing.T) { 33 | t.Helper() 34 | 35 | meta_strings, err := ReadMetaFile(metadataFile) 36 | if err != nil { 37 | t.Fatalf("failed to call ReadMetaFile(): %v", err) 38 | } 39 | meta_structs, err := MetaStringToStruct(meta_strings) 40 | if err != nil { 41 | t.Fatalf("failed to call MetaStringToStruct(): %v", err) 42 | } 43 | 44 | if meta_structs == nil { 45 | t.Fatalf("the result is not an expected value: nil") 46 | } else if meta_structs[0].AssetType != metadataAssetType { 47 | t.Fatalf("the result is not an expected value: %v != %v", meta_structs[0].AssetType, metadataAssetType) 48 | } 49 | 50 | } 51 | 52 | func TestMetaByteToStruct(t *testing.T) { 53 | t.Helper() 54 | 55 | f, err := os.Open(metadataFile) 56 | if err != nil { 57 | t.Fatalf("failed to oepn File: %v", err) 58 | } 59 | testbuf, err := ioutil.ReadAll(f) 60 | if err != nil { 61 | t.Fatalf("failed to read File: %v", err) 62 | } 63 | 64 | metaByteSlice := bytes.Split(testbuf, []byte("\n")) 65 | 66 | meta_structs, err := MetaByteToStruct(metaByteSlice) 67 | if err != nil { 68 | t.Fatalf("failed to call MetaByteToStruct(): %v", err) 69 | } 70 | 71 | if meta_structs == nil { 72 | t.Fatalf("the result is not an expected value: nil") 73 | } else if meta_structs[0].AssetType != metadataAssetType { 74 | t.Fatalf("the result is not an expected value: %v != %v", meta_structs[0].AssetType, metadataAssetType) 75 | } 76 | 77 | } 78 | 79 | func TestInsertIntoBuffer(t *testing.T) { 80 | t.Helper() 81 | meta_strings, err := ReadMetaFile(metadataFile) 82 | if err != nil { 83 | t.Fatalf("failed to call ReadMetaFile(): %v", err) 84 | } 85 | meta_structs, err := MetaStringToStruct(meta_strings) 86 | if err != nil { 87 | t.Fatalf("failed to call MetaStringToStruct(): %v", err) 88 | } 89 | 90 | var buf bytes.Buffer 91 | for _, subcommand := range subcommands { 92 | 93 | for _, v := range meta_structs { 94 | if err := InsertIntoBuffer(&v, &buf, ResouceNameMap, FuncMap, subcommand); err != nil { 95 | t.Fatalf("failed to call InsertIntoBuffer(): %v", err) 96 | } 97 | } 98 | if !strings.Contains(buf.String(), subcommand) { 99 | t.Fatalf("the result is not an expected value: %v doesnt contain %v", buf.String(), "subcommand") 100 | } 101 | 102 | } 103 | 104 | } 105 | func TestCreateFileForImport(t *testing.T) { 106 | t.Helper() 107 | defer os.Remove(ResourceTfName) 108 | defer os.Remove(ImportShName) 109 | defer os.Remove(ProviderTfName) 110 | 111 | meta_strings, err := ReadMetaFile(metadataFile) 112 | if err != nil { 113 | t.Fatalf("failed to call ReadMetaFile(): %v", err) 114 | } 115 | meta_structs, err := MetaStringToStruct(meta_strings) 116 | if err != nil { 117 | t.Fatalf("failed to call MetaStringToStruct(): %v", err) 118 | } 119 | 120 | for _, v := range subcommands { 121 | if err := CreateFileForImport(meta_structs, v); err != nil { 122 | t.Fatalf("failed to call CreateFileForImport(): %v subcommand:%v", err, v) 123 | } 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /cloudasset/templates/backend.tf.tmpl: -------------------------------------------------------------------------------- 1 | terraform { 2 | backend "{{.BackendType}}" { 3 | {{if eq .BackendType "local"}}path = "{{.BackendLocation}}"{{end}} 4 | {{if eq .BackendType "gcs"}}bucket = "{{.BackendLocation}}"{{end}} 5 | } 6 | } -------------------------------------------------------------------------------- /cloudasset/templates/import.sh.tmpl: -------------------------------------------------------------------------------- 1 | {{if .ResourceMetadata.Name}}terraform import -provider={{.Provider}} {{.ResourceMetadata.Name}}.{{if eq .ResourceMetadata.ResourceType "region"}}{{convertSlashAndDotToDash .Resource.Data.Name}} {{createRegion .Resource.Data.Region}}/{{.Resource.Data.Name}}{{else if eq .ResourceMetadata.ResourceType "project/zone"}}{{convertSlashAndDotToDash .Resource.Data.Name}} {{createProject .Name}}/{{createZone .Resource.Data.Zone}}/{{.Resource.Data.Name}}{{else if eq .ResourceMetadata.ResourceType "zone"}}{{convertSlashAndDotToDash .Resource.Data.Name}} {{createZone .Resource.Data.Zone}}/{{.Resource.Data.Name}}{{else if eq .ResourceMetadata.ResourceType "project"}}{{getLastWord .Resource.Data.Name | removeAtmark | convertSlashAndDotToDash }} {{.Resource.Data.Name }}{{else if eq .ResourceMetadata.ResourceType "location"}}{{getLastWord .Resource.Data.Name | removeAtmark | convertSlashAndDotToDash }} {{.Resource.Data.Location}}/{{ .Resource.Data.Name }}{{end}}{{end}} 2 | -------------------------------------------------------------------------------- /cloudasset/templates/provider.tf.tmpl: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "{{createProject .Name}}" 3 | region = "{{.DefaultRegion}}" 4 | } 5 | 6 | provider "google-beta" { 7 | project = "{{createProject .Name}}" 8 | region = "{{.DefaultRegion}}" 9 | } -------------------------------------------------------------------------------- /cloudasset/templates/resource.tf.tmpl: -------------------------------------------------------------------------------- 1 | {{if .ResourceMetadata.Name}}resource "{{.ResourceMetadata.Name}}" {{ if eq .ResourceMetadata.ResourceType "region"}}"{{convertSlashAndDotToDash .Resource.Data.Name}}"{{else if or (eq .ResourceMetadata.ResourceType "project/zone") (eq .ResourceMetadata.ResourceType "zone") }}"{{convertSlashAndDotToDash .Resource.Data.Name}}"{{else if eq .ResourceMetadata.ResourceType "project"}}"{{getLastWord .Resource.Data.Name | removeAtmark | convertSlashAndDotToDash }}"{{else if eq .ResourceMetadata.ResourceType "location"}}"{{getLastWord .Resource.Data.Name | convertSlashAndDotToDash}}"{{end}} {}{{end}} 2 | -------------------------------------------------------------------------------- /cmd/create.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "log" 7 | "os" 8 | "strings" 9 | 10 | "github.com/cloud-ace/terraformit-gcp/cloudasset" 11 | "github.com/cloud-ace/terraformit-gcp/resources" 12 | "github.com/cloud-ace/terraformit-gcp/terraformUtil" 13 | "github.com/cloud-ace/terraformit-gcp/utils" 14 | "github.com/spf13/cobra" 15 | "github.com/spf13/viper" 16 | ) 17 | 18 | var Subcommands = []string{"cloudasset", "importfiles", "tfstate", "tffile"} 19 | 20 | // createCmd represents the create command 21 | var createCmd = &cobra.Command{ 22 | Use: "create", 23 | Short: "create files or tfstate", 24 | Long: `subcommand = [ cloudasset, importfiles, tfstate, tffile] 25 | terraformit-gcp create cloudasset 26 | terraformit-gcp create importfiles -f /xxx/xxx or gs://xxxx.xxxx/xxxxxx 27 | terraformit-gcp create tfstate 28 | terraformit-gcp create tffile`, 29 | Run: func(cmd *cobra.Command, args []string) { 30 | 31 | if len(args) != 1 { 32 | log.Printf("Please set what you create. Support: %v", Subcommands) 33 | os.Exit(1) 34 | } 35 | 36 | subcommand := args[0] 37 | 38 | switch subcommand { 39 | case "cloudasset": 40 | //Cloud Assetを作成 41 | log.Println("################## create CloudAsset start ##################") 42 | objectName, err := cloudasset.CreateCloudAsset(viper.GetStringMapString("CloudAsset")["credential"], viper.GetStringMapString("CloudAsset")["bucket"], viper.GetStringMapString("CloudAsset")["project-number"], utils.ObjectNamePrefix) 43 | if err != nil { 44 | log.Printf("%+v\n", err) 45 | os.Exit(1) 46 | } 47 | fmt.Println("CloudAsset created successfully.") 48 | fmt.Println("CloudAsset object:", objectName) 49 | URI := "gs://" + viper.GetStringMapString("CloudAsset")["bucket"] + "/" + objectName 50 | fmt.Println("CloudAsset URI:", URI) 51 | log.Println("################## create CloudAsset end ##################") 52 | 53 | case "importfiles": 54 | //Cloud Assetを取得 55 | log.Println("################## create importfiles start ##################") 56 | var metaStructs []cloudasset.Metadata 57 | if createOptions.file == "" { 58 | log.Println("you must set -f option. You can set localfile or gs://xxxx/xxxx") 59 | os.Exit(1) 60 | } else if strings.Contains(createOptions.file, "gs://") { 61 | //set credential 62 | if createOptions.secret != "" { 63 | os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", createOptions.secret) 64 | } 65 | 66 | //get metadata from gcs 67 | cloudAsset, err := cloudasset.ReadFileFromGCS(createOptions.file) 68 | if err != nil { 69 | log.Printf("%+v\n", err) 70 | os.Exit(1) 71 | } 72 | sliceCloudAsset := bytes.Split(cloudAsset, []byte("\n")) 73 | //delete last slice because no data is included 74 | sliceCloudAsset = sliceCloudAsset[:len(sliceCloudAsset)-1] 75 | metaStructs, err = cloudasset.MetaByteToStruct(sliceCloudAsset) 76 | if err != nil { 77 | log.Printf("%+v\n", err) 78 | os.Exit(1) 79 | } 80 | 81 | } else { 82 | //get metadata from local file 83 | metaStrings, err := cloudasset.ReadMetaFile(createOptions.file) 84 | if err != nil { 85 | log.Printf("%+v\n", err) 86 | os.Exit(1) 87 | } 88 | metaStructs, err = cloudasset.MetaStringToStruct(metaStrings) 89 | if err != nil { 90 | log.Printf("%+v\n", err) 91 | os.Exit(1) 92 | } 93 | } 94 | 95 | //remove default resources 96 | metaStructs = cloudasset.RemoveDefaultResources(metaStructs, viper.GetStringMapString("Terraform")["resource-default-network"], viper.GetStringMapString("Terraform")["resource-default-subnetwork"], viper.GetStringMapString("Terraform")["resource-default-route"], viper.GetStringMapString("Terraform")["resource-default-firewall"]) 97 | 98 | //create file 99 | if err := cloudasset.CreateFileForImport(metaStructs, "provider", viper.GetStringMapString("Terraform")["gcp-provider-default-region"], viper.GetStringMapString("Terraform")["backend-type"], viper.GetStringMapString("Terraform")["backend-location"], viper.GetStringMapString("Terraform")["provider"]); err != nil { 100 | log.Printf("%+v\n", err) 101 | os.Exit(1) 102 | } 103 | if err := cloudasset.CreateFileForImport(metaStructs, "import", viper.GetStringMapString("Terraform")["gcp-provider-default-region"], viper.GetStringMapString("Terraform")["backend-type"], viper.GetStringMapString("Terraform")["backend-location"], viper.GetStringMapString("Terraform")["provider"]); err != nil { 104 | log.Printf("%+v\n", err) 105 | os.Exit(1) 106 | } 107 | if err := cloudasset.CreateFileForImport(metaStructs, "resource", viper.GetStringMapString("Terraform")["gcp-provider-default-region"], viper.GetStringMapString("Terraform")["backend-type"], viper.GetStringMapString("Terraform")["backend-location"], viper.GetStringMapString("Terraform")["provider"]); err != nil { 108 | log.Printf("%+v\n", err) 109 | os.Exit(1) 110 | } 111 | if viper.GetStringMapString("Terraform")["backend-type"] == "gcs" { 112 | if err := cloudasset.CreateFileForImport(metaStructs, "backend", viper.GetStringMapString("Terraform")["gcp-provider-default-region"], viper.GetStringMapString("Terraform")["backend-type"], viper.GetStringMapString("Terraform")["backend-location"], viper.GetStringMapString("Terraform")["provider"]); err != nil { 113 | log.Printf("%+v\n", err) 114 | os.Exit(1) 115 | } 116 | } 117 | 118 | log.Println("Importfiles created successfully") 119 | log.Println("################## create importfiles end ##################") 120 | 121 | case "tfstate": 122 | // //terraform init 123 | log.Println("################## create tfstate start ##################") 124 | if err := terraformUtil.TerraformCmd("init"); err != nil { 125 | log.Printf("%+v\n", err) 126 | os.Exit(1) 127 | } 128 | //workspace作成 129 | workspace := viper.GetStringMapString("Terraform")["workspace"] 130 | if workspace != "default" { 131 | if err := terraformUtil.TerraformCmd("workspace", "new", workspace); err != nil { 132 | log.Printf("%+v\n", err) 133 | os.Exit(1) 134 | } 135 | if err := terraformUtil.TerraformCmd("workspace", "select", workspace); err != nil { 136 | log.Printf("%+v\n", err) 137 | os.Exit(1) 138 | } 139 | } 140 | //terraform.sh -- terraform import 141 | if err := terraformUtil.ExecuteImportSh(); err != nil { 142 | log.Printf("%+v\n", err) 143 | os.Exit(1) 144 | } 145 | log.Println("tfstate created successfully") 146 | log.Println("################## create tfstate end ##################") 147 | 148 | case "tffile": 149 | log.Println("################## create tffile start ##################") 150 | var tfstatePath string 151 | var err error 152 | var tfstateBytes []byte 153 | if createOptions.file != "" { 154 | tfstatePath = createOptions.file 155 | log.Printf("get tfstate %v\n", tfstatePath) 156 | tfstateBytes, err = resources.ReadTfstateFile(tfstatePath) 157 | if err != nil { 158 | log.Printf("%+v\n", err) 159 | os.Exit(1) 160 | } 161 | } else { 162 | if viper.GetStringMapString("Terraform")["backend-type"] == "gcs" { 163 | url := "gs://" + viper.GetStringMapString("Terraform")["backend-location"] + "/" + viper.GetStringMapString("Terraform")["workspace"] + ".tfstate" 164 | log.Printf("get tfstate from %v\n", url) 165 | tfstateBytes, err = cloudasset.ReadFileFromGCS(url) 166 | if err != nil { 167 | log.Printf("%+v\n", err) 168 | os.Exit(1) 169 | } 170 | } else if viper.GetStringMapString("Terraform")["backend-type"] == "local" { 171 | 172 | tfstatePath, err = terraformUtil.GetTfstatePath(viper.GetStringMapString("Terraform")["workspace"]) 173 | if err != nil { 174 | log.Printf("%+v\n", err) 175 | } 176 | log.Printf("get tfstate %v\n", tfstatePath) 177 | 178 | tfstateBytes, err = resources.ReadTfstateFile(tfstatePath) 179 | if err != nil { 180 | log.Printf("%+v\n", err) 181 | os.Exit(1) 182 | } 183 | } else { 184 | log.Printf("wrong backend-type %v\n", viper.GetStringMapString("Terraform")["backend-type"]) 185 | os.Exit(1) 186 | } 187 | 188 | } 189 | 190 | tfstateStruct, err := resources.TfstateByteToStruct(tfstateBytes) 191 | if err != nil { 192 | log.Printf("%+v\n", err) 193 | os.Exit(1) 194 | } 195 | if err := resources.CreateTf(tfstateStruct); err != nil { 196 | log.Printf("%+v\n", err) 197 | os.Exit(1) 198 | } 199 | //terraform fmt 200 | if err := terraformUtil.TerraformCmd("fmt", utils.TfName); err != nil { 201 | log.Printf("%+v\n", err) 202 | } 203 | log.Println("tf file created successfully") 204 | log.Println("################## create tfstate end ##################") 205 | 206 | default: 207 | log.Printf("wrong args: %v", subcommand) 208 | log.Printf("Please set what you create. Support: %v", Subcommands) 209 | os.Exit(1) 210 | } 211 | }, 212 | } 213 | 214 | func init() { 215 | rootCmd.AddCommand(createCmd) 216 | createCmd.Flags().StringVarP(&createOptions.file, "file", "f", "", "CloudAssetAPI metadata file location or tfstate location") 217 | createCmd.Flags().StringVarP(&createOptions.secret, "secret", "s", "", "service account credential json file") 218 | } 219 | -------------------------------------------------------------------------------- /cmd/list.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "log" 7 | "os" 8 | "strings" 9 | 10 | "github.com/cloud-ace/terraformit-gcp/cloudasset" 11 | "github.com/spf13/cobra" 12 | ) 13 | 14 | // listCmd represents the list command 15 | var listCmd = &cobra.Command{ 16 | Use: "list", 17 | Short: "list", 18 | Long: `list`, 19 | Run: func(cmd *cobra.Command, args []string) { 20 | 21 | if len(args) != 1 { 22 | log.Printf("no arg") 23 | os.Exit(1) 24 | } 25 | 26 | subcommand := args[0] 27 | 28 | switch subcommand { 29 | case "cloudasset": 30 | var metaStructs []cloudasset.Metadata 31 | if createOptions.file == "" { 32 | log.Println("you must set -f option. You can set localfile or gs://xxxx/xxxx") 33 | os.Exit(1) 34 | } else if strings.Contains(createOptions.file, "gs://") { 35 | //set credential 36 | if createOptions.secret != "" { 37 | os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", createOptions.secret) 38 | } 39 | 40 | //get metadata from gcs 41 | cloudAsset, err := cloudasset.ReadFileFromGCS(createOptions.file) 42 | if err != nil { 43 | log.Printf("%+v\n", err) 44 | os.Exit(1) 45 | } 46 | sliceCloudAsset := bytes.Split(cloudAsset, []byte("\n")) 47 | //delete last slice because no data is included 48 | sliceCloudAsset = sliceCloudAsset[:len(sliceCloudAsset)-1] 49 | metaStructs, err = cloudasset.MetaByteToStruct(sliceCloudAsset) 50 | if err != nil { 51 | log.Printf("%+v\n", err) 52 | os.Exit(1) 53 | } 54 | 55 | } else { 56 | //get metadata from local file 57 | metaStrings, err := cloudasset.ReadMetaFile(createOptions.file) 58 | if err != nil { 59 | log.Printf("%+v\n", err) 60 | os.Exit(1) 61 | } 62 | metaStructs, err = cloudasset.MetaStringToStruct(metaStrings) 63 | if err != nil { 64 | log.Printf("%+v\n", err) 65 | os.Exit(1) 66 | } 67 | } 68 | supporttrimDuplicate := map[string]bool{} 69 | noSupporttrimDuplicate := map[string]bool{} 70 | for _, v := range metaStructs { 71 | v.ResourceMetadata = cloudasset.ResouceNameMap[v.AssetType] 72 | if v.ResourceMetadata.Name == "" { 73 | if noSupporttrimDuplicate[v.AssetType] == false { 74 | noSupporttrimDuplicate[v.AssetType] = true 75 | } 76 | } else { 77 | if supporttrimDuplicate[v.AssetType] == false { 78 | supporttrimDuplicate[v.AssetType] = true 79 | } 80 | } 81 | } 82 | fmt.Println("Support:") 83 | for k, _ := range supporttrimDuplicate { 84 | fmt.Println(k) 85 | } 86 | fmt.Println("\nNoSupport:") 87 | for k, _ := range noSupporttrimDuplicate { 88 | fmt.Println(k) 89 | } 90 | 91 | default: 92 | log.Printf("wrong subcommand") 93 | os.Exit(1) 94 | } 95 | }, 96 | } 97 | 98 | func init() { 99 | 100 | rootCmd.AddCommand(listCmd) 101 | listCmd.Flags().StringVarP(&createOptions.file, "file", "f", "", "CloudAssetAPI metadata file") 102 | } 103 | -------------------------------------------------------------------------------- /cmd/plan.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "log" 7 | "os" 8 | "time" 9 | 10 | "github.com/cloud-ace/terraformit-gcp/cloudasset" 11 | "github.com/cloud-ace/terraformit-gcp/resources" 12 | "github.com/cloud-ace/terraformit-gcp/terraformUtil" 13 | "github.com/cloud-ace/terraformit-gcp/utils" 14 | "github.com/spf13/cobra" 15 | "github.com/spf13/viper" 16 | ) 17 | 18 | // planCmd represents the plan command 19 | var planCmd = &cobra.Command{ 20 | Use: "plan", 21 | Short: "execute all steps", 22 | Long: `Following steps below are executed. 23 | create CloudAssetMetadata calling CloudAssetAPI 24 | get CloudAssetMetadata from GCS 25 | create ImportFiles 26 | "terraform init" 27 | "terraform workspace new" 28 | "terraform import"(create tfstate) 29 | create tffile 30 | "terraform plan"`, 31 | Run: func(cmd *cobra.Command, args []string) { 32 | 33 | if len(args) != 0 { 34 | log.Printf("args are not required") 35 | os.Exit(1) 36 | } 37 | 38 | //Cloud Assetを作成 39 | log.Println("################## create CloudAsset start ##################") 40 | objectName, err := cloudasset.CreateCloudAsset(viper.GetStringMapString("CloudAsset")["credential"], viper.GetStringMapString("CloudAsset")["bucket"], viper.GetStringMapString("CloudAsset")["project-number"], utils.ObjectNamePrefix) 41 | if err != nil { 42 | log.Printf("%+v\n", err) 43 | os.Exit(1) 44 | } 45 | fmt.Println("CloudAsset created successfully.") 46 | fmt.Println("CloudAsset object:", objectName) 47 | URI := "gs://" + viper.GetStringMapString("CloudAsset")["bucket"] + "/" + objectName 48 | fmt.Println("CloudAsset URI:", URI) 49 | time.Sleep(8 * time.Second) 50 | log.Println("################## create CloudAsset end ##################") 51 | 52 | //Cloud Assetを取得 53 | log.Println("################## create importfiles start ##################") 54 | var metaStructs []cloudasset.Metadata 55 | //リモートファイルから取得 56 | cloudAsset, err := cloudasset.ReadFileFromGCS(URI) 57 | if err != nil { 58 | log.Printf("%+v\n", err) 59 | os.Exit(1) 60 | } 61 | sliceCloudAsset := bytes.Split(cloudAsset, []byte("\n")) 62 | //delete last slice because no data is included 63 | sliceCloudAsset = sliceCloudAsset[:len(sliceCloudAsset)-1] 64 | metaStructs, err = cloudasset.MetaByteToStruct(sliceCloudAsset) 65 | if err != nil { 66 | log.Printf("%+v\n", err) 67 | os.Exit(1) 68 | } 69 | 70 | //remove default resources 71 | metaStructs = cloudasset.RemoveDefaultResources(metaStructs, viper.GetStringMapString("Terraform")["resource-default-network"], viper.GetStringMapString("Terraform")["resource-default-subnetwork"], viper.GetStringMapString("Terraform")["resource-default-route"], viper.GetStringMapString("Terraform")["resource-default-firewall"]) 72 | 73 | // terraform init/importのためのファイルを作成 74 | if err := cloudasset.CreateFileForImport(metaStructs, "provider", viper.GetStringMapString("Terraform")["gcp-provider-default-region"], viper.GetStringMapString("Terraform")["backend-type"], viper.GetStringMapString("Terraform")["backend-location"], viper.GetStringMapString("Terraform")["provider"]); err != nil { 75 | log.Printf("%+v\n", err) 76 | os.Exit(1) 77 | } 78 | if err := cloudasset.CreateFileForImport(metaStructs, "import", viper.GetStringMapString("Terraform")["gcp-provider-default-region"], viper.GetStringMapString("Terraform")["backend-type"], viper.GetStringMapString("Terraform")["backend-location"], viper.GetStringMapString("Terraform")["provider"]); err != nil { 79 | log.Printf("%+v\n", err) 80 | os.Exit(1) 81 | } 82 | if err := cloudasset.CreateFileForImport(metaStructs, "resource", viper.GetStringMapString("Terraform")["gcp-provider-default-region"], viper.GetStringMapString("Terraform")["backend-type"], viper.GetStringMapString("Terraform")["backend-location"], viper.GetStringMapString("Terraform")["provider"]); err != nil { 83 | log.Printf("%+v\n", err) 84 | os.Exit(1) 85 | } 86 | if viper.GetStringMapString("Terraform")["backend-type"] == "gcs" { 87 | if err := cloudasset.CreateFileForImport(metaStructs, "backend", viper.GetStringMapString("Terraform")["gcp-provider-default-region"], viper.GetStringMapString("Terraform")["backend-type"], viper.GetStringMapString("Terraform")["backend-location"], viper.GetStringMapString("Terraform")["provider"]); err != nil { 88 | log.Printf("%+v\n", err) 89 | os.Exit(1) 90 | } 91 | } 92 | log.Println("Importfiles created successfully") 93 | log.Println("################## create importfiles end ##################") 94 | 95 | // //terraform init 96 | log.Println("################## create tfstate start ##################") 97 | if err := terraformUtil.TerraformCmd("init"); err != nil { 98 | log.Printf("%+v\n", err) 99 | os.Exit(1) 100 | } 101 | //workspace作成 102 | workspace := viper.GetStringMapString("Terraform")["workspace"] 103 | if workspace != "default" { 104 | if err := terraformUtil.TerraformCmd("workspace", "new", workspace); err != nil { 105 | log.Printf("%+v\n", err) 106 | os.Exit(1) 107 | } 108 | if err := terraformUtil.TerraformCmd("workspace", "select", workspace); err != nil { 109 | log.Printf("%+v\n", err) 110 | os.Exit(1) 111 | } 112 | } 113 | //terraform.sh -- terraform import 114 | if err := terraformUtil.ExecuteImportSh(); err != nil { 115 | log.Printf("%+v\n", err) 116 | os.Exit(1) 117 | } 118 | log.Println("tfstate created successfully") 119 | log.Println("################## create tfstate end ##################") 120 | 121 | log.Println("################## create tffile start ##################") 122 | var tfstatePath string 123 | var tfstateBytes []byte 124 | if createOptions.file != "" { 125 | tfstatePath = createOptions.file 126 | log.Printf("get tfstate %v\n", tfstatePath) 127 | tfstateBytes, err = resources.ReadTfstateFile(tfstatePath) 128 | if err != nil { 129 | log.Printf("%+v\n", err) 130 | os.Exit(1) 131 | } 132 | } else { 133 | if viper.GetStringMapString("Terraform")["backend-type"] == "gcs" { 134 | url := "gs://" + viper.GetStringMapString("Terraform")["backend-location"] + "/" + viper.GetStringMapString("Terraform")["workspace"] + ".tfstate" 135 | log.Printf("get tfstate from %v\n", url) 136 | tfstateBytes, err = cloudasset.ReadFileFromGCS(url) 137 | if err != nil { 138 | log.Printf("%+v\n", err) 139 | os.Exit(1) 140 | } 141 | } else if viper.GetStringMapString("Terraform")["backend-type"] == "local" { 142 | 143 | tfstatePath, err = terraformUtil.GetTfstatePath(viper.GetStringMapString("Terraform")["workspace"]) 144 | if err != nil { 145 | log.Printf("%+v\n", err) 146 | } 147 | log.Printf("get tfstate %v\n", tfstatePath) 148 | 149 | tfstateBytes, err = resources.ReadTfstateFile(tfstatePath) 150 | if err != nil { 151 | log.Printf("%+v\n", err) 152 | os.Exit(1) 153 | } 154 | } else { 155 | log.Printf("wrong backend-type %v\n", viper.GetStringMapString("Terraform")["backend-type"]) 156 | os.Exit(1) 157 | } 158 | 159 | } 160 | 161 | tfstateStruct, err := resources.TfstateByteToStruct(tfstateBytes) 162 | if err != nil { 163 | log.Printf("%+v\n", err) 164 | os.Exit(1) 165 | } 166 | if err := resources.CreateTf(tfstateStruct); err != nil { 167 | log.Printf("%+v\n", err) 168 | os.Exit(1) 169 | } 170 | //terraform fmt 171 | if err := terraformUtil.TerraformCmd("fmt", utils.TfName); err != nil { 172 | log.Printf("%+v\n", err) 173 | } 174 | log.Println("tf file created successfully") 175 | log.Println("################## create tfstate end ##################") 176 | 177 | //terraform plan 178 | log.Println("################## terraform plan start ##################") 179 | if err := terraformUtil.TerraformCmd("plan"); err != nil { 180 | log.Printf("%+v\n", err) 181 | os.Exit(1) 182 | } 183 | log.Println("plan sccess") 184 | log.Println("################## terraform plan end ##################") 185 | }, 186 | } 187 | 188 | func init() { 189 | rootCmd.AddCommand(planCmd) 190 | } 191 | -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2019 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "fmt" 19 | "os" 20 | 21 | "github.com/spf13/cobra" 22 | "github.com/spf13/viper" 23 | ) 24 | 25 | var cfgFile string 26 | 27 | // rootCmd represents the base command when called without any subcommands 28 | var rootCmd = &cobra.Command{ 29 | Use: "terraformit-gcp", 30 | Short: "GCP terraforming tool", 31 | Long: `terraformit-gcp is an open source command line tool 32 | for generating tf files and tfstate from existing GCP resources.`, 33 | } 34 | 35 | // Execute adds all child commands to the root command and sets flags appropriately. 36 | // This is called by main.main(). It only needs to happen once to the rootCmd. 37 | func Execute() { 38 | if err := rootCmd.Execute(); err != nil { 39 | fmt.Println(err) 40 | os.Exit(1) 41 | } 42 | } 43 | 44 | type CreateOptions struct { 45 | file string 46 | secret string 47 | } 48 | 49 | var ( 50 | createOptions = &CreateOptions{} 51 | ) 52 | 53 | func init() { 54 | cobra.OnInitialize(initConfig) 55 | } 56 | 57 | // initConfig reads in config file and ENV variables if set. 58 | func initConfig() { 59 | if cfgFile != "" { 60 | // Use config file from the flag. 61 | viper.SetConfigFile(cfgFile) 62 | } else { 63 | // Find home directory. 64 | home := "." 65 | 66 | // Search config in home directory with name ".test" (without extension). 67 | viper.AddConfigPath(home) 68 | viper.SetConfigName(".terraformit-gcp") 69 | viper.SetConfigType("yaml") 70 | } 71 | 72 | viper.AutomaticEnv() // read in environment variables that match 73 | // If a config file is found, read it in. 74 | if err := viper.ReadInConfig(); err == nil { 75 | fmt.Println("Using config file:", viper.ConfigFileUsed()) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/cloud-ace/terraformit-gcp 2 | 3 | go 1.12 4 | 5 | require ( 6 | cloud.google.com/go v0.39.0 7 | github.com/google/oauth2l v0.9.1-0.20190515162341-cf46f2e826b1 8 | github.com/spf13/cobra v0.0.4 9 | github.com/spf13/viper v1.4.0 10 | golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522 11 | ) 12 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2019 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "github.com/cloud-ace/terraformit-gcp/cmd" 18 | 19 | func main() { 20 | cmd.Execute() 21 | } 22 | -------------------------------------------------------------------------------- /resources/resource_google_compute_autoscaler.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_compute_autoscaler struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | AutoscalingPolicy []Params `json:"autoscaling_policy_cooldown_period"` 14 | CreationTimestamp string `json:"creation_timestamp"` 15 | Description string `json:"description"` 16 | ID string `json:"id"` 17 | Name string `json:"name"` 18 | Project string `json:"project"` 19 | SelfLink string `json:"self_link"` 20 | Target string `json:"target"` 21 | Zone string `json:"zone"` 22 | } `json:"attributes"` 23 | Meta struct { 24 | SchemaVersion string `json:"schema_version"` 25 | } `json:"meta"` 26 | Tainted bool `json:"tainted"` 27 | } `json:"primary"` 28 | Deposed []interface{} `json:"deposed"` 29 | Provider string `json:"provider"` 30 | } 31 | 32 | type AutoscalingPolicy struct { 33 | Number string 34 | CooldownPeriod string `json:"cooldown_period"` 35 | CPUTarget string `json:"cpu_target"` 36 | LoadBalancingTarget string `json:"load_balancing_target"` 37 | MaxReplica string `json:"max_replica"` 38 | MinReplica string `json:"min_replica"` 39 | Metric []Params `json:"metric"` 40 | } 41 | 42 | func (d *AutoscalingPolicy) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 43 | if strings.Contains(key, "cooldown_period") { 44 | d.CooldownPeriod = value 45 | } else if strings.Contains(key, "cpu_target") { 46 | d.CPUTarget = value 47 | } else if strings.Contains(key, "load_balancing_target") { 48 | d.LoadBalancingTarget = value 49 | } else if strings.Contains(key, "max_replica") { 50 | d.MaxReplica = value 51 | } else if strings.Contains(key, "min_replica") { 52 | d.MinReplica = value 53 | } else if strings.Contains(key, "metric") && strings.Contains(key, "name") { 54 | //autoscaling_policy.#.metricまでを取得 55 | Number := CreateNumberFromKey(key, 2) 56 | d.Metric = CreateStructSlice(attributes_map, attributesKey, Number, 3, NewMetric) 57 | } 58 | } 59 | 60 | func (d *AutoscalingPolicy) SetNumber(num string) { 61 | d.Number = num 62 | } 63 | 64 | func (d *AutoscalingPolicy) GetNumber() string { 65 | return d.Number 66 | } 67 | 68 | func NewAutoscalingPolicy(num string) Params { 69 | var s Params = new(AutoscalingPolicy) 70 | s.SetNumber(num) 71 | return s 72 | } 73 | 74 | type Metric struct { 75 | Number string 76 | Target string 77 | Name string 78 | Type string 79 | } 80 | 81 | func (d *Metric) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 82 | if strings.Contains(key, "target") { 83 | d.Target = value 84 | } else if strings.Contains(key, "name") { 85 | d.Name = value 86 | } else if strings.Contains(key, "type") { 87 | d.Type = value 88 | } 89 | } 90 | 91 | func (d *Metric) SetNumber(num string) { 92 | d.Number = num 93 | } 94 | 95 | func (d *Metric) GetNumber() string { 96 | return d.Number 97 | } 98 | 99 | func NewMetric(num string) Params { 100 | var s Params = new(Metric) 101 | s.SetNumber(num) 102 | return s 103 | } 104 | 105 | func Newgoogle_compute_autoscaler(resourceData map[string]interface{}, resourceName string) *google_compute_autoscaler { 106 | 107 | resource := new(google_compute_autoscaler) 108 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 109 | attributesKey := CreateAttributesKey(attributes_map) 110 | MapToStruct(resourceData, resource) 111 | resource.Primary.ID = resourceName 112 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 113 | 114 | //attributes need to transform 115 | resource.Primary.Attributes.AutoscalingPolicy = CreateStructSlice(attributes_map, attributesKey, "autoscaling_policy", 1, NewAutoscalingPolicy) 116 | 117 | //beta 118 | if resourceData["provider"] == "provider.google-beta" { 119 | } 120 | return resource 121 | } 122 | -------------------------------------------------------------------------------- /resources/resource_google_compute_backend_bucket.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_backend_bucket struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | BucketName string `json:"bucket_name"` 10 | CdnPolicy []Params `json:"cdn_policy"` 11 | CreationTimestamp string `json:"creation_timestamp"` 12 | Description string `json:"description"` 13 | EnableCdn string `json:"enable_cdn"` 14 | ID string `json:"id"` 15 | Name string `json:"name"` 16 | Project string `json:"project"` 17 | SelfLink string `json:"self_link"` 18 | } `json:"attributes"` 19 | Meta struct { 20 | SchemaVersion string `json:"schema_version"` 21 | } `json:"meta"` 22 | Tainted bool `json:"tainted"` 23 | } `json:"primary"` 24 | Deposed []interface{} `json:"deposed"` 25 | Provider string `json:"provider"` 26 | } 27 | 28 | func Newgoogle_compute_backend_bucket(resourceData map[string]interface{}, resourceName string) *google_compute_backend_bucket { 29 | 30 | resource := new(google_compute_backend_bucket) 31 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 32 | attributesKey := CreateAttributesKey(attributes_map) 33 | MapToStruct(resourceData, resource) 34 | resource.Primary.ID = resourceName 35 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 36 | 37 | //attributes need to transform 38 | resource.Primary.Attributes.CdnPolicy = CreateStructSlice(attributes_map, attributesKey, "cdn_policy", 1, NewCdnPolicy) 39 | 40 | return resource 41 | } 42 | -------------------------------------------------------------------------------- /resources/resource_google_compute_backend_service.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_compute_backend_service struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | AffinityCookieTTLSec string `json:"affinity_cookie_ttl_sec"` 14 | Backend []Params `json:"backend"` 15 | CdnPolicy []Params `json:"cdn_policy"` 16 | ConnectionDrainingTimeoutSec string `json:"connection_draining_timeout_sec"` 17 | CreationTimestamp string `json:"creation_timestamp"` 18 | Description string `json:"description"` 19 | EnableCdn string `json:"enable_cdn"` 20 | Fingerprint string `json:"fingerprint"` 21 | HealthChecks []string `json:"health_checks"` 22 | Iap []Params `json:"iap"` 23 | ID string `json:"id"` 24 | LoadBalancingScheme string `json:"load_balancing_scheme"` 25 | Name string `json:"name"` 26 | PortName string `json:"port_name"` 27 | Project string `json:"project"` 28 | Protocol string `json:"protocol"` 29 | SecurityPolicy string `json:"security_policy"` 30 | SelfLink string `json:"self_link"` 31 | SessionAffinity string `json:"session_affinity"` 32 | TimeoutSec string `json:"timeout_sec"` 33 | } `json:"attributes"` 34 | Meta struct { 35 | SchemaVersion string `json:"schema_version"` 36 | } `json:"meta"` 37 | Tainted bool `json:"tainted"` 38 | } `json:"primary"` 39 | Deposed []interface{} `json:"deposed"` 40 | Provider string `json:"provider"` 41 | } 42 | 43 | type Backend struct { 44 | Number string 45 | BalancingMode string `json:"balancing_mode"` 46 | CapacityScaler string `json:"capacity_scaler"` 47 | Description string `json:"description"` 48 | Group string `json:"group"` 49 | MaxConnections string `json:"max_connections"` 50 | MaxConnectionsPerInstance string `json:"max_connections_per_instance"` 51 | MaxRate string `json:"max_rate"` 52 | MaxRatePerInstance string `json:"max_rate_per_instance"` 53 | MaxUtilization string `json:"max_utilization"` 54 | } 55 | 56 | func (d *Backend) SetNumber(num string) { 57 | d.Number = num 58 | } 59 | func (d *Backend) GetNumber() string { 60 | return d.Number 61 | } 62 | func NewBackend(num string) Params { 63 | var s Params = new(Backend) 64 | s.SetNumber(num) 65 | return s 66 | } 67 | func (d *Backend) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 68 | if strings.Contains(key, "balancing_mode") { 69 | d.BalancingMode = value 70 | } else if strings.Contains(key, "capacity_scaler") { 71 | d.CapacityScaler = value 72 | } else if strings.Contains(key, "description") { 73 | d.Description = value 74 | } else if strings.Contains(key, "group") { 75 | d.Group = value 76 | } else if strings.Contains(key, "max_connections_per_instance") { 77 | d.MaxConnectionsPerInstance = value 78 | } else if strings.Contains(key, "max_connection") { 79 | d.MaxConnections = value 80 | } else if strings.Contains(key, "max_rate_per_instance") { 81 | d.MaxRatePerInstance = value 82 | } else if strings.Contains(key, "max_rate") { 83 | d.MaxRate = value 84 | } else if strings.Contains(key, "max_utilization") { 85 | d.MaxUtilization = value 86 | } 87 | } 88 | 89 | type CdnPolicy struct { 90 | Number string 91 | CacheKeyPolicy []Params `json:"cache_key_policy"` 92 | SignedUrlCacheMaxAgeSec string `json:"signed_url_cache_max_age_sec"` 93 | } 94 | 95 | func (d *CdnPolicy) SetNumber(num string) { 96 | d.Number = num 97 | } 98 | func (d *CdnPolicy) GetNumber() string { 99 | return d.Number 100 | } 101 | func NewCdnPolicy(num string) Params { 102 | var s Params = new(CdnPolicy) 103 | s.SetNumber(num) 104 | return s 105 | } 106 | func (d *CdnPolicy) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 107 | if strings.Contains(key, "cache_key_policy") { 108 | Number := CreateNumberFromKey(key, 2) 109 | d.CacheKeyPolicy = CreateStructSlice(attributes_map, attributesKey, Number, 3, NewCacheKeyPolicy) 110 | } else if strings.Contains(key, "signed_url_cache_max_age_sec") { 111 | d.SignedUrlCacheMaxAgeSec = value 112 | } 113 | } 114 | 115 | type CacheKeyPolicy struct { 116 | Number string 117 | IncludHost string `json:"include_host"` 118 | IncludProtocol string `json:"include_protocol"` 119 | IncludQueryString string `json:"include_query_string"` 120 | QueryStringBlackList string `json:"query_string_blacklist"` 121 | QueryStringWhiteList string `json:"query_string_whitelist"` 122 | } 123 | 124 | func (d *CacheKeyPolicy) SetNumber(num string) { 125 | d.Number = num 126 | } 127 | func (d *CacheKeyPolicy) GetNumber() string { 128 | return d.Number 129 | } 130 | func NewCacheKeyPolicy(num string) Params { 131 | var s Params = new(CacheKeyPolicy) 132 | s.SetNumber(num) 133 | return s 134 | } 135 | func (d *CacheKeyPolicy) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 136 | if strings.Contains(key, "include_host") { 137 | d.IncludHost = value 138 | } else if strings.Contains(key, "include_protocol") { 139 | d.IncludProtocol = value 140 | } else if strings.Contains(key, "include_query_string") { 141 | d.IncludQueryString = value 142 | } else if strings.Contains(key, "query_string_blacklist") { 143 | d.QueryStringBlackList = value 144 | } else if strings.Contains(key, "query_string_whitelist") { 145 | d.QueryStringWhiteList = value 146 | } 147 | } 148 | 149 | type Iap struct { 150 | Number string 151 | Oauth2ClientId string `json:"oauth2_client_id"` 152 | Oauth2ClientSecret string `json:"oauth2_client_secret"` 153 | Oauth2ClientSecretSha256 string `json:"oauth2_client_secret_sha256"` 154 | } 155 | 156 | func (d *Iap) SetNumber(num string) { 157 | d.Number = num 158 | } 159 | func (d *Iap) GetNumber() string { 160 | return d.Number 161 | } 162 | func NewIap(num string) Params { 163 | var s Params = new(Iap) 164 | s.SetNumber(num) 165 | return s 166 | } 167 | func (d *Iap) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 168 | if strings.Contains(key, "oauth2_client_id") { 169 | d.Oauth2ClientId = value 170 | } else if strings.Contains(key, "oauth2_client_secret_sha256") { 171 | d.Oauth2ClientSecretSha256 = value 172 | } else if strings.Contains(key, "oauth2_client_secret") { 173 | d.Oauth2ClientSecret = value 174 | } 175 | } 176 | 177 | func Newgoogle_compute_backend_service(resourceData map[string]interface{}, resourceName string) *google_compute_backend_service { 178 | 179 | resource := new(google_compute_backend_service) 180 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 181 | attributesKey := CreateAttributesKey(attributes_map) 182 | MapToStruct(resourceData, resource) 183 | resource.Primary.ID = resourceName 184 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 185 | 186 | //attributes need to transform 187 | resource.Primary.Attributes.HealthChecks = CreateStringSlice(attributes_map, attributesKey, "health_checks") 188 | resource.Primary.Attributes.Backend = CreateStructSlice(attributes_map, attributesKey, "backend", 1, NewBackend) 189 | resource.Primary.Attributes.CdnPolicy = CreateStructSlice(attributes_map, attributesKey, "cdn_policy", 1, NewCdnPolicy) 190 | resource.Primary.Attributes.Iap = CreateStructSlice(attributes_map, attributesKey, "iap", 1, NewIap) 191 | 192 | //beta 193 | if resourceData["provider"] == "provider.google-beta" { 194 | } 195 | return resource 196 | } 197 | -------------------------------------------------------------------------------- /resources/resource_google_compute_disk.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_compute_disk struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | CreationTimestamp string `json:"creation_timestamp"` 14 | Description string `json:"description"` 15 | DiskEncryptionKey []Params `json:"disk_encryption_key"` 16 | ID string `json:"id"` 17 | Image string `json:"image"` 18 | LabelFingerprint string `json:"label_fingerprint"` 19 | Labels map[string]string `json:"labels"` 20 | LastAttachTimestamp string `json:"last_attach_timestamp"` 21 | LastDetachTimestamp string `json:"last_detach_timestamp"` 22 | Name string `json:"name"` 23 | PhysicalBlockSizeBytes string `json:"physical_block_size_bytes"` 24 | Project string `json:"project"` 25 | SelfLink string `json:"self_link"` 26 | Size string `json:"size"` 27 | Snapshot string `json:"snapshot"` 28 | SourceImageEncryptionKey []Params `json:"source_image_encryption_key"` 29 | SourceSnapshotEncryptionKey []Params `json:"source_snapshot_encryption_key"` 30 | SourceSnapshotID string `json:"source_snapshot_id"` 31 | Type string `json:"type"` 32 | Users []string `json:"users"` 33 | Zone string `json:"zone"` 34 | } `json:"attributes"` 35 | Meta struct { 36 | SchemaVersion string `json:"schema_version"` 37 | } `json:"meta"` 38 | Tainted bool `json:"tainted"` 39 | } `json:"primary"` 40 | Deposed []interface{} `json:"deposed"` 41 | Provider string `json:"provider"` 42 | } 43 | type EncryptionKey struct { 44 | Number string 45 | KmsKeySelfLink string 46 | RawKey string 47 | Sha256 string 48 | } 49 | 50 | func (d *EncryptionKey) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 51 | if strings.Contains(key, "kms_key_self_link") { 52 | d.KmsKeySelfLink = value 53 | } else if strings.Contains(key, "raw_key") { 54 | d.RawKey = value 55 | } else if strings.Contains(key, "sha256") { 56 | d.Sha256 = value 57 | } 58 | } 59 | 60 | func (d *EncryptionKey) SetNumber(num string) { 61 | d.Number = num 62 | } 63 | 64 | func (d *EncryptionKey) GetNumber() string { 65 | return d.Number 66 | } 67 | 68 | func NewEncryptionKey(num string) Params { 69 | var s Params = new(EncryptionKey) 70 | s.SetNumber(num) 71 | return s 72 | } 73 | 74 | func Newgoogle_compute_disk(resourceData map[string]interface{}, resourceName string) *google_compute_disk { 75 | 76 | resource := new(google_compute_disk) 77 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 78 | attributesKey := CreateAttributesKey(attributes_map) 79 | MapToStruct(resourceData, resource) 80 | resource.Primary.ID = resourceName 81 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 82 | 83 | //attributes need to transform 84 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 85 | resource.Primary.Attributes.Users = CreateStringSlice(attributes_map, attributesKey, "users") 86 | resource.Primary.Attributes.DiskEncryptionKey = CreateStructSlice(attributes_map, attributesKey, "disk_encryption_key", 1, NewEncryptionKey) 87 | resource.Primary.Attributes.SourceImageEncryptionKey = CreateStructSlice(attributes_map, attributesKey, "source_image_encryption_key", 1, NewEncryptionKey) 88 | resource.Primary.Attributes.SourceSnapshotEncryptionKey = CreateStructSlice(attributes_map, attributesKey, "source_snapshot_encryption_key", 1, NewEncryptionKey) 89 | //beta 90 | if resourceData["provider"] == "provider.google-beta" { 91 | } 92 | return resource 93 | } 94 | -------------------------------------------------------------------------------- /resources/resource_google_compute_firewall.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_compute_firewall struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | Allow []Params `json:"allow"` 14 | CreationTimestamp string `json:"creation_timestamp"` 15 | Deny []Params `json:"deny"` 16 | Description string `json:"description"` 17 | DestinationRanges []string `json:"destination_ranges"` 18 | Direction string `json:"direction"` 19 | Disabled string `json:"disabled"` 20 | ID string `json:"id"` 21 | Name string `json:"name"` 22 | Network string `json:"network"` 23 | Priority string `json:"priority"` 24 | Project string `json:"project"` 25 | SelfLink string `json:"self_link"` 26 | SourceRanges []string `json:"source_ranges"` 27 | SourceServiceAccounts []string `json:"source_service_accounts"` 28 | SourceTags []string `json:"source_tags"` 29 | TargetServiceAccounts []string `json:"target_service_accounts"` 30 | TargetTags []string `json:"target_tags"` 31 | EnableLogging string `json:"enable_logging"` 32 | } `json:"attributes"` 33 | Meta struct { 34 | SchemaVersion string `json:"schema_version"` 35 | } `json:"meta"` 36 | Tainted bool `json:"tainted"` 37 | } `json:"primary"` 38 | Deposed []interface{} `json:"deposed"` 39 | Provider string `json:"provider"` 40 | } 41 | 42 | type AllowOrDeny struct { 43 | Number string 44 | Protocol string 45 | Ports []string 46 | } 47 | 48 | func (d *AllowOrDeny) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 49 | if strings.Contains(key, "protocol") { 50 | d.Protocol = value 51 | } else if strings.Contains(key, "ports") { 52 | d.Ports = append(d.Ports, value) 53 | } 54 | } 55 | 56 | func (d *AllowOrDeny) SetNumber(num string) { 57 | d.Number = num 58 | } 59 | 60 | func (d *AllowOrDeny) GetNumber() string { 61 | return d.Number 62 | } 63 | 64 | func NewAllowOrDeny(num string) Params { 65 | var s Params = new(AllowOrDeny) 66 | s.SetNumber(num) 67 | return s 68 | } 69 | 70 | func Newgoogle_compute_firewall(resourceData map[string]interface{}, resourceName string) *google_compute_firewall { 71 | 72 | resource := new(google_compute_firewall) 73 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 74 | attributesKey := CreateAttributesKey(attributes_map) 75 | MapToStruct(resourceData, resource) 76 | resource.Primary.ID = resourceName 77 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 78 | 79 | //attributes need to transform 80 | resource.Primary.Attributes.DestinationRanges = CreateStringSlice(attributes_map, attributesKey, "destination_ranges") 81 | resource.Primary.Attributes.SourceRanges = CreateStringSlice(attributes_map, attributesKey, "source_ranges") 82 | resource.Primary.Attributes.SourceServiceAccounts = CreateStringSlice(attributes_map, attributesKey, "source_service_accounts") 83 | resource.Primary.Attributes.SourceTags = CreateStringSlice(attributes_map, attributesKey, "source_tags") 84 | resource.Primary.Attributes.TargetTags = CreateStringSlice(attributes_map, attributesKey, "target_tags") 85 | resource.Primary.Attributes.TargetServiceAccounts = CreateStringSlice(attributes_map, attributesKey, "target_service_accounts") 86 | resource.Primary.Attributes.Allow = CreateStructSlice(attributes_map, attributesKey, "allow", 1, NewAllowOrDeny) 87 | resource.Primary.Attributes.Deny = CreateStructSlice(attributes_map, attributesKey, "deny", 1, NewAllowOrDeny) 88 | 89 | //beta 90 | if resourceData["provider"] == "provider.google-beta" { 91 | resource.Primary.Attributes.EnableLogging = attributes_map["enable_logging"].(string) 92 | } 93 | return resource 94 | } 95 | -------------------------------------------------------------------------------- /resources/resource_google_compute_forwarding_rule.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_forwarding_rule struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | AllPorts string `json:"all_ports"` 10 | BackendService string `json:"backend_service"` 11 | CreationTimestamp string `json:"creation_timestamp"` 12 | Description string `json:"description"` 13 | ID string `json:"id"` 14 | IPAddress string `json:"ip_address"` 15 | IPProtocol string `json:"ip_protocol"` 16 | IPVersion string `json:"ip_version"` 17 | LoadBalancingScheme string `json:"load_balancing_scheme"` 18 | Name string `json:"name"` 19 | Network string `json:"network"` 20 | NetworkTier string `json:"network_tier"` 21 | PortRange string `json:"port_range"` 22 | Ports []string `json:"ports"` 23 | Project string `json:"project"` 24 | Region string `json:"region"` 25 | SelfLink string `json:"self_link"` 26 | ServiceLabel string `json:"service_label"` 27 | ServiceName string `json:"service_name"` 28 | Subnetwork string `json:"subnetwork"` 29 | Target string `json:"target"` 30 | Labels map[string]string `json:"labels"` 31 | } `json:"attributes"` 32 | Meta struct { 33 | SchemaVersion string `json:"schema_version"` 34 | } `json:"meta"` 35 | Tainted bool `json:"tainted"` 36 | } `json:"primary"` 37 | Deposed []interface{} `json:"deposed"` 38 | Provider string `json:"provider"` 39 | } 40 | 41 | func Newgoogle_compute_forwarding_rule(resourceData map[string]interface{}, resourceName string) *google_compute_forwarding_rule { 42 | 43 | resource := new(google_compute_forwarding_rule) 44 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 45 | attributesKey := CreateAttributesKey(attributes_map) 46 | MapToStruct(resourceData, resource) 47 | resource.Primary.ID = resourceName 48 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 49 | 50 | //attributes need to transform 51 | resource.Primary.Attributes.Ports = CreateStringSlice(attributes_map, attributesKey, "ports") 52 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 53 | 54 | //beta 55 | if resourceData["provider"] == "provider.google-beta" { 56 | } 57 | return resource 58 | } 59 | -------------------------------------------------------------------------------- /resources/resource_google_compute_global_forwarding_rule.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_global_forwarding_rule struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | Description string `json:"description"` 10 | ID string `json:"id"` 11 | IPAddress string `json:"ip_address"` 12 | IPProtocol string `json:"ip_protocol"` 13 | IPVersion string `json:"ip_version"` 14 | Labels map[string]string `json:"labels"` 15 | Name string `json:"name"` 16 | PortRange string `json:"port_range"` 17 | Project string `json:"project"` 18 | SelfLink string `json:"self_link"` 19 | Target string `json:"target"` 20 | } `json:"attributes"` 21 | Meta struct { 22 | SchemaVersion string `json:"schema_version"` 23 | } `json:"meta"` 24 | Tainted bool `json:"tainted"` 25 | } `json:"primary"` 26 | Deposed []interface{} `json:"deposed"` 27 | Provider string `json:"provider"` 28 | } 29 | 30 | func Newgoogle_compute_global_forwarding_rule(resourceData map[string]interface{}, resourceName string) *google_compute_global_forwarding_rule { 31 | 32 | resource := new(google_compute_global_forwarding_rule) 33 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 34 | //attributesKey := CreateAttributesKey(attributes_map) 35 | MapToStruct(resourceData, resource) 36 | resource.Primary.ID = resourceName 37 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 38 | 39 | //attributes need to transform 40 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 41 | 42 | //beta 43 | if resourceData["provider"] == "provider.google-beta" { 44 | } 45 | return resource 46 | } 47 | -------------------------------------------------------------------------------- /resources/resource_google_compute_health_check.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import "strings" 4 | 5 | type google_compute_health_check struct { 6 | Type string `json:"type"` 7 | DependsOn []string `json:"depends_on"` 8 | Primary struct { 9 | ID string `json:"id"` 10 | Attributes struct { 11 | CheckIntervalSec string `json:"check_interval_sec"` 12 | CreationTimestamp string `json:"creation_timestamp"` 13 | Description string `json:"description"` 14 | HealthyThreshold string `json:"healthy_threshold"` 15 | ID string `json:"id"` 16 | Name string `json:"name"` 17 | Project string `json:"project"` 18 | SelfLink string `json:"self_link"` 19 | HTTPSHealthCheck []Params `json:"https_health_check.port"` 20 | HTTPHealthCheck []Params `json:"http_health_check.port"` 21 | SslHealthCheck []Params `json:"ssl_health_check.port"` 22 | TCPHealthCheck []Params `json:"tcp_health_check.port"` 23 | TimeoutSec string `json:"timeout_sec"` 24 | Type string `json:"type"` 25 | UnhealthyThreshold string `json:"unhealthy_threshold"` 26 | } `json:"attributes"` 27 | Meta struct { 28 | SchemaVersion string `json:"schema_version"` 29 | } `json:"meta"` 30 | Tainted bool `json:"tainted"` 31 | } `json:"primary"` 32 | Deposed []interface{} `json:"deposed"` 33 | Provider string `json:"provider"` 34 | } 35 | 36 | type HealthCheck struct { 37 | Number string 38 | Port string `json:"port"` 39 | ProxyHeader string `json:"proxy_header"` 40 | RequestPath string `json:"request_path"` 41 | Response string `json:"response"` 42 | Host string `json:"host"` 43 | Request string `json:"request_path"` 44 | } 45 | 46 | func (d *HealthCheck) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 47 | if strings.Contains(key, "port") { 48 | d.Port = value 49 | } else if strings.Contains(key, "proxy_header") { 50 | d.ProxyHeader = value 51 | } else if strings.Contains(key, "request_path") { 52 | d.RequestPath = value 53 | } else if strings.Contains(key, "response") { 54 | d.Response = value 55 | } else if strings.Contains(key, "host") { 56 | d.Host = value 57 | //request_pathが先に評価される 58 | } else if strings.Contains(key, "request") { 59 | d.Request = value 60 | } 61 | } 62 | 63 | func (d *HealthCheck) SetNumber(num string) { 64 | d.Number = num 65 | } 66 | 67 | func (d *HealthCheck) GetNumber() string { 68 | return d.Number 69 | } 70 | 71 | func NewHealthCheck(num string) Params { 72 | var s Params = new(HealthCheck) 73 | s.SetNumber(num) 74 | return s 75 | } 76 | 77 | func Newgoogle_compute_health_check(resourceData map[string]interface{}, resourceName string) *google_compute_health_check { 78 | 79 | resource := new(google_compute_health_check) 80 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 81 | attributesKey := CreateAttributesKey(attributes_map) 82 | MapToStruct(resourceData, resource) 83 | resource.Primary.ID = resourceName 84 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 85 | 86 | //attributes need to transform 87 | resource.Primary.Attributes.HTTPSHealthCheck = CreateStructSlice(attributes_map, attributesKey, "https_health_check", 1, NewHealthCheck) 88 | resource.Primary.Attributes.HTTPHealthCheck = CreateStructSlice(attributes_map, attributesKey, "http_health_check", 1, NewHealthCheck) 89 | resource.Primary.Attributes.SslHealthCheck = CreateStructSlice(attributes_map, attributesKey, "ssl_health_check", 1, NewHealthCheck) 90 | resource.Primary.Attributes.TCPHealthCheck = CreateStructSlice(attributes_map, attributesKey, "tcp_health_check", 1, NewHealthCheck) 91 | //beta 92 | if resourceData["provider"] == "provider.google-beta" { 93 | } 94 | return resource 95 | } 96 | -------------------------------------------------------------------------------- /resources/resource_google_compute_http_health_check.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_http_health_check struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | CheckIntervalSec string `json:"check_interval_sec"` 10 | CreationTimestamp string `json:"creation_timestamp"` 11 | Description string `json:"description"` 12 | HealthyThreshold string `json:"healthy_threshold"` 13 | Host string `json:"host"` 14 | ID string `json:"id"` 15 | Name string `json:"name"` 16 | Port string `json:"port"` 17 | Project string `json:"project"` 18 | RequestPath string `json:"request_path"` 19 | SelfLink string `json:"self_link"` 20 | TimeoutSec string `json:"timeout_sec"` 21 | UnhealthyThreshold string `json:"unhealthy_threshold"` 22 | } `json:"attributes"` 23 | Meta struct { 24 | SchemaVersion string `json:"schema_version"` 25 | } `json:"meta"` 26 | Tainted bool `json:"tainted"` 27 | } `json:"primary"` 28 | Deposed []interface{} `json:"deposed"` 29 | Provider string `json:"provider"` 30 | } 31 | 32 | func Newgoogle_compute_http_health_check(resourceData map[string]interface{}, resourceName string) *google_compute_http_health_check { 33 | 34 | resource := new(google_compute_http_health_check) 35 | //attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 36 | //attributesKey := CreateAttributesKey(attributes_map) 37 | MapToStruct(resourceData, resource) 38 | resource.Primary.ID = resourceName 39 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 40 | 41 | //attributes need to transform 42 | 43 | //beta 44 | if resourceData["provider"] == "provider.google-beta" { 45 | } 46 | return resource 47 | } 48 | -------------------------------------------------------------------------------- /resources/resource_google_compute_image.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_image struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | ArchiveSizeBytes string `json:"archive_size_bytes"` 10 | CreationTimestamp string `json:"creation_timestamp"` 11 | Description string `json:"description"` 12 | DiskSizeGb string `json:"disk_size_gb"` 13 | Family string `json:"family"` 14 | ID string `json:"id"` 15 | LabelFingerprint string `json:"label_fingerprint"` 16 | Labels map[string]string `json:"labels"` 17 | Licenses []string `json:"licenses"` 18 | Name string `json:"name"` 19 | Project string `json:"project"` 20 | SelfLink string `json:"self_link"` 21 | SourceDisk string `json:"source_disk"` 22 | } `json:"attributes"` 23 | Meta struct { 24 | SchemaVersion string `json:"schema_version"` 25 | } `json:"meta"` 26 | Tainted bool `json:"tainted"` 27 | } `json:"primary"` 28 | Deposed []interface{} `json:"deposed"` 29 | Provider string `json:"provider"` 30 | } 31 | 32 | func Newgoogle_compute_image(resourceData map[string]interface{}, resourceName string) *google_compute_image { 33 | 34 | resource := new(google_compute_image) 35 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 36 | attributesKey := CreateAttributesKey(attributes_map) 37 | MapToStruct(resourceData, resource) 38 | resource.Primary.ID = resourceName 39 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 40 | 41 | //attributes need to transform 42 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 43 | resource.Primary.Attributes.Licenses = CreateStringSlice(attributes_map, attributesKey, "licenses") 44 | //beta 45 | if resourceData["provider"] == "provider.google-beta" { 46 | } 47 | return resource 48 | } 49 | -------------------------------------------------------------------------------- /resources/resource_google_compute_instance.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_compute_instance struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | AttachedDisk []Params `json:"attached_disk.#"` 14 | BootDisk string `json:"boot_disk.#"` 15 | BootDiskAutoDelete string `json:"boot_disk.auto_delete"` 16 | BootDiskDeviceName string `json:"boot_disk.device_name"` 17 | BootDiskDiskEncryptionKeyRaw string `json:"boot_disk.disk_encryption_key_raw"` 18 | BootDiskDiskEncryptionKeySha256 string `json:"boot_disk.disk_encryption_key_sha256"` 19 | BootDiskInitializeParamsImage string `json:"boot_disk.initialize_params.1.image"` 20 | BootDiskInitializeParamsSize string `json:"boot_disk.initialize_params.1.size"` 21 | BootDiskInitializeParamsType string `json:"boot_disk.initialize_params.1.type"` 22 | BootDiskSource string `json:"boot_disk.source"` 23 | CanIPForward string `json:"can_ip_forward"` 24 | CPUPlatform string `json:"cpu_platform"` 25 | DeletionProtection string `json:"deletion_protection"` 26 | GuestAccelerator []Params `json:"guest_accelerator.#"` 27 | Hostname string `json:"hostname"` 28 | ID string `json:"id"` 29 | InstanceID string `json:"instance_id"` 30 | LabelFingerprint string `json:"label_fingerprint"` 31 | Labels map[string]string `json:"labels"` 32 | MachineType string `json:"machine_type"` 33 | Metadata map[string]string `json:"metadata"` 34 | MetadataFingerprint string `json:"metadata_fingerprint"` 35 | MetadataStartupScript string `json:"metadata_startup_script"` 36 | MinCPUPlatform string `json:"min_cpu_platform"` 37 | Name string `json:"name"` 38 | NetworkInterface []Params `json:"network_interface"` 39 | Project string `json:"project"` 40 | Scheduling []Params `json:"scheduling"` 41 | ScratchDisk []Params `json:"scratch_disk"` 42 | SelfLink string `json:"self_link"` 43 | ServiceAccount []Params `json:"service_account"` 44 | Tags []string `json:"tags"` 45 | TagsFingerprint string `json:"tags_fingerprint"` 46 | Zone string `json:"zone"` 47 | } `json:"attributes"` 48 | Meta struct { 49 | SchemaVersion string `json:"schema_version"` 50 | } `json:"meta"` 51 | Tainted bool `json:"tainted"` 52 | } `json:"primary"` 53 | Deposed []interface{} `json:"deposed"` 54 | Provider string `json:"provider"` 55 | } 56 | 57 | type AttachedDisk struct { 58 | Number string 59 | DeviceName string `json:"device_name"` 60 | EncryptionKeyRaw string `json:"disk_encryption_key_raw"` 61 | EncryptionKeySha256 string `json:"disk_encryption_key_sha256"` 62 | Mode string `json:"mode"` 63 | Source string `json:"source"` 64 | } 65 | 66 | func (d *AttachedDisk) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 67 | if strings.Contains(key, "device_name") { 68 | d.DeviceName = value 69 | } else if strings.Contains(key, "disk_encryption_key_raw") { 70 | d.EncryptionKeyRaw = value 71 | } else if strings.Contains(key, "disk_encryption_key_sha256") { 72 | d.EncryptionKeySha256 = value 73 | } else if strings.Contains(key, "mode") { 74 | d.Mode = value 75 | } else if strings.Contains(key, "source") { 76 | d.Source = value 77 | } 78 | } 79 | 80 | func (d *AttachedDisk) SetNumber(num string) { 81 | d.Number = num 82 | } 83 | 84 | func (d *AttachedDisk) GetNumber() string { 85 | return d.Number 86 | } 87 | 88 | func NewAttachedDisk(num string) Params { 89 | var s Params = new(AttachedDisk) 90 | s.SetNumber(num) 91 | return s 92 | } 93 | 94 | type GuestAccelerator struct { 95 | Number string 96 | Type string `json:"type"` 97 | Count string `json:"count"` 98 | } 99 | 100 | func (d *GuestAccelerator) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 101 | if strings.Contains(key, "type") { 102 | d.Type = value 103 | } else if strings.Contains(key, "count") { 104 | d.Count = value 105 | } 106 | } 107 | 108 | func (d *GuestAccelerator) SetNumber(num string) { 109 | d.Number = num 110 | } 111 | 112 | func (d *GuestAccelerator) GetNumber() string { 113 | return d.Number 114 | } 115 | 116 | func NewGuestAccelerator(num string) Params { 117 | var s Params = new(GuestAccelerator) 118 | s.SetNumber(num) 119 | return s 120 | } 121 | 122 | type ScratchDisk struct { 123 | Number string 124 | Interface string `json:"interface"` 125 | } 126 | 127 | func (d *ScratchDisk) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 128 | if strings.Contains(key, "interface") { 129 | d.Interface = value 130 | } 131 | } 132 | 133 | func (d *ScratchDisk) SetNumber(num string) { 134 | d.Number = num 135 | } 136 | 137 | func (d *ScratchDisk) GetNumber() string { 138 | return d.Number 139 | } 140 | 141 | func NewScratchDisk(num string) Params { 142 | var s Params = new(ScratchDisk) 143 | s.SetNumber(num) 144 | return s 145 | } 146 | 147 | func Newgoogle_compute_instance(resourceData map[string]interface{}, resourceName string) *google_compute_instance { 148 | 149 | resource := new(google_compute_instance) 150 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 151 | attributesKey := CreateAttributesKey(attributes_map) 152 | MapToStruct(resourceData, resource) 153 | resource.Primary.ID = resourceName 154 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 155 | 156 | //attributes need to transform 157 | resource.Primary.Attributes.AttachedDisk = CreateStructSlice(attributes_map, attributesKey, "attached_disk", 1, NewAttachedDisk) 158 | //BootDiskは1つという前提 159 | resource.Primary.Attributes.BootDiskAutoDelete = attributes_map["boot_disk.0.auto_delete"].(string) 160 | resource.Primary.Attributes.BootDiskDeviceName = attributes_map["boot_disk.0.device_name"].(string) 161 | resource.Primary.Attributes.BootDiskDiskEncryptionKeyRaw = attributes_map["boot_disk.0.disk_encryption_key_raw"].(string) 162 | resource.Primary.Attributes.BootDiskDiskEncryptionKeySha256 = attributes_map["boot_disk.0.disk_encryption_key_sha256"].(string) 163 | resource.Primary.Attributes.BootDiskInitializeParamsImage = attributes_map["boot_disk.0.initialize_params.0.image"].(string) 164 | resource.Primary.Attributes.BootDiskInitializeParamsSize = attributes_map["boot_disk.0.initialize_params.0.size"].(string) 165 | resource.Primary.Attributes.BootDiskInitializeParamsType = attributes_map["boot_disk.0.initialize_params.0.type"].(string) 166 | resource.Primary.Attributes.BootDiskSource = attributes_map["boot_disk.0.source"].(string) 167 | resource.Primary.Attributes.GuestAccelerator = CreateStructSlice(attributes_map, attributesKey, "guest_accelerator", 1, NewGuestAccelerator) 168 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 169 | resource.Primary.Attributes.Metadata = CreateMap(attributes_map, "metadata.") 170 | resource.Primary.Attributes.NetworkInterface = CreateStructSlice(attributes_map, attributesKey, "network_interface", 1, NewNetworkInterface) 171 | resource.Primary.Attributes.Scheduling = CreateStructSlice(attributes_map, attributesKey, "scheduling", 1, NewScheduling) 172 | resource.Primary.Attributes.ScratchDisk = CreateStructSlice(attributes_map, attributesKey, "scratch_disk", 1, NewScratchDisk) 173 | resource.Primary.Attributes.ServiceAccount = CreateStructSlice(attributes_map, attributesKey, "service_account", 1, NewServiceAccount) 174 | resource.Primary.Attributes.Tags = CreateStringSlice(attributes_map, attributesKey, "tags") 175 | 176 | //beta 177 | if resourceData["provider"] == "provider.google-beta" { 178 | } 179 | return resource 180 | } 181 | -------------------------------------------------------------------------------- /resources/resource_google_compute_instance_group.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import "strings" 4 | 5 | type google_compute_instance_group struct { 6 | Type string `json:"type"` 7 | DependsOn []string `json:"depends_on"` 8 | Primary struct { 9 | ID string `json:"id"` 10 | Attributes struct { 11 | Description string `json:"description"` 12 | ID string `json:"id"` 13 | Instances []string `json:"instances."` 14 | Name string `json:"name"` 15 | NamedPort []Params `json:"named_port.#"` 16 | Network string `json:"network"` 17 | Project string `json:"project"` 18 | SelfLink string `json:"self_link"` 19 | Size string `json:"size"` 20 | Zone string `json:"zone"` 21 | } `json:"attributes"` 22 | Meta struct { 23 | SchemaVersion string `json:"schema_version"` 24 | } `json:"meta"` 25 | Tainted bool `json:"tainted"` 26 | } `json:"primary"` 27 | Deposed []interface{} `json:"deposed"` 28 | Provider string `json:"provider"` 29 | } 30 | 31 | type NamedPort struct { 32 | Number string 33 | Name string 34 | Port string 35 | } 36 | 37 | func (d *NamedPort) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 38 | if strings.Contains(key, ".name") { 39 | d.Name = value 40 | } else if strings.Contains(key, ".port") { 41 | d.Port = value 42 | } 43 | } 44 | 45 | func (d *NamedPort) SetNumber(num string) { 46 | d.Number = num 47 | } 48 | 49 | func (d *NamedPort) GetNumber() string { 50 | return d.Number 51 | } 52 | 53 | func NewNamedPort(num string) Params { 54 | var s Params = new(NamedPort) 55 | s.SetNumber(num) 56 | return s 57 | } 58 | 59 | func Newgoogle_compute_instance_group(resourceData map[string]interface{}, resourceName string) *google_compute_instance_group { 60 | 61 | resource := new(google_compute_instance_group) 62 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 63 | attributesKey := CreateAttributesKey(attributes_map) 64 | MapToStruct(resourceData, resource) 65 | resource.Primary.ID = resourceName 66 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 67 | 68 | //attributes need to transform 69 | resource.Primary.Attributes.NamedPort = CreateStructSlice(attributes_map, attributesKey, "named_port", 1, NewNamedPort) 70 | 71 | //beta 72 | if resourceData["provider"] == "provider.google-beta" { 73 | } 74 | return resource 75 | } 76 | -------------------------------------------------------------------------------- /resources/resource_google_compute_instance_group_manager.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_instance_group_manager struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | BaseInstanceName string `json:"base_instance_name"` 10 | Description string `json:"description"` 11 | Fingerprint string `json:"fingerprint"` 12 | ID string `json:"id"` 13 | InstanceGroup string `json:"instance_group"` 14 | InstanceTemplate string `json:"instance_template"` 15 | Name string `json:"name"` 16 | NamedPort []Params `json:"named_port.#"` 17 | Project string `json:"project"` 18 | RollingUpdatePolicy string `json:"rolling_update_policy.#"` 19 | SelfLink string `json:"self_link"` 20 | TargetPools []string `json:"target_pools.#"` 21 | TargetSize string `json:"target_size"` 22 | UpdateStrategy string `json:"update_strategy"` 23 | Version string `json:"version.#"` 24 | WaitForInstances string `json:"wait_for_instances"` 25 | Zone string `json:"zone"` 26 | } `json:"attributes"` 27 | Meta struct { 28 | SchemaVersion string `json:"schema_version"` 29 | } `json:"meta"` 30 | Tainted bool `json:"tainted"` 31 | } `json:"primary"` 32 | Deposed []interface{} `json:"deposed"` 33 | Provider string `json:"provider"` 34 | } 35 | 36 | func Newgoogle_compute_instance_group_manager(resourceData map[string]interface{}, resourceName string) *google_compute_instance_group_manager { 37 | 38 | resource := new(google_compute_instance_group_manager) 39 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 40 | attributesKey := CreateAttributesKey(attributes_map) 41 | MapToStruct(resourceData, resource) 42 | resource.Primary.ID = resourceName 43 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 44 | 45 | //attributes need to transform 46 | resource.Primary.Attributes.TargetPools = CreateStringSlice(attributes_map, attributesKey, "target_pools") 47 | resource.Primary.Attributes.NamedPort = CreateStructSlice(attributes_map, attributesKey, "named_port", 1, NewNamedPort) 48 | 49 | //beta 50 | if resourceData["provider"] == "provider.google-beta" { 51 | //rolling update 52 | //version 53 | } 54 | return resource 55 | } 56 | -------------------------------------------------------------------------------- /resources/resource_google_compute_instance_template.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_compute_instance_template struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | CanIPForward string `json:"can_ip_forward"` 14 | Description string `json:"description"` 15 | Disk []Params `json:"disk.#"` 16 | ID string `json:"id"` 17 | InstanceDescription string `json:"instance_description"` 18 | Labels map[string]string `json:"labels"` 19 | MachineType string `json:"machine_type"` 20 | Metadata map[string]string `json:"metadata"` 21 | MetadataFingerprint string `json:"metadata_fingerprint"` 22 | MinCPUPlatform string `json:"min_cpu_platform"` 23 | Name string `json:"name"` 24 | NetworkInterface []Params `json:"network_interface"` 25 | Project string `json:"project"` 26 | Scheduling []Params `json:"scheduling"` 27 | SelfLink string `json:"self_link"` 28 | ServiceAccount []Params `json:"service_account"` 29 | Tags []string `json:"tags"` 30 | TagsFingerprint string `json:"tags_fingerprint"` 31 | } `json:"attributes"` 32 | Meta struct { 33 | SchemaVersion string `json:"schema_version"` 34 | } `json:"meta"` 35 | Tainted bool `json:"tainted"` 36 | } `json:"primary"` 37 | Deposed []interface{} `json:"deposed"` 38 | Provider string `json:"provider"` 39 | } 40 | 41 | type NetworkInterface struct { 42 | //paramsの2重構造は対応できないから、配列で持って要素で関連づけ 43 | Number string 44 | AccessConfigAssignedNatIP []string `json:"assigned_nat_ip"` 45 | AccessConfigNatIP []string `json:"nat_ip"` 46 | AccessConfigNetworkTier []string `json:"network_tier"` 47 | Address string `json:"address"` 48 | AliasIPRangeIPCidrRange []string `json:"alias_ip_range"` 49 | AliasIPRangeIPSubnetworkRangeName []string `json:"alias_ip_range.#"` 50 | Network string `json:"network"` 51 | NetworkIP string `json:"network_ip"` 52 | Subnetwork string `json:"subnetwork"` 53 | SubnetworkProject string `json:"subnetwork_project"` 54 | } 55 | 56 | func (d *NetworkInterface) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 57 | if strings.Contains(key, "access_config") && strings.Contains(key, "assigned_nat_ip") { 58 | d.AccessConfigAssignedNatIP = append(d.AccessConfigAssignedNatIP, value) 59 | } else if strings.Contains(key, "access_config") && strings.Contains(key, "nat_ip") && !strings.Contains(key, "assigned_nat_ip") { 60 | d.AccessConfigNatIP = append(d.AccessConfigNatIP, value) 61 | } else if strings.Contains(key, "access_config") && strings.Contains(key, "network_tier") { 62 | d.AccessConfigNetworkTier = append(d.AccessConfigNetworkTier, value) 63 | } else if strings.Contains(key, "address") { 64 | d.Address = value 65 | } else if strings.Contains(key, "alias_ip_range") && strings.Contains(key, "ip_cidr_range") { 66 | d.AliasIPRangeIPCidrRange = append(d.AliasIPRangeIPCidrRange, value) 67 | } else if strings.Contains(key, "alias_ip_range") && !strings.Contains(key, "subnetwork_range_name") { 68 | d.AliasIPRangeIPSubnetworkRangeName = append(d.AliasIPRangeIPSubnetworkRangeName, value) 69 | } else if strings.Contains(key, "network_ip") { 70 | d.NetworkIP = value 71 | } else if strings.Contains(key, "subnetwork") && !strings.Contains(key, "subnetwork_project") { 72 | d.Subnetwork = value 73 | } else if strings.Contains(key, "subnetwork_project") { 74 | d.SubnetworkProject = value 75 | } else if strings.Contains(key, "network") && !strings.Contains(key, "subnetwork") && !strings.Contains(key, "network_tier") && !strings.Contains(key, "network_ip") { 76 | d.Network = value 77 | } 78 | } 79 | 80 | func (d *NetworkInterface) SetNumber(num string) { 81 | d.Number = num 82 | } 83 | 84 | func (d *NetworkInterface) GetNumber() string { 85 | return d.Number 86 | } 87 | 88 | func NewNetworkInterface(num string) Params { 89 | var s Params = new(NetworkInterface) 90 | s.SetNumber(num) 91 | return s 92 | } 93 | 94 | type NetworkInterfaceAliasIPRange struct { 95 | Number string 96 | } 97 | 98 | type Disk struct { 99 | Number string 100 | DiskAutoDelete string `json:"disk.auto_delete"` 101 | DiskBoot string `json:"disk.boot"` 102 | DiskDeviceName string `json:"disk.device_name"` 103 | DiskDiskEncryptionKey []*EncryptionKey `json:"disk.disk_encryption_key.#"` 104 | DiskDiskName string `json:"disk.disk_name"` 105 | DiskDiskSizeGb string `json:"disk.disk_size_gb"` 106 | DiskDiskType string `json:"disk.disk_type"` 107 | DiskInterface string `json:"disk.interface"` 108 | DiskMode string `json:"disk.mode"` 109 | DiskSource string `json:"disk.source"` 110 | DiskSourceImage string `json:"disk.source_image"` 111 | DiskType string `json:"disk.type"` 112 | } 113 | 114 | func (d *Disk) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 115 | if strings.Contains(key, "auto_delete") { 116 | d.DiskAutoDelete = value 117 | } else if strings.Contains(key, "boot") { 118 | d.DiskBoot = value 119 | } else if strings.Contains(key, "device_name") { 120 | d.DiskDeviceName = value 121 | } else if strings.Contains(key, "disk_encryption_key") && !strings.Contains(key, "#") { 122 | d.DiskDiskEncryptionKey = append(d.DiskDiskEncryptionKey, NewDiskEncryptionKeyforDisk(value)) 123 | } else if strings.Contains(key, "disk_name") { 124 | d.DiskDiskName = value 125 | } else if strings.Contains(key, "disk_size_gb") { 126 | d.DiskDiskSizeGb = value 127 | } else if strings.Contains(key, "disk_type") { 128 | d.DiskDiskType = value 129 | } else if strings.Contains(key, "interface") { 130 | d.DiskInterface = value 131 | } else if strings.Contains(key, "mode") { 132 | d.DiskMode = value 133 | } else if strings.Contains(key, "source_image") { 134 | d.DiskSourceImage = value 135 | } else if strings.Contains(key, "source") { 136 | d.DiskSource = value 137 | } else if strings.Contains(key, "type") { 138 | d.DiskType = value 139 | } 140 | } 141 | 142 | func (d *Disk) SetNumber(num string) { 143 | d.Number = num 144 | } 145 | 146 | func (d *Disk) GetNumber() string { 147 | return d.Number 148 | } 149 | 150 | func NewDisk(num string) Params { 151 | var s Params = new(Disk) 152 | s.SetNumber(num) 153 | return s 154 | } 155 | 156 | //bimyou 157 | func NewDiskEncryptionKeyforDisk(v string) *EncryptionKey { 158 | s := new(EncryptionKey) 159 | s.KmsKeySelfLink = v 160 | return s 161 | } 162 | 163 | type Scheduling struct { 164 | Number string 165 | AutomaticRestart string `json:"automatic_restart"` 166 | OnHostMaintenance string `json:"on_host_maintenance"` 167 | Preemptible string `json:"preemptible"` 168 | } 169 | 170 | func (d *Scheduling) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 171 | if strings.Contains(key, "automatic_restart") { 172 | d.AutomaticRestart = value 173 | } else if strings.Contains(key, "on_host_maintenance") { 174 | d.OnHostMaintenance = value 175 | } else if strings.Contains(key, "preemptible") { 176 | d.Preemptible = value 177 | } 178 | } 179 | 180 | func (d *Scheduling) SetNumber(num string) { 181 | d.Number = num 182 | } 183 | 184 | func (d *Scheduling) GetNumber() string { 185 | return d.Number 186 | } 187 | 188 | func NewScheduling(num string) Params { 189 | var s Params = new(Scheduling) 190 | s.SetNumber(num) 191 | return s 192 | } 193 | 194 | type ServiceAccount struct { 195 | Number string 196 | Email string `json:"service_account.email"` 197 | Scopes []string `json:"service_account.scopes"` 198 | } 199 | 200 | func (d *ServiceAccount) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 201 | if strings.Contains(key, "email") { 202 | d.Email = value 203 | } else if strings.Contains(key, "scopes") { 204 | d.Scopes = append(d.Scopes, value) 205 | } 206 | } 207 | 208 | func (d *ServiceAccount) SetNumber(num string) { 209 | d.Number = num 210 | } 211 | 212 | func (d *ServiceAccount) GetNumber() string { 213 | return d.Number 214 | } 215 | 216 | func NewServiceAccount(num string) Params { 217 | var s Params = new(ServiceAccount) 218 | s.SetNumber(num) 219 | return s 220 | } 221 | 222 | func Newgoogle_compute_instance_template(resourceData map[string]interface{}, resourceName string) *google_compute_instance_template { 223 | 224 | resource := new(google_compute_instance_template) 225 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 226 | attributesKey := CreateAttributesKey(attributes_map) 227 | MapToStruct(resourceData, resource) 228 | resource.Primary.ID = resourceName 229 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 230 | 231 | //attributes need to transform 232 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 233 | resource.Primary.Attributes.Metadata = CreateMap(attributes_map, "metadata.") 234 | resource.Primary.Attributes.NetworkInterface = CreateStructSlice(attributes_map, attributesKey, "network_interface", 1, NewNetworkInterface) 235 | resource.Primary.Attributes.Scheduling = CreateStructSlice(attributes_map, attributesKey, "scheduling", 1, NewScheduling) 236 | resource.Primary.Attributes.ServiceAccount = CreateStructSlice(attributes_map, attributesKey, "service_account", 1, NewServiceAccount) 237 | resource.Primary.Attributes.Tags = CreateStringSlice(attributes_map, attributesKey, "tags") 238 | resource.Primary.Attributes.Disk = CreateStructSlice(attributes_map, attributesKey, "disk", 1, NewDisk) 239 | 240 | //beta 241 | if resourceData["provider"] == "provider.google-beta" { 242 | } 243 | return resource 244 | } 245 | -------------------------------------------------------------------------------- /resources/resource_google_compute_network.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_network struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | AutoCreateSubnetworks string `json:"auto_create_subnetworks"` 10 | DeleteDefaultRoutesOnCreate string `json:"delete_default_routes_on_create"` 11 | Description string `json:"description"` 12 | GatewayIpv4 string `json:"gateway_ipv4"` 13 | ID string `json:"id"` 14 | Ipv4Range string `json:"ipv4_range"` 15 | Name string `json:"name"` 16 | Project string `json:"project"` 17 | RoutingMode string `json:"routing_mode"` 18 | SelfLink string `json:"self_link"` 19 | } `json:"attributes"` 20 | Meta struct { 21 | SchemaVersion string `json:"schema_version"` 22 | } `json:"meta"` 23 | Tainted bool `json:"tainted"` 24 | } `json:"primary"` 25 | Deposed []interface{} `json:"deposed"` 26 | Provider string `json:"provider"` 27 | } 28 | 29 | func Newgoogle_compute_network(resourceData map[string]interface{}, resourceName string) *google_compute_network { 30 | 31 | resource := new(google_compute_network) 32 | //attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 33 | //attributesKey := CreateAttributesKey(attributes_map) 34 | MapToStruct(resourceData, resource) 35 | resource.Primary.ID = resourceName 36 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 37 | 38 | //attributes need to transform 39 | 40 | //beta 41 | if resourceData["provider"] == "provider.google-beta" { 42 | } 43 | return resource 44 | } 45 | -------------------------------------------------------------------------------- /resources/resource_google_compute_route.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_route struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | Description string `json:"description"` 10 | DestRange string `json:"dest_range"` 11 | ID string `json:"id"` 12 | Name string `json:"name"` 13 | Network string `json:"network"` 14 | NextHopGateway string `json:"next_hop_gateway"` 15 | NextHopInstance string `json:"next_hop_instance"` 16 | NextHopIP string `json:"next_hop_ip"` 17 | NextHopNetwork string `json:"next_hop_network"` 18 | NextHopVpnTunnel string `json:"next_hop_vpn_tunnel"` 19 | Priority string `json:"priority"` 20 | Project string `json:"project"` 21 | SelfLink string `json:"self_link"` 22 | Tags []string `json:"tags"` 23 | EnableLogging string `json:"enable_logging"` 24 | } `json:"attributes"` 25 | Meta struct { 26 | SchemaVersion string `json:"schema_version"` 27 | } `json:"meta"` 28 | Tainted bool `json:"tainted"` 29 | } `json:"primary"` 30 | Deposed []interface{} `json:"deposed"` 31 | Provider string `json:"provider"` 32 | } 33 | 34 | func Newgoogle_compute_route(resourceData map[string]interface{}, resourceName string) *google_compute_route { 35 | 36 | resource := new(google_compute_route) 37 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 38 | attributesKey := CreateAttributesKey(attributes_map) 39 | MapToStruct(resourceData, resource) 40 | resource.Primary.ID = resourceName 41 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 42 | 43 | //attributes need to transform 44 | resource.Primary.Attributes.Tags = CreateStringSlice(attributes_map, attributesKey, "tags") 45 | //beta 46 | if resourceData["provider"] == "provider.google-beta" { 47 | } 48 | return resource 49 | } 50 | -------------------------------------------------------------------------------- /resources/resource_google_compute_snapshot.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_snapshot struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | CreationTimestamp string `json:"creation_timestamp"` 10 | Description string `json:"description"` 11 | DiskSizeGb string `json:"disk_size_gb"` 12 | ID string `json:"id"` 13 | LabelFingerprint string `json:"label_fingerprint"` 14 | Labels map[string]string `json:"labels"` 15 | Name string `json:"name"` 16 | Project string `json:"project"` 17 | SelfLink string `json:"self_link"` 18 | SnapshotEncryptionKey []Params `json:"snapshot_encryption_key"` 19 | SnapshotID string `json:"snapshot_id"` 20 | SourceDisk string `json:"source_disk"` 21 | SourceDiskLink string `json:"source_disk_link"` 22 | StorageBytes string `json:"storage_bytes"` 23 | } `json:"attributes"` 24 | Meta struct { 25 | SchemaVersion string `json:"schema_version"` 26 | } `json:"meta"` 27 | Tainted bool `json:"tainted"` 28 | } `json:"primary"` 29 | Deposed []interface{} `json:"deposed"` 30 | Provider string `json:"provider"` 31 | } 32 | 33 | type SnapshotEncryptionKey struct { 34 | Number string 35 | RawKey string 36 | } 37 | 38 | func (s *SnapshotEncryptionKey) SetRawKey(RawKey string) { 39 | s.RawKey = RawKey 40 | } 41 | func NewSnapshotEncryptionKey(num string) *SnapshotEncryptionKey { 42 | s := new(SnapshotEncryptionKey) 43 | s.Number = num 44 | return s 45 | } 46 | 47 | func Newgoogle_compute_snapshot(resourceData map[string]interface{}, resourceName string) *google_compute_snapshot { 48 | 49 | resource := new(google_compute_snapshot) 50 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 51 | attributesKey := CreateAttributesKey(attributes_map) 52 | MapToStruct(resourceData, resource) 53 | resource.Primary.ID = resourceName 54 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 55 | 56 | //attributes need to transform 57 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 58 | resource.Primary.Attributes.SnapshotEncryptionKey = CreateStructSlice(attributes_map, attributesKey, "snapshot_encryption_key", 1, NewEncryptionKey) 59 | 60 | //beta 61 | if resourceData["provider"] == "provider.google-beta" { 62 | } 63 | return resource 64 | } 65 | -------------------------------------------------------------------------------- /resources/resource_google_compute_ssl_certificate.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_ssl_certificate struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | Certificate string `json:"certificate"` 10 | CertificateID string `json:"certificate_id"` 11 | CreationTimestamp string `json:"creation_timestamp"` 12 | Description string `json:"description"` 13 | ID string `json:"id"` 14 | Name string `json:"name"` 15 | Project string `json:"project"` 16 | SelfLink string `json:"self_link"` 17 | } `json:"attributes"` 18 | Meta struct { 19 | SchemaVersion string `json:"schema_version"` 20 | } `json:"meta"` 21 | Tainted bool `json:"tainted"` 22 | } `json:"primary"` 23 | Deposed []interface{} `json:"deposed"` 24 | Provider string `json:"provider"` 25 | } 26 | 27 | func Newgoogle_compute_ssl_certificate(resourceData map[string]interface{}, resourceName string) *google_compute_ssl_certificate { 28 | 29 | resource := new(google_compute_ssl_certificate) 30 | //attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 31 | //attributesKey := CreateAttributesKey(attributes_map) 32 | //Struct 33 | MapToStruct(resourceData, resource) 34 | resource.Primary.ID = resourceName 35 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 36 | 37 | //attributes need to transform 38 | 39 | //beta 40 | if resourceData["provider"] == "provider.google-beta" { 41 | } 42 | return resource 43 | } 44 | -------------------------------------------------------------------------------- /resources/resource_google_compute_subnetwork.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_compute_subnetwork struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | CreationTimestamp string `json:"creation_timestamp"` 14 | Description string `json:"description"` 15 | EnableFlowLogs string `json:"enable_flow_logs"` 16 | Fingerprint string `json:"fingerprint"` 17 | GatewayAddress string `json:"gateway_address"` 18 | ID string `json:"id"` 19 | IPCidrRange string `json:"ip_cidr_range"` 20 | Name string `json:"name"` 21 | Network string `json:"network"` 22 | PrivateIPGoogleAccess string `json:"private_ip_google_access"` 23 | Project string `json:"project"` 24 | Region string `json:"region"` 25 | SecondaryIPRange []Params `json:"secondary_ip_range"` 26 | SelfLink string `json:"self_link"` 27 | } `json:"attributes"` 28 | Meta struct { 29 | SchemaVersion string `json:"schema_version"` 30 | } `json:"meta"` 31 | Tainted bool `json:"tainted"` 32 | } `json:"primary"` 33 | Deposed []interface{} `json:"deposed"` 34 | Provider string `json:"provider"` 35 | } 36 | 37 | type SecondaryIPRange struct { 38 | Number string 39 | Ip_cidr_range string 40 | Range_name string 41 | } 42 | 43 | func (d *SecondaryIPRange) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 44 | if strings.Contains(key, "ip_cidr_range") { 45 | d.Ip_cidr_range = value 46 | } else if strings.Contains(key, "range_name") { 47 | d.Range_name = value 48 | } 49 | } 50 | 51 | func (d *SecondaryIPRange) SetNumber(num string) { 52 | d.Number = num 53 | } 54 | 55 | func (d *SecondaryIPRange) GetNumber() string { 56 | return d.Number 57 | } 58 | 59 | func NewSecondaryIPRange(num string) Params { 60 | var s Params = new(SecondaryIPRange) 61 | s.SetNumber(num) 62 | return s 63 | } 64 | 65 | func Newgoogle_compute_subnetwork(resourceData map[string]interface{}, resourceName string) *google_compute_subnetwork { 66 | 67 | resource := new(google_compute_subnetwork) 68 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 69 | attributesKey := CreateAttributesKey(attributes_map) 70 | MapToStruct(resourceData, resource) 71 | resource.Primary.ID = resourceName 72 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 73 | 74 | //attributes need to transform 75 | resource.Primary.Attributes.SecondaryIPRange = CreateStructSlice(attributes_map, attributesKey, "secondary_ip_range", 1, NewSecondaryIPRange) 76 | //beta 77 | if resourceData["provider"] == "provider.google-beta" { 78 | } 79 | return resource 80 | } 81 | -------------------------------------------------------------------------------- /resources/resource_google_compute_target_http_proxy.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_target_http_proxy struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | CreationTimestamp string `json:"creation_timestamp"` 10 | Description string `json:"description"` 11 | ID string `json:"id"` 12 | Name string `json:"name"` 13 | Project string `json:"project"` 14 | ProxyID string `json:"proxy_id"` 15 | SelfLink string `json:"self_link"` 16 | URLMap string `json:"url_map"` 17 | } `json:"attributes"` 18 | Meta struct { 19 | SchemaVersion string `json:"schema_version"` 20 | } `json:"meta"` 21 | Tainted bool `json:"tainted"` 22 | } `json:"primary"` 23 | Deposed []interface{} `json:"deposed"` 24 | Provider string `json:"provider"` 25 | } 26 | 27 | func Newgoogle_compute_target_http_proxy(resourceData map[string]interface{}, resourceName string) *google_compute_target_http_proxy { 28 | 29 | resource := new(google_compute_target_http_proxy) 30 | //attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 31 | //attributesKey := CreateAttributesKey(attributes_map) 32 | //Struct 33 | MapToStruct(resourceData, resource) 34 | resource.Primary.ID = resourceName 35 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 36 | 37 | //attributes need to transform 38 | 39 | //beta 40 | if resourceData["provider"] == "provider.google-beta" { 41 | } 42 | return resource 43 | } 44 | -------------------------------------------------------------------------------- /resources/resource_google_compute_target_https_proxy.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_target_https_proxy struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | CreationTimestamp string `json:"creation_timestamp"` 10 | Description string `json:"description"` 11 | ID string `json:"id"` 12 | Name string `json:"name"` 13 | Project string `json:"project"` 14 | ProxyID string `json:"proxy_id"` 15 | QuicOverride string `json:"quic_override"` 16 | SelfLink string `json:"self_link"` 17 | SslCertificates []string `json:"ssl_certificates"` 18 | SslPolicy string `json:"ssl_policy"` 19 | URLMap string `json:"url_map"` 20 | } `json:"attributes"` 21 | Meta struct { 22 | SchemaVersion string `json:"schema_version"` 23 | } `json:"meta"` 24 | Tainted bool `json:"tainted"` 25 | } `json:"primary"` 26 | Deposed []interface{} `json:"deposed"` 27 | Provider string `json:"provider"` 28 | } 29 | 30 | func Newgoogle_compute_target_https_proxy(resourceData map[string]interface{}, resourceName string) *google_compute_target_https_proxy { 31 | 32 | resource := new(google_compute_target_https_proxy) 33 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 34 | attributesKey := CreateAttributesKey(attributes_map) 35 | //Struct 36 | MapToStruct(resourceData, resource) 37 | resource.Primary.ID = resourceName 38 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 39 | 40 | //attributes need to transform 41 | resource.Primary.Attributes.SslCertificates = CreateStringSlice(attributes_map, attributesKey, "ssl_certificates") 42 | 43 | //beta 44 | if resourceData["provider"] == "provider.google-beta" { 45 | } 46 | return resource 47 | } 48 | -------------------------------------------------------------------------------- /resources/resource_google_compute_target_pool.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_compute_target_pool struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | BackupPool string `json:"backup_pool"` 10 | Description string `json:"description"` 11 | FailoverRatio string `json:"failover_ratio"` 12 | HealthChecks []string `json:"health_checks"` 13 | ID string `json:"id"` 14 | Instances []string `json:"instances"` 15 | Name string `json:"name"` 16 | Project string `json:"project"` 17 | Region string `json:"region"` 18 | SelfLink string `json:"self_link"` 19 | SessionAffinity string `json:"session_affinity"` 20 | } `json:"attributes"` 21 | Meta struct { 22 | SchemaVersion string `json:"schema_version"` 23 | } `json:"meta"` 24 | Tainted bool `json:"tainted"` 25 | } `json:"primary"` 26 | Deposed []interface{} `json:"deposed"` 27 | Provider string `json:"provider"` 28 | } 29 | 30 | func Newgoogle_compute_target_pool(resourceData map[string]interface{}, resourceName string) *google_compute_target_pool { 31 | 32 | resource := new(google_compute_target_pool) 33 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 34 | attributesKey := CreateAttributesKey(attributes_map) 35 | MapToStruct(resourceData, resource) 36 | resource.Primary.ID = resourceName 37 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 38 | resource.Primary.Attributes.HealthChecks = CreateStringSlice(attributes_map, attributesKey, "health_checks") 39 | resource.Primary.Attributes.Instances = CreateStringSlice(attributes_map, attributesKey, "instances") 40 | //attributes need to transform 41 | 42 | //beta 43 | if resourceData["provider"] == "provider.google-beta" { 44 | } 45 | return resource 46 | } 47 | -------------------------------------------------------------------------------- /resources/resource_google_compute_url_map.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_compute_url_map struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | CreationTimestamp string `json:"creation_timestamp"` 14 | DefaultService string `json:"default_service"` 15 | Description string `json:"description"` 16 | Fingerprint string `json:"fingerprint"` 17 | HostRule []Params `json:"host_rule"` 18 | ID string `json:"id"` 19 | MapID string `json:"map_id"` 20 | Name string `json:"name"` 21 | PathMatcher []Params `json:"path_matcher"` 22 | Project string `json:"project"` 23 | SelfLink string `json:"self_link"` 24 | Test []Params `json:"test"` 25 | } `json:"attributes"` 26 | Meta struct { 27 | SchemaVersion string `json:"schema_version"` 28 | } `json:"meta"` 29 | Tainted bool `json:"tainted"` 30 | } `json:"primary"` 31 | Deposed []interface{} `json:"deposed"` 32 | Provider string `json:"provider"` 33 | } 34 | 35 | type PathMatcher struct { 36 | Number string 37 | DefaultService string `json:"default_service"` 38 | Description string `json:"description"` 39 | Name string `json:"name"` 40 | PathRule []Params 41 | } 42 | 43 | func (d *PathMatcher) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 44 | if strings.Contains(key, "default_service") { 45 | d.DefaultService = value 46 | } else if strings.Contains(key, "path_rule") && strings.Contains(key, "service") { 47 | //path_matcher.#.path_ruleまでを取得 48 | Number := CreateNumberFromKey(key, 2) 49 | d.PathRule = CreateStructSlice(attributes_map, attributesKey, Number, 3, NewPathRule) 50 | 51 | } else if strings.Contains(key, "description") { 52 | d.Description = value 53 | } else if strings.Contains(key, "name") { 54 | d.Name = value 55 | } 56 | } 57 | 58 | func (d *PathMatcher) SetNumber(num string) { 59 | d.Number = num 60 | } 61 | 62 | func (d *PathMatcher) GetNumber() string { 63 | return d.Number 64 | } 65 | 66 | func NewPathMatcher(num string) Params { 67 | var s Params = new(PathMatcher) 68 | s.SetNumber(num) 69 | return s 70 | } 71 | 72 | type PathRule struct { 73 | Number string 74 | Paths []string 75 | Service string `json:".path_rule.service"` 76 | } 77 | 78 | func (d *PathRule) SetNumber(num string) { 79 | d.Number = num 80 | } 81 | 82 | func (d *PathRule) GetNumber() string { 83 | return d.Number 84 | } 85 | 86 | func NewPathRule(num string) Params { 87 | var s Params = new(PathRule) 88 | s.SetNumber(num) 89 | return s 90 | } 91 | 92 | func (d *PathRule) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 93 | if strings.Contains(key, "service") { 94 | d.Service = value 95 | } else if strings.Contains(key, "paths") { 96 | d.Paths = append(d.Paths, value) 97 | } 98 | } 99 | 100 | type HostRule struct { 101 | Number string 102 | Description string `json:"description"` 103 | Hosts []string `json:"hosts"` 104 | PathMatcher string `json:"path_matcher"` 105 | } 106 | 107 | func (d *HostRule) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 108 | if strings.Contains(key, "description") { 109 | d.Description = value 110 | } else if strings.Contains(key, "hosts") { 111 | d.Hosts = append(d.Hosts, value) 112 | } else if strings.Contains(key, "path_matcher") { 113 | d.PathMatcher = value 114 | } 115 | } 116 | 117 | func (d *HostRule) SetNumber(num string) { 118 | d.Number = num 119 | } 120 | 121 | func (d *HostRule) GetNumber() string { 122 | return d.Number 123 | } 124 | 125 | func NewHostRule(num string) Params { 126 | var s Params = new(HostRule) 127 | s.SetNumber(num) 128 | return s 129 | } 130 | 131 | type Test struct { 132 | Number string 133 | Description string `json:"description"` 134 | Host string `json:"host"` 135 | Path string `json:"path"` 136 | Service string `json:"service"` 137 | } 138 | 139 | func (d *Test) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 140 | if strings.Contains(key, "description") { 141 | d.Description = value 142 | } else if strings.Contains(key, "host") { 143 | d.Host = value 144 | } else if strings.Contains(key, "path") { 145 | d.Path = value 146 | } else if strings.Contains(key, "service") { 147 | d.Service = value 148 | } 149 | } 150 | 151 | func (d *Test) SetNumber(num string) { 152 | d.Number = num 153 | } 154 | 155 | func (d *Test) GetNumber() string { 156 | return d.Number 157 | } 158 | 159 | func NewTest(num string) Params { 160 | var s Params = new(HostRule) 161 | s.SetNumber(num) 162 | return s 163 | } 164 | 165 | func Newgoogle_compute_url_map(resourceData map[string]interface{}, resourceName string) *google_compute_url_map { 166 | 167 | resource := new(google_compute_url_map) 168 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 169 | attributesKey := CreateAttributesKey(attributes_map) 170 | MapToStruct(resourceData, resource) 171 | resource.Primary.ID = resourceName 172 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 173 | 174 | //attributes need to transform 175 | resource.Primary.Attributes.HostRule = CreateStructSlice(attributes_map, attributesKey, "host_rule", 1, NewHostRule) 176 | resource.Primary.Attributes.PathMatcher = CreateStructSlice(attributes_map, attributesKey, "path_matcher", 1, NewPathMatcher) 177 | 178 | //beta 179 | if resourceData["provider"] == "provider.google-beta" { 180 | } 181 | return resource 182 | } 183 | -------------------------------------------------------------------------------- /resources/resource_google_dns_managed_zone.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_dns_managed_zone struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | Description string `json:"description"` 14 | DNSName string `json:"dns_name"` 15 | ForwardingConfig []Params `json:"forwarding_config"` 16 | ID string `json:"id"` 17 | Labels map[string]string `json:"labels"` 18 | Name string `json:"name"` 19 | NameServers []string `json:"name_servers"` 20 | PeeringConfig []Params `json:"peering_config"` 21 | PrivateVisibilityConfig []Params `json:"private_visibility_config"` 22 | Project string `json:"project"` 23 | Visibility string `json:"visibility"` 24 | } `json:"attributes"` 25 | Meta struct { 26 | SchemaVersion string `json:"schema_version"` 27 | } `json:"meta"` 28 | Tainted bool `json:"tainted"` 29 | } `json:"primary"` 30 | Deposed []interface{} `json:"deposed"` 31 | Provider string `json:"provider"` 32 | } 33 | 34 | type ForwardingConfig struct { 35 | Number string 36 | TargetNameServers []Params `json:"target_name_servers"` 37 | } 38 | 39 | func (d *ForwardingConfig) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 40 | if strings.Contains(key, "target_name_servers") { 41 | Number := CreateNumberFromKey(key, 2) 42 | d.TargetNameServers = CreateStructSlice(attributes_map, attributesKey, Number, 3, NewTargetNameServers) 43 | } 44 | } 45 | 46 | func (d *ForwardingConfig) SetNumber(num string) { 47 | d.Number = num 48 | } 49 | 50 | func (d *ForwardingConfig) GetNumber() string { 51 | return d.Number 52 | } 53 | 54 | func NewForwardingConfig(num string) Params { 55 | var s Params = new(ForwardingConfig) 56 | s.SetNumber(num) 57 | return s 58 | } 59 | 60 | type TargetNameServers struct { 61 | Number string 62 | IPv4Address string `json:"ipv4_address"` 63 | } 64 | 65 | func (d *TargetNameServers) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 66 | if strings.Contains(key, "ipv4_address") { 67 | d.IPv4Address = value 68 | } 69 | } 70 | 71 | func (d *TargetNameServers) SetNumber(num string) { 72 | d.Number = num 73 | } 74 | 75 | func (d *TargetNameServers) GetNumber() string { 76 | return d.Number 77 | } 78 | 79 | func NewTargetNameServers(num string) Params { 80 | var s Params = new(TargetNameServers) 81 | s.SetNumber(num) 82 | return s 83 | } 84 | 85 | type PeeringConfig struct { 86 | Number string 87 | TargetNetwork []Params `json:"target_network"` 88 | } 89 | 90 | func (d *PeeringConfig) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 91 | if strings.Contains(key, "target_network") { 92 | Number := CreateNumberFromKey(key, 2) 93 | d.TargetNetwork = CreateStructSlice(attributes_map, attributesKey, Number, 3, NewTargetNetwork) 94 | } 95 | } 96 | 97 | func (d *PeeringConfig) SetNumber(num string) { 98 | d.Number = num 99 | } 100 | 101 | func (d *PeeringConfig) GetNumber() string { 102 | return d.Number 103 | } 104 | 105 | func NewPeeringConfig(num string) Params { 106 | var s Params = new(PeeringConfig) 107 | s.SetNumber(num) 108 | return s 109 | } 110 | 111 | type TargetNetwork struct { 112 | Number string 113 | NetworkURL string `json:"network_url"` 114 | } 115 | 116 | func (d *TargetNetwork) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 117 | if strings.Contains(key, "network_url") { 118 | d.NetworkURL = value 119 | } 120 | } 121 | 122 | func (d *TargetNetwork) SetNumber(num string) { 123 | d.Number = num 124 | } 125 | 126 | func (d *TargetNetwork) GetNumber() string { 127 | return d.Number 128 | } 129 | 130 | func NewTargetNetwork(num string) Params { 131 | var s Params = new(TargetNetwork) 132 | s.SetNumber(num) 133 | return s 134 | } 135 | 136 | type PrivateVisibilityConfig struct { 137 | Number string 138 | Networks []Params `json:"networks"` 139 | } 140 | 141 | func (d *PrivateVisibilityConfig) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 142 | if strings.Contains(key, "target_network") { 143 | Number := CreateNumberFromKey(key, 2) 144 | d.Networks = CreateStructSlice(attributes_map, attributesKey, Number, 3, NewNetworks) 145 | } 146 | } 147 | 148 | func (d *PrivateVisibilityConfig) SetNumber(num string) { 149 | d.Number = num 150 | } 151 | 152 | func (d *PrivateVisibilityConfig) GetNumber() string { 153 | return d.Number 154 | } 155 | 156 | func NewPrivateVisibilityConfig(num string) Params { 157 | var s Params = new(PrivateVisibilityConfig) 158 | s.SetNumber(num) 159 | return s 160 | } 161 | 162 | type Networks struct { 163 | Number string 164 | NetworkURL string `json:"network_url"` 165 | } 166 | 167 | func (d *Networks) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 168 | if strings.Contains(key, "network_url") { 169 | d.NetworkURL = value 170 | } 171 | } 172 | 173 | func (d *Networks) SetNumber(num string) { 174 | d.Number = num 175 | } 176 | 177 | func (d *Networks) GetNumber() string { 178 | return d.Number 179 | } 180 | 181 | func NewNetworks(num string) Params { 182 | var s Params = new(Networks) 183 | s.SetNumber(num) 184 | return s 185 | } 186 | 187 | func Newgoogle_dns_managed_zone(resourceData map[string]interface{}, resourceName string) *google_dns_managed_zone { 188 | 189 | resource := new(google_dns_managed_zone) 190 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 191 | attributesKey := CreateAttributesKey(attributes_map) 192 | MapToStruct(resourceData, resource) 193 | resource.Primary.ID = resourceName 194 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 195 | 196 | //attributes need to transform 197 | resource.Primary.Attributes.NameServers = CreateStringSlice(attributes_map, attributesKey, "name_servers") 198 | resource.Primary.Attributes.PeeringConfig = CreateStructSlice(attributes_map, attributesKey, "peering_config", 1, NewPeeringConfig) 199 | resource.Primary.Attributes.ForwardingConfig = CreateStructSlice(attributes_map, attributesKey, "forwarding_config", 1, NewForwardingConfig) 200 | resource.Primary.Attributes.PrivateVisibilityConfig = CreateStructSlice(attributes_map, attributesKey, "private_visibility_config", 1, NewPrivateVisibilityConfig) 201 | 202 | return resource 203 | } 204 | -------------------------------------------------------------------------------- /resources/resource_google_dns_policy.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_dns_policy struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | AlternativeNameServerConfig []Params `json:"alternative_name_server_config"` 14 | Description string `json:"description"` 15 | EnableInboundForwarding string `json:"enable_inbound_forwarding"` 16 | EnableLogging string `json:"enable_logging"` 17 | ID string `json:"id"` 18 | Name string `json:"name"` 19 | Networks []Params `json:"networks"` 20 | Project string `json:"project"` 21 | } `json:"attributes"` 22 | Meta struct { 23 | SchemaVersion string `json:"schema_version"` 24 | } `json:"meta"` 25 | Tainted bool `json:"tainted"` 26 | } `json:"primary"` 27 | Deposed []interface{} `json:"deposed"` 28 | Provider string `json:"provider"` 29 | } 30 | 31 | type AlternativeNameServerConfig struct { 32 | Number string 33 | TargetNameServers []string `json:"target_name_servers"` 34 | } 35 | 36 | func (d *AlternativeNameServerConfig) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 37 | if strings.Contains(key, "target_name_servers") { 38 | d.TargetNameServers = append(d.TargetNameServers, value) 39 | } 40 | } 41 | 42 | func (d *AlternativeNameServerConfig) SetNumber(num string) { 43 | d.Number = num 44 | } 45 | 46 | func (d *AlternativeNameServerConfig) GetNumber() string { 47 | return d.Number 48 | } 49 | 50 | func NewAlternativeNameServerConfig(num string) Params { 51 | var s Params = new(AlternativeNameServerConfig) 52 | s.SetNumber(num) 53 | return s 54 | } 55 | 56 | func Newgoogle_dns_policy(resourceData map[string]interface{}, resourceName string) *google_dns_policy { 57 | 58 | resource := new(google_dns_policy) 59 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 60 | attributesKey := CreateAttributesKey(attributes_map) 61 | MapToStruct(resourceData, resource) 62 | resource.Primary.ID = resourceName 63 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 64 | 65 | //attributes need to transform 66 | resource.Primary.Attributes.AlternativeNameServerConfig = CreateStructSlice(attributes_map, attributesKey, "alternative_name_server_config", 1, NewAlternativeNameServerConfig) 67 | resource.Primary.Attributes.Networks = CreateStructSlice(attributes_map, attributesKey, "networks", 1, NewNetworks) 68 | 69 | return resource 70 | } 71 | -------------------------------------------------------------------------------- /resources/resource_google_kms_crypto_key.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import "strings" 4 | 5 | type google_kms_crypto_key struct { 6 | Type string `json:"type"` 7 | DependsOn []string `json:"depends_on"` 8 | Primary struct { 9 | ID string `json:"id"` 10 | Attributes struct { 11 | ID string `json:"id"` 12 | KeyRing string `json:"key_ring"` 13 | Name string `json:"name"` 14 | RotationPeriod string `json:"rotation_period"` 15 | SelfLink string `json:"self_link"` 16 | VersionTemplate []Params `json:"version_template"` 17 | } `json:"attributes"` 18 | Meta struct { 19 | SchemaVersion string `json:"schema_version"` 20 | } `json:"meta"` 21 | Tainted bool `json:"tainted"` 22 | } `json:"primary"` 23 | Deposed []interface{} `json:"deposed"` 24 | Provider string `json:"provider"` 25 | } 26 | 27 | type VersionTemplate struct { 28 | Number string 29 | Algorithm string `json:"algorithm"` 30 | ProtectionLevel string `json:"protection_level"` 31 | } 32 | 33 | func (d *VersionTemplate) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 34 | if strings.Contains(key, "algorithm") { 35 | d.Algorithm = value 36 | } else if strings.Contains(key, "protection_level") { 37 | d.ProtectionLevel = value 38 | } 39 | } 40 | 41 | func (d *VersionTemplate) SetNumber(num string) { 42 | d.Number = num 43 | } 44 | 45 | func (d *VersionTemplate) GetNumber() string { 46 | return d.Number 47 | } 48 | 49 | func NewVersionTemplate(num string) Params { 50 | var s Params = new(VersionTemplate) 51 | s.SetNumber(num) 52 | return s 53 | } 54 | 55 | func Newgoogle_kms_crypto_key(resourceData map[string]interface{}, resourceName string) *google_kms_crypto_key { 56 | 57 | resource := new(google_kms_crypto_key) 58 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 59 | attributesKey := CreateAttributesKey(attributes_map) 60 | MapToStruct(resourceData, resource) 61 | resource.Primary.ID = resourceName 62 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 63 | 64 | //attributes need to transform 65 | resource.Primary.Attributes.VersionTemplate = CreateStructSlice(attributes_map, attributesKey, "version_template", 1, NewVersionTemplate) 66 | 67 | return resource 68 | } 69 | -------------------------------------------------------------------------------- /resources/resource_google_kms_key_ring.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_kms_key_ring struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | ID string `json:"id"` 10 | Location string `json:"location"` 11 | Name string `json:"name"` 12 | Project string `json:"project"` 13 | SelfLink string `json:"self_link"` 14 | } `json:"attributes"` 15 | Meta struct { 16 | SchemaVersion string `json:"schema_version"` 17 | } `json:"meta"` 18 | Tainted bool `json:"tainted"` 19 | } `json:"primary"` 20 | Deposed []interface{} `json:"deposed"` 21 | Provider string `json:"provider"` 22 | } 23 | 24 | func Newgoogle_kms_key_ring(resourceData map[string]interface{}, resourceName string) *google_kms_key_ring { 25 | 26 | resource := new(google_kms_key_ring) 27 | //attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 28 | //attributesKey := CreateAttributesKey(attributes_map) 29 | MapToStruct(resourceData, resource) 30 | resource.Primary.ID = resourceName 31 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 32 | 33 | //attributes need to transform 34 | 35 | //beta 36 | return resource 37 | } 38 | -------------------------------------------------------------------------------- /resources/resource_google_project.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_project struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | AppEngine string `json:"app_engine.#"` 10 | AutoCreateNetwork string `json:"auto_create_network"` 11 | BillingAccount string `json:"billing_account"` 12 | FolderID string `json:"folder_id"` 13 | ID string `json:"id"` 14 | Labels map[string]string `json:"labels.%"` 15 | Name string `json:"name"` 16 | Number string `json:"number"` 17 | OrgID string `json:"org_id"` 18 | ProjectID string `json:"project_id"` 19 | } `json:"attributes"` 20 | Meta struct { 21 | SchemaVersion string `json:"schema_version"` 22 | } `json:"meta"` 23 | Tainted bool `json:"tainted"` 24 | } `json:"primary"` 25 | Deposed []interface{} `json:"deposed"` 26 | Provider string `json:"provider"` 27 | } 28 | 29 | func Newgoogle_project(resourceData map[string]interface{}, resourceName string) *google_project { 30 | 31 | resource := new(google_project) 32 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 33 | //attributesKey := CreateAttributesKey(attributes_map) 34 | MapToStruct(resourceData, resource) 35 | resource.Primary.ID = resourceName 36 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 37 | 38 | //attributes need to transform 39 | resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 40 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 41 | //beta 42 | if resourceData["provider"] == "provider.google-beta" { 43 | } 44 | return resource 45 | } 46 | -------------------------------------------------------------------------------- /resources/resource_google_pubsub_subscription.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_pubsub_subscription struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | AckDeadlineSeconds string `json:"ack_deadline_seconds"` 14 | ID string `json:"id"` 15 | Labels map[string]string `json:"labels"` 16 | MessageRetentionDuration string `json:"message_retention_duration"` 17 | Name string `json:"name"` 18 | Path string `json:"path"` 19 | Project string `json:"project"` 20 | PushConfig []Params `json:"push_config"` 21 | RetainAckedMessages string `json:"retain_acked_messages"` 22 | Topic string `json:"topic"` 23 | ExpirationPolicy []Params `json:"expiration_policy"` 24 | } `json:"attributes"` 25 | Meta struct { 26 | SchemaVersion string `json:"schema_version"` 27 | } `json:"meta"` 28 | Tainted bool `json:"tainted"` 29 | } `json:"primary"` 30 | Deposed []interface{} `json:"deposed"` 31 | Provider string `json:"provider"` 32 | } 33 | 34 | type PushConfig struct { 35 | Number string 36 | PushEndpoint string `json:"push_endpoint"` 37 | Attributes string `json:"attributes"` 38 | } 39 | 40 | func (d *PushConfig) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 41 | if strings.Contains(key, "push_endpoint") { 42 | d.PushEndpoint = value 43 | } else if strings.Contains(key, "attributes") { 44 | d.Attributes = value 45 | } 46 | } 47 | 48 | func (d *PushConfig) SetNumber(num string) { 49 | d.Number = num 50 | } 51 | 52 | func (d *PushConfig) GetNumber() string { 53 | return d.Number 54 | } 55 | 56 | func NewPushConfig(num string) Params { 57 | var s Params = new(PushConfig) 58 | s.SetNumber(num) 59 | return s 60 | } 61 | 62 | type ExpirationPolicy struct { 63 | Number string 64 | TTL string `json:"ttl"` 65 | } 66 | 67 | func (d *ExpirationPolicy) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 68 | if strings.Contains(key, "ttl") { 69 | d.TTL = value 70 | } 71 | } 72 | 73 | func (d *ExpirationPolicy) SetNumber(num string) { 74 | d.Number = num 75 | } 76 | 77 | func (d *ExpirationPolicy) GetNumber() string { 78 | return d.Number 79 | } 80 | 81 | func NewExpirationPolicy(num string) Params { 82 | var s Params = new(ExpirationPolicy) 83 | s.SetNumber(num) 84 | return s 85 | } 86 | 87 | func Newgoogle_pubsub_subscription(resourceData map[string]interface{}, resourceName string) *google_pubsub_subscription { 88 | 89 | resource := new(google_pubsub_subscription) 90 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 91 | attributesKey := CreateAttributesKey(attributes_map) 92 | MapToStruct(resourceData, resource) 93 | resource.Primary.ID = resourceName 94 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 95 | 96 | //attributes need to transform 97 | 98 | resource.Primary.Attributes.PushConfig = CreateStructSlice(attributes_map, attributesKey, "push_config", 1, NewPushConfig) 99 | resource.Primary.Attributes.ExpirationPolicy = CreateStructSlice(attributes_map, attributesKey, "expiration_policy", 1, NewExpirationPolicy) 100 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 101 | 102 | return resource 103 | } 104 | -------------------------------------------------------------------------------- /resources/resource_google_pubsub_topic.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_pubsub_topic struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | ID string `json:"id"` 10 | Labels map[string]string `json:"labels"` 11 | Name string `json:"name"` 12 | Project string `json:"project"` 13 | } `json:"attributes"` 14 | Meta struct { 15 | SchemaVersion string `json:"schema_version"` 16 | } `json:"meta"` 17 | Tainted bool `json:"tainted"` 18 | } `json:"primary"` 19 | Deposed []interface{} `json:"deposed"` 20 | Provider string `json:"provider"` 21 | } 22 | 23 | func Newgoogle_pubsub_topic(resourceData map[string]interface{}, resourceName string) *google_pubsub_topic { 24 | 25 | resource := new(google_pubsub_topic) 26 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 27 | //attributesKey := CreateAttributesKey(attributes_map) 28 | MapToStruct(resourceData, resource) 29 | resource.Primary.ID = resourceName 30 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 31 | 32 | //attributes need to transform 33 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 34 | 35 | return resource 36 | } 37 | -------------------------------------------------------------------------------- /resources/resource_google_service_account.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | type google_service_account struct { 4 | Type string `json:"type"` 5 | DependsOn []string `json:"depends_on"` 6 | Primary struct { 7 | ID string `json:"id"` 8 | Attributes struct { 9 | AccountID string `json:"account_id"` 10 | DisplayName string `json:"display_name"` 11 | Email string `json:"email"` 12 | ID string `json:"id"` 13 | Name string `json:"name"` 14 | Project string `json:"project"` 15 | UniqueID string `json:"unique_id"` 16 | } `json:"attributes"` 17 | Meta struct { 18 | SchemaVersion string `json:"schema_version"` 19 | } `json:"meta"` 20 | Tainted bool `json:"tainted"` 21 | } `json:"primary"` 22 | Deposed []interface{} `json:"deposed"` 23 | Provider string `json:"provider"` 24 | } 25 | 26 | func Newgoogle_service_account(resourceData map[string]interface{}, resourceName string) *google_service_account { 27 | 28 | resource := new(google_service_account) 29 | //attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 30 | //attributesKey := CreateAttributesKey(attributes_map) 31 | MapToStruct(resourceData, resource) 32 | resource.Primary.ID = resourceName 33 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 34 | 35 | //attributes need to transform 36 | 37 | //beta 38 | if resourceData["provider"] == "provider.google-beta" { 39 | } 40 | return resource 41 | } 42 | -------------------------------------------------------------------------------- /resources/resource_google_storage_bucket.go: -------------------------------------------------------------------------------- 1 | package resources 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | type google_storage_bucket struct { 8 | Type string `json:"type"` 9 | DependsOn []string `json:"depends_on"` 10 | Primary struct { 11 | ID string `json:"id"` 12 | Attributes struct { 13 | Cors []Params `json:"cors"` 14 | Encryption []Params `json:"encryption"` 15 | ForceDestroy string `json:"force_destroy"` 16 | ID string `json:"id"` 17 | Labels map[string]string `json:"labels"` 18 | LifecycleRule []Params `json:"lifecycle_rule"` 19 | Location string `json:"location"` 20 | Logging []Params `json:"logging"` 21 | Name string `json:"name"` 22 | Project string `json:"project"` 23 | RequesterPays string `json:"requester_pays"` 24 | SelfLink string `json:"self_link"` 25 | StorageClass string `json:"storage_class"` 26 | URL string `json:"url"` 27 | Versioning []Params `json:"versioning"` 28 | } `json:"attributes"` 29 | Meta struct { 30 | SchemaVersion string `json:"schema_version"` 31 | } `json:"meta"` 32 | Tainted bool `json:"tainted"` 33 | } `json:"primary"` 34 | Deposed []interface{} `json:"deposed"` 35 | Provider string `json:"provider"` 36 | } 37 | 38 | type Cors struct { 39 | Number string 40 | MaxAgeSeconds string `json:"max_age_seconds"` 41 | Method []string `json:"method"` 42 | Origin []string `json:"origin"` 43 | ResponseHeader []string `json:"response_header"` 44 | } 45 | 46 | func (d *Cors) SetNumber(num string) { 47 | d.Number = num 48 | } 49 | func (d *Cors) GetNumber() string { 50 | return d.Number 51 | } 52 | func NewCors(num string) Params { 53 | var s Params = new(Cors) 54 | s.SetNumber(num) 55 | return s 56 | } 57 | func (d *Cors) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 58 | if strings.Contains(key, "max_age_seconds") { 59 | d.MaxAgeSeconds = value 60 | } else if strings.Contains(key, "method") { 61 | d.Method = append(d.Method, value) 62 | } else if strings.Contains(key, "origin") { 63 | d.Origin = append(d.Origin, value) 64 | } else if strings.Contains(key, "response_header") { 65 | d.ResponseHeader = append(d.ResponseHeader, value) 66 | } 67 | } 68 | 69 | type LifecycleRule struct { 70 | Number string 71 | Action []Params `json:"lifecycle_rule.action"` 72 | Condition []Params `json:"lifecycle_rule.condition"` 73 | } 74 | 75 | func (d *LifecycleRule) SetNumber(num string) { 76 | d.Number = num 77 | } 78 | func (d *LifecycleRule) GetNumber() string { 79 | return d.Number 80 | } 81 | func NewLifecycleRule(num string) Params { 82 | var s Params = new(LifecycleRule) 83 | s.SetNumber(num) 84 | return s 85 | } 86 | 87 | func (d *LifecycleRule) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 88 | if strings.Contains(key, "action") { 89 | //lifecycle_rule.0.actionまでを取得 90 | Number := CreateNumberFromKey(key, 2) 91 | d.Action = CreateStructSlice(attributes_map, attributesKey, Number, 3, NewAction) 92 | } else if strings.Contains(key, "condition") { 93 | //lifecycle_rule.0.conditionまでを取得 94 | Number := CreateNumberFromKey(key, 2) 95 | d.Condition = CreateStructSlice(attributes_map, attributesKey, Number, 3, NewCondition) 96 | } 97 | } 98 | 99 | type Action struct { 100 | Number string 101 | StorageClass string `json:"storage_class"` 102 | Type string `json:"type"` 103 | } 104 | 105 | func (d *Action) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 106 | if strings.Contains(key, "storage_class") { 107 | d.StorageClass = value 108 | } else if strings.Contains(key, "type") { 109 | d.Type = value 110 | } 111 | } 112 | 113 | func (d *Action) SetNumber(num string) { 114 | d.Number = num 115 | } 116 | 117 | func (d *Action) GetNumber() string { 118 | return d.Number 119 | } 120 | 121 | func NewAction(num string) Params { 122 | var s Params = new(Action) 123 | s.SetNumber(num) 124 | return s 125 | } 126 | 127 | type Condition struct { 128 | Number string 129 | Age string `json:"age"` 130 | CreatedBefore string `json:"created_before"` 131 | IsLive string `json:"is_live"` 132 | MatchesStorageClass []string `json:"matches_storage_class"` 133 | NumNewerVersions string `json:"num_newer_versions"` 134 | WithState string `json:"with_state"` 135 | } 136 | 137 | func (d *Condition) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 138 | if strings.Contains(key, "age") && !strings.Contains(key, "storage") { 139 | d.Age = value 140 | } else if strings.Contains(key, "created_before") { 141 | d.CreatedBefore = value 142 | } else if strings.Contains(key, "is_live") { 143 | d.IsLive = value 144 | } else if strings.Contains(key, "matches_storage_class") { 145 | d.MatchesStorageClass = append(d.MatchesStorageClass, value) 146 | } else if strings.Contains(key, "num_newer_versions") { 147 | d.NumNewerVersions = value 148 | } else if strings.Contains(key, "with_state") { 149 | d.WithState = value 150 | } 151 | } 152 | 153 | func (d *Condition) SetNumber(num string) { 154 | d.Number = num 155 | } 156 | 157 | func (d *Condition) GetNumber() string { 158 | return d.Number 159 | } 160 | 161 | func NewCondition(num string) Params { 162 | var s Params = new(Condition) 163 | s.SetNumber(num) 164 | return s 165 | } 166 | 167 | type Encryption struct { 168 | Number string 169 | DefaultKmsKeyName string `json:"default_kms_key_name"` 170 | } 171 | 172 | func (d *Encryption) SetNumber(num string) { 173 | d.Number = num 174 | } 175 | func (d *Encryption) GetNumber() string { 176 | return d.Number 177 | } 178 | func NewEncryption(num string) Params { 179 | var s Params = new(Encryption) 180 | s.SetNumber(num) 181 | return s 182 | } 183 | 184 | func (d *Encryption) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 185 | if strings.Contains(key, "default_kms_key_name") { 186 | d.DefaultKmsKeyName = value 187 | } 188 | } 189 | 190 | type Versioning struct { 191 | Number string 192 | Enabled string `json:"enabled"` 193 | } 194 | 195 | func (d *Versioning) SetNumber(num string) { 196 | d.Number = num 197 | } 198 | 199 | func (d *Versioning) GetNumber() string { 200 | return d.Number 201 | } 202 | 203 | func NewVersioning(num string) Params { 204 | var s Params = new(Versioning) 205 | s.SetNumber(num) 206 | return s 207 | } 208 | 209 | func (d *Versioning) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 210 | if strings.Contains(key, "enabled") { 211 | d.Enabled = value 212 | } 213 | } 214 | 215 | type Logging struct { 216 | Number string 217 | LogBucket string `json:"log_bucket"` 218 | LogObjectPrefix string `json:"log_object_prefix"` 219 | } 220 | 221 | func (d *Logging) SetNumber(num string) { 222 | d.Number = num 223 | } 224 | 225 | func (d *Logging) GetNumber() string { 226 | return d.Number 227 | } 228 | 229 | func NewLogging(num string) Params { 230 | var s Params = new(Logging) 231 | s.SetNumber(num) 232 | return s 233 | } 234 | 235 | func (d *Logging) SetParameter(key, value string, attributes_map map[string]interface{}, attributesKey []string) { 236 | if strings.Contains(key, "log_bucket") { 237 | d.LogBucket = value 238 | } else if strings.Contains(key, "log_object_prefix") { 239 | d.LogObjectPrefix = value 240 | } 241 | } 242 | 243 | func Newgoogle_storage_bucket(resourceData map[string]interface{}, resourceName string) *google_storage_bucket { 244 | 245 | resource := new(google_storage_bucket) 246 | attributes_map := resourceData["primary"].(map[string]interface{})["attributes"].(map[string]interface{}) 247 | attributesKey := CreateAttributesKey(attributes_map) 248 | MapToStruct(resourceData, resource) 249 | resource.Primary.ID = resourceName 250 | //resource.DependsOn = InterfaceToStrings(resourceData["depends_on"].([]interface{})) 251 | 252 | //attributes need to transform 253 | resource.Primary.Attributes.Cors = CreateStructSlice(attributes_map, attributesKey, "cors", 1, NewCors) 254 | resource.Primary.Attributes.Encryption = CreateStructSlice(attributes_map, attributesKey, "encryption", 1, NewCors) 255 | resource.Primary.Attributes.Labels = CreateMap(attributes_map, "labels") 256 | resource.Primary.Attributes.LifecycleRule = CreateStructSlice(attributes_map, attributesKey, "lifecycle_rule", 1, NewLifecycleRule) 257 | resource.Primary.Attributes.Logging = CreateStructSlice(attributes_map, attributesKey, "logging", 1, NewLogging) 258 | resource.Primary.Attributes.Versioning = CreateStructSlice(attributes_map, attributesKey, "versioning", 1, NewVersioning) 259 | 260 | //beta 261 | if resourceData["provider"] == "provider.google-beta" { 262 | } 263 | return resource 264 | } 265 | -------------------------------------------------------------------------------- /resources/templates/google_compute_autoscaler.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_autoscaler" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | target = "{{.Primary.Attributes.Target}}" 9 | 10 | {{range $i, $v := .Primary.Attributes.AutoscalingPolicy}} 11 | autoscaling_policy { 12 | //required 13 | max_replicas = "{{$v.MaxReplica}}" 14 | min_replicas = "{{$v.MinReplica}}" 15 | //optional 16 | {{$tmp := $v.CooldownPeriod}}{{with $tmp}} 17 | cooldown_period = "{{$tmp}}"{{end}} 18 | 19 | {{$tmp := $v.CPUTarget}}{{with $tmp}} 20 | cpu_utilization { 21 | target = "{{$tmp}}" 22 | }{{end}} 23 | 24 | {{$tmp := $v.LoadBalancingTarget}}{{with $tmp}} 25 | load_balancing_utilization { 26 | target = "{{$tmp}}" 27 | }{{end}} 28 | 29 | {{$tmp := $v.Metric}}{{with $tmp}} 30 | {{range $ii, $vv := $tmp}} 31 | metric { 32 | name = "{{$vv.Name}}" 33 | {{with $vv.Type}}type = "{{$vv.Type}}"{{end}} 34 | {{with $vv.Target}}target = "{{$vv.Target}}"{{end}} 35 | //beta 36 | //single_instance_assignment 37 | //filter 38 | }{{end}}{{end}} 39 | }{{end}} 40 | //optional 41 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 42 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 43 | 44 | {{$tmp := .Primary.Attributes.Zone}}{{with $tmp}} 45 | zone = "{{$tmp}}"{{end}} 46 | 47 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 48 | project = "{{$tmp}}"{{end}} 49 | 50 | //beta 51 | } 52 | -------------------------------------------------------------------------------- /resources/templates/google_compute_backend_bucket.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_backend_bucket" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | bucket_name = "{{.Primary.Attributes.BucketName}}" 8 | 9 | //optional 10 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 11 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 12 | 13 | {{$tmp := .Primary.Attributes.EnableCdn}}{{with $tmp}} 14 | enable_cdn = "{{$tmp}}"{{end}} 15 | 16 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 17 | project = "{{$tmp}}"{{end}} 18 | 19 | 20 | {{range $i, $v := .Primary.Attributes.CdnPolicy}} 21 | cdn_policy { 22 | {{$tmp := $v.SignedUrlCacheMaxAgeSec}}{{with $tmp}}signed_url_cache_max_age_sec = "{{$tmp}}"{{end}} 23 | }{{end}} 24 | 25 | } 26 | -------------------------------------------------------------------------------- /resources/templates/google_compute_backend_service.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_backend_service" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | {{$tmp := .Primary.Attributes.HealthChecks}}{{$length := len $tmp}} 8 | health_checks = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}] 9 | 10 | //optional 11 | {{$tmp := .Primary.Attributes.AffinityCookieTTLSec}}{{with $tmp}} 12 | affinity_cookie_ttl_sec = "{{$tmp}}"{{end}} 13 | 14 | {{$tmp := .Primary.Attributes.AffinityCookieTTLSec}}{{with $tmp}} 15 | affinity_cookie_ttl_sec = "{{$tmp}}"{{end}} 16 | 17 | {{$tmp := .Primary.Attributes.ConnectionDrainingTimeoutSec}}{{with $tmp}} 18 | connection_draining_timeout_sec = "{{$tmp}}"{{end}} 19 | 20 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 21 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 22 | 23 | {{$tmp := .Primary.Attributes.EnableCdn}}{{with $tmp}} 24 | enable_cdn = "{{$tmp}}"{{end}} 25 | 26 | {{$tmp := .Primary.Attributes.PortName}}{{with $tmp}} 27 | port_name = "{{$tmp}}"{{end}} 28 | 29 | {{$tmp := .Primary.Attributes.Protocol}}{{with $tmp}} 30 | protocol = "{{$tmp}}"{{end}} 31 | 32 | {{$tmp := .Primary.Attributes.LoadBalancingScheme}}{{with $tmp}} 33 | load_balancing_scheme = "{{$tmp}}"{{end}} 34 | 35 | {{$tmp := .Primary.Attributes.SecurityPolicy}}{{with $tmp}} 36 | security_policy = "{{$tmp}}"{{end}} 37 | 38 | {{$tmp := .Primary.Attributes.SessionAffinity}}{{with $tmp}} 39 | session_affinity = "{{$tmp}}"{{end}} 40 | 41 | {{$tmp := .Primary.Attributes.TimeoutSec}}{{with $tmp}} 42 | timeout_sec = "{{$tmp}}"{{end}} 43 | 44 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 45 | project = "{{$tmp}}"{{end}} 46 | 47 | {{range $i, $v := .Primary.Attributes.Backend}} 48 | backend { 49 | {{$tmp := $v.BalancingMode}}{{with $tmp}}balancing_mode = "{{$tmp}}"{{end}} 50 | {{$tmp := $v.CapacityScaler}}{{with $tmp}}capacity_scaler = "{{$tmp}}"{{end}} 51 | {{$tmp := $v.Description}}{{with $tmp}}description = "{{escapeDoubleQuote $tmp}}"{{end}} 52 | {{$tmp := $v.Group}}{{with $tmp}}group = "{{$tmp}}"{{end}} 53 | {{$tmp := $v.MaxConnections}}{{with $tmp}}max_connections = "{{$tmp}}"{{end}} 54 | {{$tmp := $v.MaxConnectionsPerInstance}}{{with $tmp}}max_connections_per_instance = "{{$tmp}}"{{end}} 55 | {{$tmp := $v.MaxRate}}{{with $tmp}}max_rate = "{{$tmp}}"{{end}} 56 | {{$tmp := $v.MaxRatePerInstance}}{{with $tmp}}max_rate_per_instance = "{{$tmp}}"{{end}} 57 | {{$tmp := $v.MaxUtilization}}{{with $tmp}}max_utilization = "{{$tmp}}"{{end}} 58 | }{{end}} 59 | 60 | {{range $i, $v := .Primary.Attributes.Iap}} 61 | iap { 62 | {{$tmp := $v.Oauth2ClientId}}{{with $tmp}}oauth2_client_id = "{{$tmp}}"{{end}} 63 | {{$tmp := $v.Oauth2ClientSecret}}{{with $tmp}}oauth2_client_secret = "{{$tmp}}"{{end}} 64 | {{$tmp := $v.Oauth2ClientSecretSha256}}{{with $tmp}}oauth2_client_secret_sha256 = "{{$tmp}}"{{end}} 65 | }{{end}} 66 | 67 | {{range $i, $v := .Primary.Attributes.CdnPolicy}} 68 | cdn_policy { 69 | {{$tmp := $v.SignedUrlCacheMaxAgeSec}}{{with $tmp}}signed_url_cache_max_age_sec = "{{$tmp}}"{{end}} 70 | 71 | {{$tmp := $v.CacheKeyPolicy}}{{with $tmp}} 72 | {{range $ii, $vv := $tmp}} 73 | cache_key_policy{ 74 | {{$tmp1 := $v.IncludHost}}{{with $tmp1}}include_host = "{{$tmp1}}"{{end}} 75 | {{$tmp1 := $v.IncludProtocol}}{{with $tmp1}}include_protocol = "{{$tmp1}}"{{end}} 76 | {{$tmp1 := $v.IncludQueryString}}{{with $tmp1}}include_query_string = "{{$tmp1}}"{{end}} 77 | {{$tmp1 := $v.QueryStringBlackList}}{{with $tmp1}}query_string_blacklist = "{{$tmp1}}"{{end}} 78 | {{$tmp1 := $v.QueryStringWhiteList}}{{with $tmp1}}query_string_whitelist = "{{$tmp1}}"{{end}} 79 | }{{end}}{{end}} 80 | }{{end}} 81 | 82 | //beta 83 | //custom_request_headers 84 | } 85 | -------------------------------------------------------------------------------- /resources/templates/google_compute_disk.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_disk" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | //optional 8 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 9 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 10 | 11 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 12 | labels { 13 | {{range $i, $v := $tmp}} 14 | {{$i}} = "{{$v}}"{{end}} 15 | }{{end}} 16 | 17 | {{$tmp := .Primary.Attributes.Size}}{{with $tmp}} 18 | size = "{{$tmp}}"{{end}} 19 | 20 | {{$tmp := .Primary.Attributes.PhysicalBlockSizeBytes}}{{with $tmp}} 21 | physical_block_size_bytes = "{{$tmp}}"{{end}} 22 | 23 | {{$tmp := .Primary.Attributes.Type}}{{with $tmp}} 24 | type = "{{$tmp}}"{{end}} 25 | 26 | {{$tmp := .Primary.Attributes.Image}}{{with $tmp}} 27 | image = "{{$tmp}}"{{end}} 28 | 29 | {{$tmp := .Primary.Attributes.Zone}}{{with $tmp}} 30 | zone = "{{$tmp}}"{{end}} 31 | 32 | {{$tmp := .Primary.Attributes.Snapshot}}{{with $tmp}} 33 | snapshot = "{{$tmp}}"{{end}} 34 | 35 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 36 | project = "{{$tmp}}"{{end}} 37 | 38 | //add sha256 if you need 39 | {{$tmp := .Primary.Attributes.DiskEncryptionKey}}{{with $tmp}} 40 | {{range $i, $v := $tmp}} 41 | disk_encryption_key { 42 | {{$tmp1 := $v.RawKey}}{{with $tmp1}}raw_key = "{{$tmp1}}"{{end}} 43 | //sha256 44 | {{$tmp2 := $v.KmsKeySelfLink}}{{with $tmp2}}kms_key_self_link = "{{$tmp2}}"{{end}} 45 | }{{end}}{{end}} 46 | {{$tmp := .Primary.Attributes.SourceImageEncryptionKey}}{{with $tmp}} 47 | {{range $i, $v := $tmp}} 48 | source_image_encryption_key { 49 | {{$tmp1 := $v.RawKey}}{{with $tmp1}}raw_key = "{{$tmp1}}"{{end}} 50 | //sha256 51 | {{$tmp2 := $v.KmsKeySelfLink}}{{with $tmp2}}kms_key_self_link = "{{$tmp2}}"{{end}} 52 | }{{end}}{{end}} 53 | 54 | {{$tmp := .Primary.Attributes.SourceSnapshotEncryptionKey}}{{with $tmp}} 55 | {{range $i, $v := $tmp}} 56 | source_snapshot_encryption_key { 57 | {{$tmp1 := $v.RawKey}}{{with $tmp1}}raw_key = "{{$tmp1}}"{{end}} 58 | //sha256 59 | {{$tmp2 := $v.KmsKeySelfLink}}{{with $tmp2}}kms_key_self_link = "{{$tmp2}}"{{end}} 60 | }{{end}}{{end}} 61 | } 62 | -------------------------------------------------------------------------------- /resources/templates/google_compute_firewall.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_firewall" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | network = "{{.Primary.Attributes.Network}}" 8 | //optional 9 | {{range $i, $v := .Primary.Attributes.Allow}}{{$length := len $v.Ports}} 10 | allow { 11 | protocol = "{{$v.Protocol}}" 12 | {{with $v.Ports}}ports = [{{range $ii, $vv := $v.Ports}}{{if lt (plus $ii) $length }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 13 | }{{end}} 14 | {{range $i, $v := .Primary.Attributes.Deny}}{{$length := len $v.Ports}} 15 | deny { 16 | protocol = "{{$v.Protocol}}" 17 | {{with $v.Ports}}ports = [{{range $ii, $vv := $v.Ports}}{{if lt (plus $ii) $length }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 18 | }{{end}} 19 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 20 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 21 | 22 | {{$tmp := .Primary.Attributes.DestinationRanges}} 23 | {{with $tmp}}{{$length := len $tmp}} 24 | destination_ranges = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 25 | 26 | {{$tmp := .Primary.Attributes.Direction}}{{with $tmp}} 27 | direction = "{{$tmp}}"{{end}} 28 | 29 | {{$tmp := .Primary.Attributes.Disabled}}{{with $tmp}} 30 | disabled = "{{$tmp}}"{{end}} 31 | 32 | {{$tmp := .Primary.Attributes.Priority}}{{with $tmp}} 33 | priority = "{{$tmp}}"{{end}} 34 | 35 | {{$tmp := .Primary.Attributes.SourceRanges}} 36 | {{with $tmp}}{{$length := len $tmp}} 37 | source_ranges = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 38 | 39 | {{$tmp := .Primary.Attributes.SourceServiceAccounts}} 40 | {{with $tmp}}{{$length := len $tmp}} 41 | source_service_accounts = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 42 | 43 | {{$tmp := .Primary.Attributes.SourceTags}} 44 | {{with $tmp}}{{$length := len $tmp}} 45 | source_tags = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 46 | 47 | {{$tmp := .Primary.Attributes.TargetTags}} 48 | {{with $tmp}}{{$length := len $tmp}} 49 | target_tags = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 50 | 51 | {{$tmp := .Primary.Attributes.TargetServiceAccounts}} 52 | {{with $tmp}}{{$length := len $tmp}} 53 | target_service_accounts = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 54 | 55 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 56 | project = "{{$tmp}}"{{end}} 57 | 58 | //beta 59 | {{ if eq .Provider "provider.google-beta" }} 60 | {{$tmp := .Primary.Attributes.EnableLogging}}{{with $tmp}} 61 | enable_logging = "{{$tmp}}"{{end}}{{ end }} 62 | } 63 | -------------------------------------------------------------------------------- /resources/templates/google_compute_forwarding_rule.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_forwarding_rule" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | 9 | //optional 10 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 11 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 12 | 13 | {{$tmp := .Primary.Attributes.IPAddress}}{{with $tmp}} 14 | ip_address = "{{$tmp}}"{{end}} 15 | 16 | {{$tmp := .Primary.Attributes.IPProtocol}}{{with $tmp}} 17 | ip_protocol = "{{$tmp}}"{{end}} 18 | 19 | {{$tmp := .Primary.Attributes.BackendService}}{{with $tmp}} 20 | backend_service = "{{$tmp}}"{{end}} 21 | 22 | {{$tmp := .Primary.Attributes.IPVersion}}{{with $tmp}} 23 | ip_version = "{{$tmp}}"{{end}} 24 | 25 | {{$tmp := .Primary.Attributes.LoadBalancingScheme}}{{with $tmp}} 26 | load_balancing_scheme = "{{$tmp}}"{{end}} 27 | 28 | {{$tmp := .Primary.Attributes.Network}}{{with $tmp}} 29 | network = "{{$tmp}}"{{end}} 30 | 31 | {{$tmp := .Primary.Attributes.PortRange}}{{with $tmp}} 32 | port_range = "{{$tmp}}"{{end}} 33 | 34 | {{$tmp := .Primary.Attributes.Ports}} 35 | {{with $tmp}}{{$length := len $tmp}} 36 | ports = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 37 | 38 | {{$tmp := .Primary.Attributes.Subnetwork}}{{with $tmp}} 39 | subnetwork = "{{$tmp}}"{{end}} 40 | 41 | {{$tmp := .Primary.Attributes.Target}}{{with $tmp}} 42 | target = "{{$tmp}}"{{end}} 43 | 44 | {{$tmp := .Primary.Attributes.AllPorts}}{{with $tmp}} 45 | all_ports = "{{$tmp}}"{{end}} 46 | 47 | {{$tmp := .Primary.Attributes.NetworkTier}}{{with $tmp}} 48 | network_tier = "{{$tmp}}"{{end}} 49 | 50 | {{$tmp := .Primary.Attributes.ServiceLabel}}{{with $tmp}} 51 | service_label = "{{$tmp}}"{{end}} 52 | 53 | {{$tmp := .Primary.Attributes.Region}}{{with $tmp}} 54 | region = "{{$tmp}}"{{end}} 55 | 56 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 57 | project = "{{$tmp}}"{{end}} 58 | 59 | //beta 60 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 61 | labels { 62 | {{range $i, $v := $tmp}} 63 | {{$i}} = "{{$v}}"{{end}} 64 | }{{end}} 65 | 66 | } 67 | -------------------------------------------------------------------------------- /resources/templates/google_compute_global_forwarding_rule.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_global_forwarding_rule" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | target = "{{.Primary.Attributes.Target}}" 9 | 10 | //optional 11 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 12 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 13 | 14 | {{$tmp := .Primary.Attributes.IPAddress}}{{with $tmp}} 15 | ip_address = "{{$tmp}}"{{end}} 16 | 17 | {{$tmp := .Primary.Attributes.IPProtocol}}{{with $tmp}} 18 | ip_protocol = "{{$tmp}}"{{end}} 19 | 20 | {{$tmp := .Primary.Attributes.PortRange}}{{with $tmp}} 21 | port_range = "{{$tmp}}"{{end}} 22 | 23 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 24 | project = "{{$tmp}}"{{end}} 25 | 26 | {{$tmp := .Primary.Attributes.IPVersion}}{{with $tmp}} 27 | ip_version = "{{$tmp}}"{{end}} 28 | 29 | //beta 30 | {{ if eq .Provider "provider.google-beta" }} 31 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 32 | labels { 33 | {{range $i, $v := $tmp}} 34 | {{$i}} = "{{$v}}"{{end}} 35 | }{{end}} 36 | {{ end }} 37 | 38 | } 39 | -------------------------------------------------------------------------------- /resources/templates/google_compute_health_check.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_health_check" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | 9 | //optional 10 | {{$tmp := .Primary.Attributes.CheckIntervalSec}}{{with $tmp}} 11 | check_interval_sec = "{{$tmp}}"{{end}} 12 | 13 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 14 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 15 | 16 | {{$tmp := .Primary.Attributes.HealthyThreshold}}{{with $tmp}} 17 | healthy_threshold = "{{$tmp}}"{{end}} 18 | 19 | {{$tmp := .Primary.Attributes.TimeoutSec}}{{with $tmp}} 20 | timeout_sec = "{{$tmp}}"{{end}} 21 | 22 | {{$tmp := .Primary.Attributes.UnhealthyThreshold}}{{with $tmp}} 23 | unhealthy_threshold = "{{$tmp}}"{{end}} 24 | 25 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 26 | project = "{{$tmp}}"{{end}} 27 | 28 | {{$tmp := .Primary.Attributes.HTTPHealthCheck}}{{with $tmp}} 29 | {{range $i, $v := $tmp}} 30 | http_health_check { 31 | {{$tmp := $v.Host}}{{with $tmp}} 32 | host = "{{$tmp}}"{{end}} 33 | {{$tmp := $v.RequestPath}}{{with $tmp}} 34 | request_path = "{{$tmp}}"{{end}} 35 | {{$tmp := $v.Response}}{{with $tmp}} 36 | response = "{{$tmp}}"{{end}} 37 | {{$tmp := $v.Port}}{{with $tmp}} 38 | port = "{{$tmp}}"{{end}} 39 | {{$tmp := $v.ProxyHeader}}{{with $tmp}} 40 | proxy_header = "{{$tmp}}"{{end}} 41 | {{$tmp := $v.Request}}{{with $tmp}} 42 | request = "{{$tmp}}"{{end}} 43 | }{{end}}{{end}} 44 | 45 | {{$tmp := .Primary.Attributes.HTTPSHealthCheck}}{{with $tmp}} 46 | {{range $i, $v := $tmp}} 47 | https_health_check { 48 | {{$tmp := $v.Host}}{{with $tmp}} 49 | host = "{{$tmp}}"{{end}} 50 | {{$tmp := $v.RequestPath}}{{with $tmp}} 51 | request_path = "{{$tmp}}"{{end}} 52 | {{$tmp := $v.Response}}{{with $tmp}} 53 | response = "{{$tmp}}"{{end}} 54 | {{$tmp := $v.Port}}{{with $tmp}} 55 | port = "{{$tmp}}"{{end}} 56 | {{$tmp := $v.ProxyHeader}}{{with $tmp}} 57 | proxy_header = "{{$tmp}}"{{end}} 58 | {{$tmp := $v.Request}}{{with $tmp}} 59 | request = "{{$tmp}}"{{end}} 60 | }{{end}}{{end}} 61 | 62 | {{$tmp := .Primary.Attributes.SslHealthCheck}}{{with $tmp}} 63 | {{range $i, $v := $tmp}} 64 | ssl_health_check { 65 | {{$tmp := $v.Host}}{{with $tmp}} 66 | host = "{{$tmp}}"{{end}} 67 | {{$tmp := $v.RequestPath}}{{with $tmp}} 68 | request_path = "{{$tmp}}"{{end}} 69 | {{$tmp := $v.Response}}{{with $tmp}} 70 | response = "{{$tmp}}"{{end}} 71 | {{$tmp := $v.Port}}{{with $tmp}} 72 | port = "{{$tmp}}"{{end}} 73 | {{$tmp := $v.ProxyHeader}}{{with $tmp}} 74 | proxy_header = "{{$tmp}}"{{end}} 75 | {{$tmp := $v.Request}}{{with $tmp}} 76 | request = "{{$tmp}}"{{end}} 77 | }{{end}}{{end}} 78 | 79 | {{$tmp := .Primary.Attributes.TCPHealthCheck}}{{with $tmp}} 80 | {{range $i, $v := $tmp}} 81 | tcp_health_check { 82 | {{$tmp := $v.Host}}{{with $tmp}} 83 | host = "{{$tmp}}"{{end}} 84 | {{$tmp := $v.RequestPath}}{{with $tmp}} 85 | request_path = "{{$tmp}}"{{end}} 86 | {{$tmp := $v.Response}}{{with $tmp}} 87 | response = "{{$tmp}}"{{end}} 88 | {{$tmp := $v.Port}}{{with $tmp}} 89 | port = "{{$tmp}}"{{end}} 90 | {{$tmp := $v.ProxyHeader}}{{with $tmp}} 91 | proxy_header = "{{$tmp}}"{{end}} 92 | {{$tmp := $v.Request}}{{with $tmp}} 93 | request = "{{$tmp}}"{{end}} 94 | }{{end}}{{end}} 95 | //beta 96 | } 97 | -------------------------------------------------------------------------------- /resources/templates/google_compute_http_health_check.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_http_health_check" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | 9 | //optional 10 | {{$tmp := .Primary.Attributes.CheckIntervalSec}}{{with $tmp}} 11 | check_interval_sec = "{{$tmp}}"{{end}} 12 | 13 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 14 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 15 | 16 | {{$tmp := .Primary.Attributes.HealthyThreshold}}{{with $tmp}} 17 | healthy_threshold = "{{$tmp}}"{{end}} 18 | 19 | {{$tmp := .Primary.Attributes.Host}}{{with $tmp}} 20 | host = "{{$tmp}}"{{end}} 21 | 22 | {{$tmp := .Primary.Attributes.Port}}{{with $tmp}} 23 | port = "{{$tmp}}"{{end}} 24 | 25 | {{$tmp := .Primary.Attributes.RequestPath}}{{with $tmp}} 26 | request_path = "{{$tmp}}"{{end}} 27 | 28 | {{$tmp := .Primary.Attributes.TimeoutSec}}{{with $tmp}} 29 | timeout_sec = "{{$tmp}}"{{end}} 30 | 31 | {{$tmp := .Primary.Attributes.UnhealthyThreshold}}{{with $tmp}} 32 | unhealthy_threshold = "{{$tmp}}"{{end}} 33 | 34 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 35 | project = "{{$tmp}}"{{end}} 36 | 37 | //beta 38 | } 39 | -------------------------------------------------------------------------------- /resources/templates/google_compute_image.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_image" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | //optional 8 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 9 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 10 | 11 | {{$tmp := .Primary.Attributes.DiskSizeGb}}{{with $tmp}} 12 | disk_size_gb = "{{$tmp}}"{{end}} 13 | 14 | {{$tmp := .Primary.Attributes.Family}}{{with $tmp}} 15 | family = "{{$tmp}}"{{end}} 16 | 17 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 18 | labels { 19 | {{range $i, $v := $tmp}} 20 | {{$i}} = "{{$v}}"{{end}} 21 | }{{end}} 22 | 23 | {{$tmp := .Primary.Attributes.Licenses}} 24 | {{with $tmp}}{{$length := len $tmp}} 25 | licenses = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 26 | 27 | {{$tmp := .Primary.Attributes.SourceDisk}}{{with $tmp}} 28 | source_disk = "{{$tmp}}"{{end}} 29 | 30 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 31 | project = "{{$tmp}}"{{end}} 32 | 33 | //raw-disk 34 | } 35 | 36 | -------------------------------------------------------------------------------- /resources/templates/google_compute_instance.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_instance" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | boot_disk{ 7 | {{$tmp := .Primary.Attributes.BootDiskAutoDelete}}{{with $tmp}}auto_delete = "{{$tmp}}"{{end}} 8 | {{$tmp := .Primary.Attributes.BootDiskDeviceName}}{{with $tmp}}device_name = "{{$tmp}}"{{end}} 9 | {{$tmp := .Primary.Attributes.BootDiskDiskEncryptionKeyRaw}}{{with $tmp}}encryption_key_raw = "{{$tmp}}"{{end}} 10 | initialize_params{ 11 | {{$tmp := .Primary.Attributes.BootDiskInitializeParamsImage}}{{with $tmp}}image = "{{$tmp}}"{{end}} 12 | {{$tmp := .Primary.Attributes.BootDiskInitializeParamsSize}}{{with $tmp}}size = "{{$tmp}}"{{end}} 13 | {{$tmp := .Primary.Attributes.BootDiskInitializeParamsType}}{{with $tmp}}type = "{{$tmp}}"{{end}} 14 | } 15 | } 16 | machine_type = "{{.Primary.Attributes.MachineType}}" 17 | {{$tmp := .Primary.Attributes.Name}}{{with $tmp}} 18 | name = "{{$tmp}}"{{end}} 19 | 20 | {{$tmp := .Primary.Attributes.Zone}}{{with $tmp}} 21 | zone = "{{$tmp}}"{{end}} 22 | 23 | {{range $i, $v := .Primary.Attributes.NetworkInterface}} 24 | network_interface { 25 | {{$tmp := $v.Network}}{{with $tmp}}network = "{{$tmp}}"{{end}} 26 | {{$tmp := $v.Subnetwork}}{{with $tmp}}subnetwork = "{{$tmp}}"{{end}} 27 | {{$tmp := $v.SubnetworkProject}}{{with $tmp}}subnetwork_project = "{{$tmp}}"{{end}} 28 | {{$tmp := $v.NetworkIP}}{{with $tmp}}network_ip = "{{$tmp}}"{{end}} 29 | 30 | {{$tmp := $v.AccessConfigNatIP}}{{$tmp1 := $v.AccessConfigNetworkTier}}{{with $tmp}} 31 | {{range $ii, $vv := $tmp}} 32 | access_config{ 33 | nat_ip = "{{$vv}}" 34 | {{range $iii, $vvv := $tmp1}} 35 | {{ if eq $iii $ii }}network_tier = "{{$vvv}}"{{end}} 36 | {{end}} 37 | }{{end}}{{end}} 38 | }{{end}} 39 | 40 | //optional 41 | //allow_stopping_for_update 42 | {{range $i, $v := .Primary.Attributes.AttachedDisk}} 43 | attached_disk { 44 | {{$tmp := $v.DeviceName}}{{with $tmp}}device_name = "{{$tmp}}"{{end}} 45 | {{$tmp := $v.EncryptionKeyRaw}}{{with $tmp}}disk_encryption_key_raw = "{{$tmp}}"{{end}} 46 | {{$tmp := $v.Source}}{{with $tmp}}source = "{{$tmp}}"{{end}} 47 | {{$tmp := $v.Mode}}{{with $tmp}}mode = "{{$tmp}}"{{end}} 48 | }{{end}} 49 | 50 | {{$tmp := .Primary.Attributes.CanIPForward}}{{with $tmp}} 51 | can_ip_forward = "{{$tmp}}"{{end}} 52 | //create_timeout 53 | //description 54 | 55 | {{$tmp := .Primary.Attributes.DeletionProtection}}{{with $tmp}} 56 | deletion_protection = "{{$tmp}}"{{end}} 57 | 58 | {{$tmp := .Primary.Attributes.Hostname}}{{with $tmp}} 59 | hostname = "{{$tmp}}"{{end}} 60 | 61 | {{range $i, $v := .Primary.Attributes.GuestAccelerator}} 62 | guest_accelerator { 63 | {{$tmp := $v.Type}}{{with $tmp}}type = "{{$tmp}}"{{end}} 64 | {{$tmp := $v.Count}}{{with $tmp}}count = "{{$tmp}}"{{end}} 65 | }{{end}} 66 | 67 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 68 | labels { 69 | {{range $i, $v := $tmp}} 70 | {{$i}} = "{{$v}}"{{end}} 71 | }{{end}} 72 | {{$tmp := .Primary.Attributes.Metadata}}{{with $tmp}} 73 | metadata { 74 | //改行は\n手動で変換する 75 | //metadata_startup_script 76 | {{range $i, $v := $tmp}} 77 | {{$i}} = "{{$v}}" 78 | {{end}} 79 | }{{end}} 80 | 81 | {{$tmp := .Primary.Attributes.MetadataStartupScript}}{{with $tmp}} 82 | metadata_startup_script = "{{$tmp}}"{{end}} 83 | 84 | {{$tmp := .Primary.Attributes.MinCPUPlatform}}{{with $tmp}} 85 | min_cpu_platform = "{{$tmp}}"{{end}} 86 | 87 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 88 | project = "{{$tmp}}"{{end}} 89 | 90 | {{range $i, $v := .Primary.Attributes.Scheduling}} 91 | scheduling { 92 | {{$tmp := $v.AutomaticRestart}}{{with $tmp}}automatic_restart = "{{$tmp}}"{{end}} 93 | {{$tmp := $v.OnHostMaintenance}}{{with $tmp}}on_host_maintenance = "{{$tmp}}"{{end}} 94 | {{$tmp := $v.Preemptible}}{{with $tmp}}preemptible = "{{$tmp}}"{{end}} 95 | }{{end}} 96 | 97 | {{range $i, $v := .Primary.Attributes.GuestAccelerator}} 98 | scratch_disk { 99 | {{$tmp := $v.Interface}}{{with $tmp}}interface = "{{$tmp}}"{{end}} 100 | }{{end}} 101 | 102 | {{range $i, $v := .Primary.Attributes.ServiceAccount}}{{$length := len $v.Scopes}} 103 | service_account { 104 | email = "{{$v.Email}}" 105 | {{with $v.Scopes}}scopes = [{{range $ii, $vv := $v.Scopes}}{{if lt (plus $ii) $length }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 106 | }{{end}} 107 | 108 | {{$tmp := .Primary.Attributes.Tags}} 109 | {{with $tmp}}{{$length := len $tmp}} 110 | tags = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 111 | 112 | } 113 | -------------------------------------------------------------------------------- /resources/templates/google_compute_instance_group.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_instance_group" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | zone = "{{.Primary.Attributes.Zone}}" 9 | //optional 10 | //instances 11 | 12 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 13 | project = "{{$tmp}}"{{end}} 14 | 15 | {{$tmp := .Primary.Attributes.Network}}{{with $tmp}} 16 | network = "{{$tmp}}"{{end}} 17 | //named_port 18 | {{$tmp := .Primary.Attributes.NamedPort}}{{with $tmp}} 19 | {{range $i, $v := $tmp}} 20 | named_port { 21 | //required 22 | name = "{{$v.Name}}" 23 | port = "{{$v.Port}}" 24 | }{{end}}{{end}} 25 | //beta 26 | } 27 | -------------------------------------------------------------------------------- /resources/templates/google_compute_instance_group_manager.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_instance_group_manager" "{{convertSlashAndDotToDash .Primary.Attributes.Zone}}-{{convertSlashAndDotToDash .Primary.Attributes.Name}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | base_instance_name = "{{.Primary.Attributes.BaseInstanceName}}" 8 | instance_template = "{{.Primary.Attributes.InstanceTemplate}}" 9 | name = "{{.Primary.Attributes.Name}}" 10 | zone = "{{.Primary.Attributes.Zone}}" 11 | 12 | //optional 13 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 14 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 15 | {{$tmp := .Primary.Attributes.NamedPort}}{{with $tmp}} 16 | {{range $i, $v := $tmp}} 17 | named_port { 18 | //required 19 | name = "{{$v.Name}}" 20 | port = "{{$v.Port}}" 21 | }{{end}}{{end}} 22 | {{$tmp := .Primary.Attributes.TargetSize}}{{with $tmp}} 23 | target_size = "{{$tmp}}"{{end}} 24 | //target_pools 25 | {{$tmp := .Primary.Attributes.TargetPools}} 26 | {{with $tmp}}{{$length := len $tmp}} 27 | target_pools = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 28 | {{$tmp := .Primary.Attributes.WaitForInstances}}{{with $tmp}} 29 | wait_for_instances = "{{$tmp}}"{{end}} 30 | 31 | {{ if eq .Provider "provider.google-beta" }} 32 | //version = "{{.Primary.Attributes.Version}}" 33 | //auto_healing_policies 34 | //update_policy 35 | {{ end }} 36 | 37 | } 38 | -------------------------------------------------------------------------------- /resources/templates/google_compute_instance_template.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_instance_template" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | machine_type = "{{.Primary.Attributes.MachineType}}" 7 | {{range $i, $v := .Primary.Attributes.Disk}} 8 | disk { 9 | {{$tmp := $v.DiskAutoDelete}}{{with $tmp}}auto_delete = "{{$tmp}}"{{end}} 10 | {{$tmp := $v.DiskBoot}}{{with $tmp}}boot = "{{$tmp}}"{{end}} 11 | {{$tmp := $v.DiskDeviceName}}{{with $tmp}}device_name = "{{$tmp}}"{{end}} 12 | {{$tmp := $v.DiskDiskName}}{{with $tmp}}disk_name = "{{$tmp}}"{{end}} 13 | {{$tmp := $v.DiskDiskSizeGb}}{{with $tmp}}disk_size_gb = "{{$tmp}}"{{end}} 14 | {{$tmp := $v.DiskDiskType}}{{with $tmp}}disk_type = "{{$tmp}}"{{end}} 15 | {{$tmp := $v.DiskInterface}}{{with $tmp}}interface = "{{$tmp}}"{{end}} 16 | {{$tmp := $v.DiskMode}}{{with $tmp}}mode = "{{$tmp}}"{{end}} 17 | {{$tmp := $v.DiskSource}}{{with $tmp}}source = "{{$tmp}}"{{end}} 18 | {{$tmp := $v.DiskSourceImage}}{{with $tmp}}source_image = "{{$tmp}}"{{end}} 19 | {{$tmp := $v.DiskType}}{{with $tmp}}type = "{{$tmp}}"{{end}} 20 | {{range $ii, $vv := $v.DiskDiskEncryptionKey}} 21 | disk_encryption_key{ 22 | kms_key_self_link = "{{$vv.KmsKeySelfLink}}" 23 | }{{end}} 24 | }{{end}} 25 | 26 | {{range $i, $v := .Primary.Attributes.NetworkInterface}} 27 | network_interface { 28 | {{$tmp := $v.Network}}{{with $tmp}}network = "{{$tmp}}"{{end}} 29 | {{$tmp := $v.Subnetwork}}{{with $tmp}}subnetwork = "{{$tmp}}"{{end}} 30 | {{$tmp := $v.SubnetworkProject}}{{with $tmp}}subnetwork_project = "{{$tmp}}"{{end}} 31 | {{$tmp := $v.NetworkIP}}{{with $tmp}}network_ip = "{{$tmp}}"{{end}} 32 | 33 | {{$tmp := $v.AccessConfigNatIP}}{{$tmp1 := $v.AccessConfigNetworkTier}}{{with $tmp}} 34 | {{range $ii, $vv := $tmp}} 35 | access_config{ 36 | nat_ip = "{{$vv}}" 37 | {{range $iii, $vvv := $tmp1}} 38 | {{ if eq $iii $ii }}network_tier = "{{$vvv}}"{{end}} 39 | {{end}} 40 | }{{end}}{{end}} 41 | }{{end}} 42 | 43 | //optional 44 | {{$tmp := .Primary.Attributes.Name}}{{with $tmp}} 45 | name = "{{$tmp}}"{{end}} 46 | //name_prefix 47 | 48 | {{$tmp := .Primary.Attributes.CanIPForward}}{{with $tmp}} 49 | can_ip_forward = "{{$tmp}}"{{end}} 50 | 51 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 52 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 53 | 54 | {{$tmp := .Primary.Attributes.InstanceDescription}}{{with $tmp}} 55 | instance_description = "{{escapeDoubleQuote $tmp}}"{{end}} 56 | 57 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 58 | labels { 59 | {{range $i, $v := $tmp}} 60 | {{$i}} = "{{$v}}"{{end}} 61 | }{{end}} 62 | {{$tmp := .Primary.Attributes.Metadata}}{{with $tmp}} 63 | metadata { 64 | //改行は\n手動で変換する 65 | //metadata_startup_script 66 | {{range $i, $v := $tmp}} 67 | {{$i}} = "{{$v}}" 68 | {{end}} 69 | }{{end}} 70 | 71 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 72 | project = "{{$tmp}}"{{end}} 73 | 74 | //region 75 | {{range $i, $v := .Primary.Attributes.Scheduling}} 76 | scheduling { 77 | {{$tmp := $v.AutomaticRestart}}{{with $tmp}}automatic_restart = "{{$tmp}}"{{end}} 78 | {{$tmp := $v.OnHostMaintenance}}{{with $tmp}}on_host_maintenance = "{{$tmp}}"{{end}} 79 | {{$tmp := $v.Preemptible}}{{with $tmp}}preemptible = "{{$tmp}}"{{end}} 80 | }{{end}} 81 | 82 | {{range $i, $v := .Primary.Attributes.ServiceAccount}}{{$length := len $v.Scopes}} 83 | service_account { 84 | email = "{{$v.Email}}" 85 | {{with $v.Scopes}}scopes = [{{range $ii, $vv := $v.Scopes}}{{if lt (plus $ii) $length }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 86 | }{{end}} 87 | 88 | {{$tmp := .Primary.Attributes.Tags}} 89 | {{with $tmp}}{{$length := len $tmp}} 90 | tags = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 91 | 92 | //guest_accelerator 93 | {{$tmp := .Primary.Attributes.MinCPUPlatform}}{{with $tmp}} 94 | min_cpu_platform = "{{$tmp}}"{{end}} 95 | 96 | } 97 | -------------------------------------------------------------------------------- /resources/templates/google_compute_network.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_network" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | 9 | //optional 10 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 11 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 12 | 13 | {{$tmp := .Primary.Attributes.Ipv4Range}}{{with $tmp}} 14 | ipv4_range = "{{$tmp}}"{{end}} 15 | 16 | {{$tmp := .Primary.Attributes.AutoCreateSubnetworks}}{{with $tmp}} 17 | auto_create_subnetworks = "{{$tmp}}"{{end}} 18 | 19 | {{$tmp := .Primary.Attributes.RoutingMode}}{{with $tmp}} 20 | routing_mode = "{{$tmp}}"{{end}} 21 | 22 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 23 | project = "{{$tmp}}"{{end}} 24 | 25 | {{$tmp := .Primary.Attributes.DeleteDefaultRoutesOnCreate}}{{with $tmp}} 26 | delete_default_routes_on_create = "{{$tmp}}"{{end}} 27 | 28 | //beta 29 | } 30 | -------------------------------------------------------------------------------- /resources/templates/google_compute_route.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_route" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | dest_range = "{{.Primary.Attributes.DestRange}}" 8 | network = "{{.Primary.Attributes.Network}}" 9 | //optional 10 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 11 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 12 | 13 | {{$tmp := .Primary.Attributes.Priority}}{{with $tmp}} 14 | priority = "{{$tmp}}"{{end}} 15 | 16 | {{$tmp := .Primary.Attributes.Tags}} 17 | {{with $tmp}}{{$length := len $tmp}} 18 | tags = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 19 | 20 | {{$tmp := .Primary.Attributes.NextHopGateway}}{{with $tmp}} 21 | next_hop_gateway = "{{$tmp}}"{{end}} 22 | 23 | {{$tmp := .Primary.Attributes.NextHopInstance}}{{with $tmp}} 24 | next_hop_instance = "{{$tmp}}"{{end}} 25 | 26 | {{$tmp := .Primary.Attributes.NextHopIP}}{{with $tmp}} 27 | next_hop_ip = "{{$tmp}}"{{end}} 28 | 29 | {{$tmp := .Primary.Attributes.NextHopVpnTunnel}}{{with $tmp}} 30 | next_hop_vpn_tunnel = "{{$tmp}}"{{end}} 31 | 32 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 33 | project = "{{$tmp}}"{{end}} 34 | 35 | //beta 36 | {{$tmp := .Primary.Attributes.EnableLogging}}{{with $tmp}} 37 | enable_logging = "{{$tmp}}"{{end}} 38 | } 39 | -------------------------------------------------------------------------------- /resources/templates/google_compute_snapshot.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_snapshot" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | source_disk = "{{.Primary.Attributes.SourceDisk}}" 8 | //optional 9 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 10 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 11 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 12 | labels { 13 | {{range $i, $v := $tmp}} 14 | {{$i}} = "{{$v}}"{{end}} 15 | }{{end}} 16 | //zone = 17 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 18 | project = "{{$tmp}}"{{end}} 19 | 20 | //disk_encryption_key { 21 | //raw_key = 22 | //} 23 | {{$tmp := .Primary.Attributes.SnapshotEncryptionKey}}{{with $tmp}} 24 | {{range $i, $v := $tmp}} 25 | //source_snapshot_encryption_key { 26 | //raw_key = "{{$v.RawKey }}" 27 | //sha256 = "{{$v.Sha256 }}" 28 | //}{{end}}{{end}} 29 | } 30 | -------------------------------------------------------------------------------- /resources/templates/google_compute_ssl_certificate.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_ssl_certificate" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //You cannot get private_key 3 | 4 | //provider 5 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 6 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 7 | 8 | //required 9 | certificate = "{{.Primary.Attributes.Certificate}}" 10 | //cannot get private key from tfstate.Please set if you need. 11 | //private_key = "" 12 | 13 | //optional 14 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 15 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 16 | 17 | {{$tmp := .Primary.Attributes.Name}}{{with $tmp}} 18 | name = "{{$tmp}}"{{end}} 19 | //name_prefix Conflicts with name. 20 | 21 | //beta 22 | } 23 | -------------------------------------------------------------------------------- /resources/templates/google_compute_subnetwork.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_subnetwork" "{{convertSlashAndDotToDash .Primary.Attributes.Name}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | 6 | //required 7 | ip_cidr_range = "{{.Primary.Attributes.IPCidrRange}}" 8 | name = "{{.Primary.Attributes.Name}}" 9 | network = "{{.Primary.Attributes.Network}}" 10 | 11 | //optional 12 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 13 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 14 | 15 | {{$tmp := .Primary.Attributes.EnableFlowLogs}}{{with $tmp}} 16 | enable_flow_logs = "{{$tmp}}"{{end}} 17 | 18 | {{$tmp := .Primary.Attributes.PrivateIPGoogleAccess}}{{with $tmp}} 19 | private_ip_google_access = "{{$tmp}}"{{end}} 20 | 21 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 22 | project = "{{$tmp}}"{{end}} 23 | 24 | {{$tmp := .Primary.Attributes.Region}}{{with $tmp}} 25 | region = "{{$tmp}}"{{end}} 26 | 27 | {{range $i, $v := .Primary.Attributes.SecondaryIPRange}} 28 | secondary_ip_range { 29 | range_name = "{{$v.Range_name }}" 30 | ip_cidr_range = "{{$v.Ip_cidr_range }}" 31 | }{{end}} 32 | 33 | //beta 34 | } 35 | -------------------------------------------------------------------------------- /resources/templates/google_compute_target_http_proxy.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_target_http_proxy" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | url_map = "{{.Primary.Attributes.URLMap}}" 9 | 10 | //optional 11 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 12 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 13 | 14 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 15 | project = "{{$tmp}}"{{end}} 16 | //beta 17 | } 18 | -------------------------------------------------------------------------------- /resources/templates/google_compute_target_https_proxy.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_target_https_proxy" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | url_map = "{{.Primary.Attributes.URLMap}}" 9 | 10 | {{$tmp := .Primary.Attributes.SslCertificates}} 11 | {{with $tmp}}{{$length := len $tmp}} 12 | ssl_certificates = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 13 | 14 | //optional 15 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 16 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 17 | 18 | {{$tmp := .Primary.Attributes.QuicOverride}}{{with $tmp}} 19 | quic_override = "{{$tmp}}"{{end}} 20 | 21 | {{$tmp := .Primary.Attributes.SslPolicy}}{{with $tmp}} 22 | ssl_policy = "{{$tmp}}"{{end}} 23 | 24 | 25 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 26 | project = "{{$tmp}}"{{end}} 27 | //beta 28 | } 29 | -------------------------------------------------------------------------------- /resources/templates/google_compute_target_pool.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_target_pool" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | 8 | //optional 9 | {{$tmp := .Primary.Attributes.BackupPool}}{{with $tmp}} 10 | backup_pool = "{{$tmp}}"{{end}} 11 | 12 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 13 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 14 | 15 | {{$tmp := .Primary.Attributes.FailoverRatio}}{{with $tmp}} 16 | failover_ratio = "{{$tmp}}"{{end}} 17 | 18 | {{$tmp := .Primary.Attributes.HealthChecks}} 19 | {{with $tmp}}{{$length := len $tmp}} 20 | health_checks = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 21 | 22 | {{$tmp := .Primary.Attributes.Instances}} 23 | {{with $tmp}}{{$length := len $tmp}} 24 | instances = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 25 | 26 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 27 | project = "{{$tmp}}"{{end}} 28 | 29 | {{$tmp := .Primary.Attributes.Region}}{{with $tmp}} 30 | region = "{{$tmp}}"{{end}} 31 | 32 | {{$tmp := .Primary.Attributes.SessionAffinity}}{{with $tmp}} 33 | session_affinity = "{{$tmp}}"{{end}} 34 | 35 | //beta 36 | } 37 | -------------------------------------------------------------------------------- /resources/templates/google_compute_url_map.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_compute_url_map" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | default_service = "{{.Primary.Attributes.DefaultService}}" 8 | //optional 9 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 10 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 11 | 12 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 13 | project = "{{$tmp}}"{{end}} 14 | 15 | //host_rule 16 | {{range $i, $v := .Primary.Attributes.HostRule}}{{$length := len $v.Hosts}} 17 | host_rule { 18 | {{$tmp := $v.Description}}{{with $tmp}}description = "{{$tmp}}" {{end}} 19 | {{with $v.Hosts}}hosts = [{{range $ii, $vv := $v.Hosts}}{{if lt (plus $ii) $length }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 20 | {{$tmp := $v.PathMatcher}}{{with $tmp}}path_matcher = "{{$tmp}}" {{end}} 21 | }{{end}} 22 | 23 | //path_,atch 24 | {{range $i, $v := .Primary.Attributes.PathMatcher}} 25 | path_matcher { 26 | {{$tmp := $v.DefaultService}}{{with $tmp}}default_service = "{{$tmp}}"{{end}} 27 | {{$tmp := $v.Description}}{{with $tmp}}description = "{{escapeDoubleQuote $tmp}}"{{end}} 28 | {{$tmp := $v.Name}}{{with $tmp}}name = "{{$tmp}}"{{end}} 29 | 30 | {{$tmp := $v.PathRule}}{{with $tmp}} 31 | {{range $ii, $vv := $tmp}} 32 | path_rule{ 33 | service = "{{$vv.Service}}" 34 | paths = [{{range $iii, $vvv := $vv.Paths}}{{$length := len $vv.Paths}}{{if lt (plus $iii) $length}}"{{$vvv}}",{{else}}"{{$vvv}}"{{ end }}{{ end }}] 35 | }{{end}}{{end}} 36 | }{{end}} 37 | 38 | //test 39 | {{range $i, $v := .Primary.Attributes.Test}} 40 | test { 41 | {{$tmp := $v.Description}}{{with $tmp}}description = "{{$tmp}}" {{end}} 42 | {{$tmp := $v.Host}}{{with $tmp}}host = "{{$tmp}}" {{end}} 43 | {{$tmp := $v.Path}}{{with $tmp}}path = "{{$tmp}}" {{end}} 44 | {{$tmp := $v.Service}}{{with $tmp}}service = "{{$tmp}}" {{end}} 45 | }{{end}} 46 | 47 | 48 | 49 | //beta 50 | {{ if eq .Provider "provider.google-beta" }} 51 | {{ end }} 52 | } 53 | -------------------------------------------------------------------------------- /resources/templates/google_container_cluster.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_container_cluster" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | 9 | //optional 10 | {{$tmp := .Primary.Attributes.Location}}{{with $tmp}} 11 | location = "{{$tmp}}"{{end}} 12 | 13 | {{$tmp := .Primary.Attributes.Zone}}{{with $tmp}} 14 | //deprecated 15 | //zone = "{{$tmp}}"{{end}} 16 | 17 | {{$tmp := .Primary.Attributes.Region}}{{with $tmp}} 18 | //deprecated 19 | //region = "{{$tmp}}"{{end}} 20 | 21 | {{$tmp := .Primary.Attributes.AdditionalZones}} 22 | {{with $tmp}}{{$length := len $tmp}} 23 | //deprecated 24 | //additional_zones = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 25 | 26 | {{$tmp := .Primary.Attributes.NodeLocations}} 27 | {{with $tmp}}{{$length := len $tmp}} 28 | node_locations = [{{range $i, $v := $tmp}}{{if lt (plus $i) $length }}"{{$v}}",{{else}}"{{$v}}"{{ end }}{{ end }}]{{end}} 29 | 30 | {{range $i, $v := .Primary.Attributes.AddonsConfig}} 31 | addons_config { 32 | {{$tmp := $v.HorizontalPodAutoscaling}}{{with $tmp}} 33 | {{range $ii, $vv := $tmp}} 34 | horizontal_pod_autoscaling { 35 | {{$tmp1 := $vv.Disabled}}{{with $tmp1}}disabled = "{{$tmp1}}"{{end}} 36 | }{{end}}{{end}} 37 | 38 | {{$tmp := $v.HTTPLoadBalancing}}{{with $tmp}} 39 | {{range $ii, $vv := $tmp}} 40 | http_load_balancing { 41 | {{$tmp1 := $vv.Disabled}}{{with $tmp1}}disabled = "{{$tmp1}}"{{end}} 42 | }{{end}}{{end}} 43 | 44 | {{$tmp := $v.KubernetesDashboard}}{{with $tmp}} 45 | {{range $ii, $vv := $tmp}} 46 | kubernetes_dashboard { 47 | {{$tmp1 := $vv.Disabled}}{{with $tmp1}}disabled = "{{$tmp1}}"{{end}} 48 | }{{end}}{{end}} 49 | 50 | {{$tmp := $v.NetworkPolicyConfig}}{{with $tmp}} 51 | {{range $ii, $vv := $tmp}} 52 | network_policy_config { 53 | {{$tmp1 := $vv.Disabled}}{{with $tmp1}}disabled = "{{$tmp1}}"{{end}} 54 | }{{end}}{{end}} 55 | 56 | //istio_config 57 | //cloudrun_config 58 | 59 | }{{end}} 60 | 61 | {{range $i, $v := .Primary.Attributes.ClusterAutoscaling}} 62 | cluster_autoscaling { 63 | {{$tmp := $v.Enabled}}{{with $tmp}}enabled = "{{$tmp}}"{{end}} 64 | 65 | {{$tmp := $v.ResourceLimits}}{{with $tmp}} 66 | {{range $ii, $vv := $tmp}} 67 | resource_limits { 68 | {{$tmp1 := $vv.ResourceType}}{{with $tmp1}}resource_type = "{{$tmp1}}"{{end}} 69 | {{$tmp1 := $vv.Minimum}}{{with $tmp1}}minimum = "{{$tmp1}}"{{end}} 70 | {{$tmp1 := $vv.Maximum}}{{with $tmp1}}maximum = "{{$tmp1}}"{{end}} 71 | }{{end}}{{end}} 72 | }{{end}} 73 | 74 | //database_encryption 75 | 76 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 77 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 78 | 79 | //default_max_pods_per_node 80 | //enable_binary_authorization 81 | 82 | {{$tmp := .Primary.Attributes.EnableKubernetesAlpha}}{{with $tmp}} 83 | enable_kubernetes_alpha = "{{$tmp}}"{{end}} 84 | 85 | //enable_tpu 86 | 87 | {{$tmp := .Primary.Attributes.EnableLegacyAbac}}{{with $tmp}} 88 | enable_legacy_abac = "{{$tmp}}"{{end}} 89 | 90 | {{$tmp := .Primary.Attributes.InitialNodeCount}}{{with $tmp}} 91 | initial_node_count = "{{$tmp}}"{{end}} 92 | 93 | {{range $i, $v := .Primary.Attributes.IPAllocationPolicy}} 94 | ip_allocation_policy { 95 | {{$tmp := $v.UseIPAliases}}{{with $tmp}}use_ip_aliases = "{{$tmp}}"{{end}} 96 | {{$tmp := $v.ClusterSecondaryRangeName}}{{with $tmp}}//cluster_secondary_range_name = "{{$tmp}}"{{end}} 97 | {{$tmp := $v.ServicesSecondaryRangeName}}{{with $tmp}}//services_secondary_range_name = "{{$tmp}}"{{end}} 98 | {{$tmp := $v.ClusterIpv4CidrBlock}}{{with $tmp}}cluster_ipv4_cidr_block = "{{$tmp}}"{{end}} 99 | {{$tmp := $v.NodeIpv4CidrBlock}}{{with $tmp}}node_ipv4_cidr_block = "{{$tmp}}"{{end}} 100 | {{$tmp := $v.ServicesIpv4CidrBlock}}{{with $tmp}}services_ipv4_cidr_block = "{{$tmp}}"{{end}} 101 | {{$tmp := $v.CreateSubnetwork}}{{with $tmp}}create_subnetwork = "{{$tmp}}"{{end}} 102 | {{$tmp := $v.SubnetworkName}}{{with $tmp}}subnetwork_name = "{{$tmp}}"{{end}} 103 | }{{end}} 104 | 105 | {{$tmp := .Primary.Attributes.LoggingService}}{{with $tmp}} 106 | logging_service = "{{$tmp}}"{{end}} 107 | 108 | {{range $i, $v := .Primary.Attributes.MaintenancePolicy}} 109 | maintenance_policy { 110 | 111 | {{$tmp := $v.DailyMaintenanceWindow}}{{with $tmp}} 112 | {{range $ii, $vv := $tmp}} 113 | daily_maintenance_window { 114 | {{$tmp1 := $vv.StartTime}}{{with $tmp1}}start_time = "{{$tmp1}}"{{end}} 115 | }{{end}}{{end}} 116 | }{{end}} 117 | 118 | {{range $i, $v := .Primary.Attributes.MasterAuth}} 119 | master_auth { 120 | {{$tmp := $v.Password}}{{with $tmp}}password = "{{$tmp}}"{{end}} 121 | {{$tmp := $v.Username}}{{with $tmp}}username = "{{$tmp}}"{{end}} 122 | 123 | {{$tmp := $v.ClientCertificateConfig}}{{with $tmp}} 124 | {{range $ii, $vv := $tmp}} 125 | client_certificate_config { 126 | }{{end}}{{end}} 127 | }{{end}} 128 | 129 | {{range $i, $v := .Primary.Attributes.MasterAuthorizedNetworksConfig}} 130 | master_authorized_networks_config { 131 | {{$tmp := $v.CidrBlocks}}{{with $tmp}} 132 | {{range $ii, $vv := $tmp}} 133 | cidr_blocks { 134 | {{$tmp1 := $vv.CidrBlock}}{{with $tmp1}}cidr_block = "{{$tmp1}}"{{end}} 135 | {{$tmp1 := $vv.DisplayName}}{{with $tmp1}}display_name = "{{$tmp1}}"{{end}} 136 | }{{end}}{{end}} 137 | }{{end}} 138 | 139 | //min_master_version 140 | 141 | {{$tmp := .Primary.Attributes.MonitoringService}}{{with $tmp}} 142 | monitoring_service = "{{$tmp}}"{{end}} 143 | 144 | {{$tmp := .Primary.Attributes.Network}}{{with $tmp}} 145 | network = "{{$tmp}}"{{end}} 146 | 147 | {{range $i, $v := .Primary.Attributes.NetworkPolicy}} 148 | network_policy { 149 | {{$tmp := $v.Enabled}}{{with $tmp}}enabled = "{{$tmp}}"{{end}} 150 | {{$tmp := $v.Provider}}{{with $tmp}}provider = "{{$tmp}}"{{end}} 151 | }{{end}} 152 | 153 | {{range $i, $v := .Primary.Attributes.NodeConfig}} 154 | node_config { 155 | {{$tmp := $v.DiskSizeGb}}{{with $tmp}}disk_size_gb = "{{$tmp}}"{{end}} 156 | {{$tmp := $v.DiskType}}{{with $tmp}}disk_type = "{{$tmp}}"{{end}} 157 | 158 | {{$tmp := $v.GuestAccelerator}}{{with $tmp}} 159 | {{range $ii, $vv := $tmp}} 160 | guest_accelerator { 161 | {{$tmp1 := $vv.Type}}{{with $tmp1}}type = "{{$tmp1}}"{{end}} 162 | {{$tmp1 := $vv.Count}}{{with $tmp1}}count = "{{$tmp1}}"{{end}} 163 | }{{end}}{{end}} 164 | 165 | {{$tmp := $v.ImageType}}{{with $tmp}}image_type = "{{$tmp}}"{{end}} 166 | 167 | {{$tmp := $v.Labels}}{{with $tmp}} 168 | labels { 169 | {{range $ii, $vv := $tmp}} 170 | {{$ii}} = "{{$vv}}"{{end}} 171 | }{{end}} 172 | 173 | //local_ssd_count 174 | {{$tmp := $v.MachineType}}{{with $tmp}}machine_type = "{{$tmp}}"{{end}} 175 | 176 | {{$tmp := $v.Metadata}}{{with $tmp}} 177 | metadata { 178 | {{range $ii, $vv := $tmp}} 179 | {{$ii}} = "{{$vv}}"{{end}} 180 | }{{end}} 181 | 182 | //min_cpu_platform 183 | 184 | {{$length := len $v.OauthScopes}} 185 | {{with $v.OauthScopes}}oauth_scopes = [{{range $ii, $vv := $v.OauthScopes}}{{if lt (plus $ii) $length }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 186 | 187 | {{$tmp := $v.Preemptible}}{{with $tmp}}preemptible = "{{$tmp}}"{{end}} 188 | {{$tmp := $v.ServiceAccount}}{{with $tmp}}service_account = "{{$tmp}}"{{end}} 189 | 190 | {{$length := len $v.OauthScopes}} 191 | {{with $v.Tags}}tags = [{{range $ii, $vv := $v.Tags}}{{if lt (plus $ii) $length }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 192 | 193 | {{$tmp := $v.Taint}}{{with $tmp}} 194 | {{range $ii, $vv := $tmp}} 195 | taint { 196 | {{$tmp1 := $vv.Key}}{{with $tmp1}}key = "{{$tmp1}}"{{end}} 197 | {{$tmp1 := $vv.Value}}{{with $tmp1}}value = "{{$tmp1}}"{{end}} 198 | {{$tmp1 := $vv.Effect}}{{with $tmp1}}effect = "{{$tmp1}}"{{end}} 199 | }{{end}}{{end}} 200 | 201 | {{$tmp := $v.WorkloadMetadataConfig}}{{with $tmp}}workload_metadata_config = "{{$tmp}}"{{end}} 202 | 203 | }{{end}} 204 | 205 | //Warning: node pools defined inside a cluster can't be changed (or added/removed) after cluster creation without deleting and recreating the entire cluster. 206 | //node_pool 207 | 208 | {{$tmp := .Primary.Attributes.NodeVersion}}{{with $tmp}} 209 | node_version = "{{$tmp}}"{{end}} 210 | 211 | //pod_security_policy_config 212 | 213 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 214 | project = "{{$tmp}}"{{end}} 215 | 216 | {{range $i, $v := .Primary.Attributes.PrivateClusterConfig}} 217 | private_cluster_config { 218 | {{$tmp := $v.EnablePrivateEndpoint}}{{with $tmp}}enable_private_endpoint = "{{$tmp}}"{{end}} 219 | {{$tmp := $v.EnablePrivateNodes}}{{with $tmp}}enable_private_nodes = "{{$tmp}}"{{end}} 220 | {{$tmp := $v.MasterIpv4CidrBlock}}{{with $tmp}}master_ipv4_cidr_block = "{{$tmp}}"{{end}} 221 | }{{end}} 222 | 223 | //remove_default_node_pool 224 | 225 | {{$tmp := .Primary.Attributes.ResourceLabels}}{{with $tmp}} 226 | resource_labels { 227 | {{range $i, $v := $tmp}} 228 | {{$i}} = "{{$v}}"{{end}} 229 | }{{end}} 230 | 231 | {{$tmp := .Primary.Attributes.Subnetwork}}{{with $tmp}} 232 | subnetwork = "{{$tmp}}"{{end}} 233 | 234 | } 235 | -------------------------------------------------------------------------------- /resources/templates/google_dns_managed_zone.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_dns_managed_zone" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | dns_name = "{{.Primary.Attributes.DNSName}}" 9 | 10 | //optional 11 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 12 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 13 | 14 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 15 | labels { 16 | {{range $i, $v := $tmp}} 17 | {{$i}} = "{{$v}}"{{end}} 18 | }{{end}} 19 | 20 | {{$tmp := .Primary.Attributes.Visibility}}{{with $tmp}} 21 | visibility = "{{$tmp}}"{{end}} 22 | 23 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 24 | project = "{{$tmp}}"{{end}} 25 | 26 | {{range $i, $v := .Primary.Attributes.PrivateVisibilityConfig}} 27 | private_visibility_config { 28 | {{$tmp := $v.Networks}}{{with $tmp}} 29 | {{range $ii, $vv := $tmp}} 30 | networks { 31 | {{$tmp1 := $vv.NetworkURL}}{{with $tmp1}}network_url = "{{$tmp1}}"{{end}} 32 | }{{end}}{{end}} 33 | }{{end}} 34 | 35 | {{range $i, $v := .Primary.Attributes.ForwardingConfig}} 36 | forwarding_config { 37 | {{$tmp := $v.TargetNameServers}}{{with $tmp}} 38 | {{range $ii, $vv := $tmp}} 39 | target_name_servers { 40 | {{$tmp1 := $vv.IPv4Address}}{{with $tmp1}}ipv4_address = "{{$tmp1}}"{{end}} 41 | }{{end}}{{end}} 42 | }{{end}} 43 | 44 | {{range $i, $v := .Primary.Attributes.PrivateVisibilityConfig}} 45 | private_visibility_config { 46 | {{$tmp := $v.Networks}}{{with $tmp}} 47 | {{range $ii, $vv := $tmp}} 48 | networks { 49 | {{$tmp1 := $vv.NetworkURL}}{{with $tmp1}}network_url = "{{$tmp1}}"{{end}} 50 | }{{end}}{{end}} 51 | }{{end}} 52 | 53 | {{range $i, $v := .Primary.Attributes.PeeringConfig}} 54 | peering_config { 55 | {{$tmp := $v.TargetNetwork}}{{with $tmp}} 56 | {{range $ii, $vv := $tmp}} 57 | target_network { 58 | {{$tmp1 := $vv.NetworkURL}}{{with $tmp1}}network_url = "{{$tmp1}}"{{end}} 59 | }{{end}}{{end}} 60 | }{{end}} 61 | } 62 | -------------------------------------------------------------------------------- /resources/templates/google_dns_policy.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_dns_policy" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | 9 | //optional 10 | {{$tmp := .Primary.Attributes.Description}}{{with $tmp}} 11 | description = "{{escapeDoubleQuote $tmp}}"{{end}} 12 | 13 | {{$tmp := .Primary.Attributes.EnableInboundForwarding}}{{with $tmp}} 14 | enable_inbound_forwarding = "{{$tmp}}"{{end}} 15 | 16 | {{$tmp := .Primary.Attributes.EnableLogging}}{{with $tmp}} 17 | enable_logging = "{{$tmp}}"{{end}} 18 | 19 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 20 | project = "{{$tmp}}"{{end}} 21 | 22 | {{range $i, $v := .Primary.Attributes.AlternativeNameServerConfig}} 23 | alternative_name_server_config { 24 | {{$tmp := $v.TargetNameServers}}{{with $tmp}} 25 | {{range $ii, $vv := $tmp}} 26 | target_name_servers { 27 | {{$tmp1 := $vv}}{{with $tmp1}}ipv4_address = "{{$tmp1}}"{{end}} 28 | }{{end}}{{end}} 29 | }{{end}} 30 | 31 | {{range $i, $v := .Primary.Attributes.Networks}} 32 | networks { 33 | {{$tmp := $v.NetworkURL}}{{with $tmp}}network_url = "{{$tmp}}"{{end}} 34 | }{{end}} 35 | 36 | } 37 | -------------------------------------------------------------------------------- /resources/templates/google_kms_crypto_key.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_kms_crypto_key" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //required 3 | name = "{{.Primary.Attributes.Name}}" 4 | key_ring = "{{.Primary.Attributes.KeyRing}}" 5 | 6 | //optional 7 | {{$tmp := .Primary.Attributes.RotationPeriod}}{{with $tmp}} 8 | rotation_period = "{{$tmp}}"{{end}} 9 | 10 | {{range $i, $v := .Primary.Attributes.VersionTemplate}} 11 | version_template { 12 | {{$tmp := $v.Algorithm}}{{with $tmp}}algorithm = "{{$tmp}}" {{end}} 13 | {{$tmp := $v.ProtectionLevel}}{{with $tmp}}protection_level = "{{$tmp}}" {{end}} 14 | }{{end}} 15 | } 16 | -------------------------------------------------------------------------------- /resources/templates/google_kms_key_ring.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_kms_key_ring" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //required 3 | name = "{{.Primary.Attributes.Name}}" 4 | location = "{{.Primary.Attributes.Location}}" 5 | 6 | //optional 7 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 8 | project = "{{$tmp}}"{{end}} 9 | } 10 | -------------------------------------------------------------------------------- /resources/templates/google_project.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_project" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //required 3 | name = "{{.Primary.Attributes.Name}}" 4 | project_id = "{{.Primary.Attributes.ProjectID}}" 5 | //optional 6 | {{$tmp := .Primary.Attributes.OrgID}}{{with $tmp}} 7 | org_id = "{{$tmp}}"{{end}} 8 | 9 | {{$tmp := .Primary.Attributes.FolderID}}{{with $tmp}} 10 | folder_id = "{{$tmp}}"{{end}} 11 | 12 | {{$tmp := .Primary.Attributes.BillingAccount}}{{with $tmp}} 13 | billing_account = "{{$tmp}}"{{end}} 14 | 15 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 16 | labels { 17 | {{range $i, $v := $tmp}} 18 | {{$i}} = "{{$v}}"{{end}} 19 | }{{end}} 20 | 21 | //please set if you need 22 | //skip delete = 23 | //auto_create_network = 24 | } 25 | -------------------------------------------------------------------------------- /resources/templates/google_pubsub_subscription.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_pubsub_subscription" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | topic = "{{.Primary.Attributes.Topic}}" 9 | 10 | //optional 11 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 12 | labels { 13 | {{range $i, $v := $tmp}} 14 | {{$i}} = "{{$v}}"{{end}} 15 | }{{end}} 16 | 17 | {{$tmp := .Primary.Attributes.AckDeadlineSeconds}}{{with $tmp}} 18 | ack_deadline_seconds = "{{$tmp}}"{{end}} 19 | 20 | {{$tmp := .Primary.Attributes.MessageRetentionDuration}}{{with $tmp}} 21 | message_retention_duration = "{{$tmp}}"{{end}} 22 | 23 | {{$tmp := .Primary.Attributes.RetainAckedMessages}}{{with $tmp}} 24 | retain_acked_messages = "{{$tmp}}"{{end}} 25 | 26 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 27 | project = "{{$tmp}}"{{end}} 28 | 29 | {{range $i, $v := .Primary.Attributes.PushConfig}} 30 | push_config { 31 | push_endpoint = "{{$v.PushEndpoint}}" 32 | attributes = "{{$v.Attributes}}" 33 | }{{end}} 34 | 35 | //beta 36 | } 37 | -------------------------------------------------------------------------------- /resources/templates/google_pubsub_topic.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_pubsub_topic" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google" {{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta" {{ end }} 5 | 6 | //required 7 | name = "{{.Primary.Attributes.Name}}" 8 | 9 | //optional 10 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 11 | project = "{{$tmp}}"{{end}} 12 | 13 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 14 | labels { 15 | {{range $i, $v := $tmp}} 16 | {{$i}} = "{{$v}}"{{end}} 17 | }{{end}} 18 | } 19 | -------------------------------------------------------------------------------- /resources/templates/google_service_account.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource google_service_account "{{convertSlashAndDotToDash .Primary.ID | removeAtmark }}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | account_id = "{{.Primary.Attributes.AccountID}}" 7 | display_name = "{{.Primary.Attributes.DisplayName}}" 8 | //optional 9 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 10 | project = "{{$tmp}}"{{end}} 11 | 12 | //beta 13 | } 14 | -------------------------------------------------------------------------------- /resources/templates/google_sql_database_instance.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_sql_database_instance" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | 6 | //required 7 | region = "{{.Primary.Attributes.Region}}" 8 | 9 | {{range $i, $v := .Primary.Attributes.Settings}} 10 | settings { 11 | {{$tmp := $v.Tier}}{{with $tmp}}tier = "{{$tmp}}"{{end}} 12 | {{$tmp := $v.ActivationPolicy}}{{with $tmp}}activation_policy = "{{$tmp}}"{{end}} 13 | {{$length := len $v.AuthorizedGaeApplications}}{{with $v.AuthorizedGaeApplications}}authorized_gae_applications = [{{range $ii, $vv := $v.AuthorizedGaeApplications}}{{if lt (plus $ii) $length }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 14 | {{$tmp := $v.AvailabilityType}}{{with $tmp}}availability_type = "{{$tmp}}"{{end}} 15 | {{$tmp := $v.CrashSafeReplication}}{{with $tmp}}crash_safe_replication = "{{$tmp}}"{{end}} 16 | {{$tmp := $v.DiskAutoresize}}{{with $tmp}}disk_autoresize = "{{$tmp}}"{{end}} 17 | {{$tmp := $v.DiskSize}}{{with $tmp}}disk_size = "{{$tmp}}"{{end}} 18 | {{$tmp := $v.DiskType}}{{with $tmp}}disk_type = "{{$tmp}}"{{end}} 19 | {{$tmp := $v.PricingPlan}}{{with $tmp}}pricing_plan = "{{$tmp}}"{{end}} 20 | {{$tmp := $v.ReplicationType}}{{with $tmp}}replication_type = "{{$tmp}}"{{end}} 21 | {{$tmp := $v.UserLabels}}{{with $tmp}} 22 | user_labels { 23 | {{range $ii, $vv := $tmp}} 24 | {{$ii}} = "{{$vv}}"{{end}} 25 | }{{end}} 26 | 27 | {{$tmp := $v.BackupConfiguration}}{{with $tmp}} 28 | {{range $ii, $vv := $tmp}} 29 | backup_configuration { 30 | {{$tmp1 := $vv.BinaryLogEnabled}}{{with $tmp1}}binary_log_enabled = "{{$tmp1}}"{{end}} 31 | {{$tmp1 := $vv.Enabled}}{{with $tmp1}}enabled = "{{$tmp1}}"{{end}} 32 | {{$tmp1 := $vv.StartTime}}{{with $tmp1}}start_time = "{{$tmp1}}"{{end}} 33 | }{{end}}{{end}} 34 | 35 | {{$tmp := $v.DatabaseFlags}}{{with $tmp}} 36 | {{range $ii, $vv := $tmp}} 37 | database_flags { 38 | {{$tmp1 := $vv.Name}}{{with $tmp1}}name = "{{$tmp1}}"{{end}} 39 | {{$tmp1 := $vv.Value}}{{with $tmp1}}value = "{{$tmp1}}"{{end}} 40 | }{{end}}{{end}} 41 | 42 | {{$tmp := $v.IPConfiguration}}{{with $tmp}} 43 | {{range $ii, $vv := $tmp}} 44 | ip_configuration { 45 | {{$tmp1 := $vv.Ipv4Enabled}}{{with $tmp1}}ipv4_enabled = "{{$tmp1}}"{{end}} 46 | {{$tmp1 := $vv.PrivateNetwork}}{{with $tmp1}}private_network = "{{$tmp1}}"{{end}} 47 | {{$tmp1 := $vv.RequireSsl}}{{with $tmp1}}require_ssl = "{{$tmp1}}"{{end}} 48 | {{$tmp1 := $vv.AuthorizedNetworks}}{{with $tmp1}} 49 | {{range $iii, $vvv := $tmp1}} 50 | authorized_networks { 51 | {{$tmp2 := $vvv.ExpirationTime}}{{with $tmp2}}expiration_time = "{{$tmp2}}"{{end}} 52 | {{$tmp2 := $vvv.Name}}{{with $tmp2}}name = "{{$tmp2}}"{{end}} 53 | {{$tmp2 := $vvv.Value}}{{with $tmp2}}value = "{{$tmp2}}"{{end}} 54 | }{{end}}{{end}} 55 | }{{end}}{{end}} 56 | 57 | {{$tmp := $v.LocationPreference}}{{with $tmp}} 58 | {{range $ii, $vv := $tmp}} 59 | location_preference { 60 | {{$tmp1 := $vv.FollowGaeApplication}}{{with $tmp1}}follow_gae_application = "{{$tmp1}}"{{end}} 61 | {{$tmp1 := $vv.Zone}}{{with $tmp1}}zone = "{{$tmp1}}"{{end}} 62 | }{{end}}{{end}} 63 | 64 | {{$tmp := $v.MaintenanceWindow}}{{with $tmp}} 65 | {{range $ii, $vv := $tmp}} 66 | maintenance_window { 67 | {{$tmp1 := $vv.Day}}{{with $tmp1}}day = "{{$tmp1}}"{{end}} 68 | {{$tmp1 := $vv.Hour}}{{with $tmp1}}hour = "{{$tmp1}}"{{end}} 69 | {{$tmp1 := $vv.UpdateTrack}}{{with $tmp1}}update_track = "{{$tmp1}}"{{end}} 70 | }{{end}}{{end}} 71 | 72 | }{{end}} 73 | 74 | //optional 75 | {{range $i, $v := .Primary.Attributes.ReplicaConfiguration}} 76 | replica_configuration { 77 | {{$tmp := $v.CaCertificate}}{{with $tmp}}ca_certificate = "{{$tmp}}"{{end}} 78 | {{$tmp := $v.ClientCertificate}}{{with $tmp}}client_certificate = "{{$tmp}}"{{end}} 79 | {{$tmp := $v.ClientKey}}{{with $tmp}}client_key = "{{$tmp}}"{{end}} 80 | {{$tmp := $v.ConnectRetryInterval}}{{with $tmp}}connect_retry_interval = "{{$tmp}}"{{end}} 81 | {{$tmp := $v.DumpFilePath}}{{with $tmp}}dump_file_path = "{{$tmp}}"{{end}} 82 | {{$tmp := $v.FailoverTarget}}{{with $tmp}}failover_target = "{{$tmp}}"{{end}} 83 | {{$tmp := $v.MasterHeartbeatPeriod}}{{with $tmp}}master_heartbeat_period = "{{$tmp}}"{{end}} 84 | {{$tmp := $v.Password}}{{with $tmp}}password = "{{$tmp}}"{{end}} 85 | {{$tmp := $v.SslCipher}}{{with $tmp}}ssl_cipher = "{{$tmp}}"{{end}} 86 | {{$tmp := $v.Username}}{{with $tmp}}username = "{{$tmp}}"{{end}} 87 | {{$tmp := $v.VerifyServerCertificate}}{{with $tmp}}verify_server_certificate = "{{$tmp}}"{{end}} 88 | }{{end}} 89 | 90 | {{$tmp := .Primary.Attributes.DatabaseVersion}}{{with $tmp}} 91 | database_version = "{{$tmp}}"{{end}} 92 | 93 | {{$tmp := .Primary.Attributes.Name}}{{with $tmp}} 94 | name = "{{$tmp}}"{{end}} 95 | 96 | {{$tmp := .Primary.Attributes.MasterInstanceName}}{{with $tmp}} 97 | master_instance_name = "{{$tmp}}"{{end}} 98 | 99 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 100 | project = "{{$tmp}}"{{end}} 101 | 102 | } 103 | -------------------------------------------------------------------------------- /resources/templates/google_storage_bucket.tf.tmpl: -------------------------------------------------------------------------------- 1 | resource "google_storage_bucket" "{{convertSlashAndDotToDash .Primary.ID}}"{ 2 | //provider 3 | {{ if eq .Provider "provider.google" }}provider = "google"{{ end }} 4 | {{ if eq .Provider "provider.google-beta" }}provider = "google-beta"{{ end }} 5 | //required 6 | name = "{{.Primary.Attributes.Name}}" 7 | //optional 8 | {{$tmp := .Primary.Attributes.ForceDestroy}}{{with $tmp}} 9 | force_destroy = "{{$tmp}}"{{end}} 10 | 11 | {{$tmp := .Primary.Attributes.Location}}{{with $tmp}} 12 | location = "{{$tmp}}"{{end}} 13 | 14 | {{$tmp := .Primary.Attributes.Project}}{{with $tmp}} 15 | project = "{{$tmp}}"{{end}} 16 | 17 | {{$tmp := .Primary.Attributes.StorageClass}}{{with $tmp}} 18 | storage_class = "{{$tmp}}"{{end}} 19 | 20 | {{range $i, $v := .Primary.Attributes.LifecycleRule}} 21 | lifecycle_rule { 22 | {{$tmp := $v.Action}}{{with $tmp}} 23 | {{range $ii, $vv := $tmp}} 24 | action{ 25 | {{with $vv.Type}}type = "{{$vv.Type}}"{{end}} 26 | {{with $vv.StorageClass}}storage_class = "{{$vv.StorageClass}}"{{end}} 27 | }{{end}}{{end}} 28 | {{$tmp := $v.Condition}}{{with $tmp}} 29 | {{range $ii, $vv := $tmp}}{{$length := len $vv.MatchesStorageClass}} 30 | condition{ 31 | {{with $vv.Age}}age = "{{$vv.Age}}"{{end}} 32 | {{with $vv.CreatedBefore}}created_before = "{{$vv.CreatedBefore}}"{{end}} 33 | {{with $vv.IsLive}}is_live = "{{$vv.IsLive}}"{{end}} 34 | {{with $vv.WithState}}with_state = "{{$vv.WithState}}"{{end}} 35 | {{with $vv.NumNewerVersions}}num_newer_versions = "{{$vv.NumNewerVersions}}"{{end}} 36 | {{with $vv.MatchesStorageClass}}matches_storage_class = [{{range $iii, $vvv := $vv.MatchesStorageClass}}{{if lt (plus $iii) $length }}"{{$vvv}}",{{else}}"{{$vvv}}"{{ end }}{{ end }}]{{end}} 37 | }{{end}}{{end}} 38 | }{{end}} 39 | 40 | {{range $i, $v := .Primary.Attributes.Versioning}} 41 | versioning { 42 | {{with $v.Enabled}}enabled = "{{$v.Enabled}}"{{end}} 43 | }{{end}} 44 | 45 | //website not supported 46 | {{range $i, $v := .Primary.Attributes.Cors}}{{$lengthm := len $v.Method}}{{$lengtho := len $v.Origin}}{{$lengthr := len $v.ResponseHeader}} 47 | cors { 48 | {{with $v.Method}}method = [{{range $ii, $vv := $v.Method}}{{if lt (plus $ii) $lengthm }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 49 | {{with $v.Origin}}origin = [{{range $ii, $vv := $v.Origin}}{{if lt (plus $ii) $lengtho }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 50 | {{with $v.ResponseHeader}}response_header = [{{range $ii, $vv := $v.ResponseHeader}}{{if lt (plus $ii) $lengthr }}"{{$vv}}",{{else}}"{{$vv}}"{{ end }}{{ end }}]{{end}} 51 | {{with $v.MaxAgeSeconds}}max_age_seconds = "{{$v.MaxAgeSeconds}}"{{end}} 52 | }{{end}} 53 | 54 | {{$tmp := .Primary.Attributes.Labels}}{{with $tmp}} 55 | labels { 56 | {{range $i, $v := $tmp}} 57 | {{$i}} = "{{$v}}"{{end}} 58 | }{{end}} 59 | 60 | {{range $i, $v := .Primary.Attributes.Logging}} 61 | logging { 62 | {{$tmp := $v.LogBucket}}{{with $tmp}}log_bucket = "{{$tmp}}" {{end}} 63 | {{$tmp := $v.LogObjectPrefix}}{{with $tmp}}log_object_prefix = "{{$tmp}}" {{end}} 64 | }{{end}} 65 | 66 | {{range $i, $v := .Primary.Attributes.Encryption}} 67 | encryption { 68 | {{$tmp := $v.DefaultKmsKeyName}}{{with $tmp}}default_kms_key_name = "{{$tmp}}" {{end}} 69 | }{{end}} 70 | 71 | {{$tmp := .Primary.Attributes.RequesterPays}}{{with $tmp}} 72 | requester_pays = "{{$tmp}}"{{end}} 73 | 74 | } 75 | -------------------------------------------------------------------------------- /terraformUtil/terraformUtil.go: -------------------------------------------------------------------------------- 1 | package terraformUtil 2 | 3 | import ( 4 | "bytes" 5 | "os/exec" 6 | "path" 7 | "strings" 8 | 9 | "github.com/cloud-ace/terraformit-gcp/utils" 10 | "golang.org/x/xerrors" 11 | ) 12 | 13 | func TerraformCmd(subcommand ...string) error { 14 | var stdout bytes.Buffer 15 | var stderr bytes.Buffer 16 | 17 | cmd := exec.Command("terraform", subcommand...) 18 | cmd.Stdout = &stdout 19 | cmd.Stderr = &stderr 20 | err := cmd.Run() 21 | //subcommandごとにエラー処理 22 | if err != nil { 23 | return xerrors.Errorf("Error: %v \ncommand:terraform %v \n%s", err, subcommand, stderr.String()) 24 | } 25 | return nil 26 | } 27 | 28 | func ExecuteImportSh() error { 29 | var stdout bytes.Buffer 30 | var stderr bytes.Buffer 31 | 32 | cmd := exec.Command("sh", path.Base(utils.ImportShName)) 33 | cmd.Stdout = &stdout 34 | cmd.Stderr = &stderr 35 | err := cmd.Run() 36 | 37 | if err != nil { 38 | return xerrors.Errorf("Import Error: %v\n%s", err, stderr.String()) 39 | } 40 | if strings.Contains(stdout.String(), "Error") || strings.Contains(stderr.String(), "Error") { 41 | return xerrors.Errorf("Error! %v\n%s", err, stderr.String()) 42 | } 43 | return nil 44 | } 45 | 46 | func GetTfstatePath(workspace string) (string, error) { 47 | if workspace == "" { 48 | return "", xerrors.New("Error: workspace is not set") 49 | } 50 | switch workspace { 51 | case "default": 52 | return "./" + utils.TfstateName, nil 53 | default: 54 | return "./" + "terraform.tfstate.d/" + workspace + "/" + utils.TfstateName, nil 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /utils/cmn.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os" 7 | "strings" 8 | "text/template" 9 | 10 | "golang.org/x/xerrors" 11 | ) 12 | 13 | //File name 14 | const ( 15 | RepositoryDirectory = "github.com/cloud-ace/terraformit-gcp" 16 | ProviderTfName = "terraformit-gcp-provider.tf" 17 | ResourceTfName = "terraformit-gcp-resource.tf" 18 | BackendTfName = "terraformit-gcp-backend.tf" 19 | TfName = "terraformit-gcp-resource.tf" 20 | ImportShName = "terraformit-gcp-import.sh" 21 | TfstateName = "terraform.tfstate" 22 | ObjectNamePrefix = "CloudAssetMetadata" 23 | ) 24 | 25 | func CreateFile(fileName string, buf bytes.Buffer) error { 26 | file, err := os.OpenFile(fileName, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0777) 27 | if err != nil { 28 | return xerrors.Errorf("failed to open file: %w", err) 29 | } 30 | defer file.Close() 31 | 32 | file.Write(buf.Bytes()) 33 | if err != nil { 34 | return xerrors.Errorf("Error: %w", err) 35 | } 36 | fmt.Println(fileName, " created.") 37 | return nil 38 | } 39 | 40 | //templateに渡すfunction 41 | var FuncMap = template.FuncMap{ 42 | "plus": func(a int) int { return a + 1 }, 43 | "createRegion": func(s string) string { 44 | 45 | slice := strings.Split(s, "/") 46 | return slice[8] 47 | }, 48 | "createZone": func(s string) string { 49 | 50 | slice := strings.Split(s, "/") 51 | return slice[8] 52 | }, 53 | "createProject": func(s string) string { 54 | 55 | slice := strings.Split(s, "/") 56 | return slice[4] 57 | }, 58 | "convertSlashAndDotToDash": func(s string) string { 59 | tmp := strings.Replace(s, "/", "-", -1) 60 | return strings.Replace(tmp, ".", "-", -1) 61 | }, 62 | "convertsingleTodouble": func(s string) string { 63 | return strings.Replace(s, "`", "\"", -1) 64 | }, 65 | "escapeDoubleQuote": func(s string) string { 66 | return strings.Replace(s, "\"", "\\\"", -1) 67 | }, 68 | "removeAtmark": func(s string) string { 69 | return strings.Replace(s, "@", "-", -1) 70 | // ss := strings.Split(s, "@") 71 | // return ss[0] 72 | }, 73 | "getLastWord": func(s string) string { 74 | 75 | ss := strings.Split(s, "/") 76 | return ss[len(ss)-1] 77 | }, 78 | } 79 | 80 | func GetGoPath() string { 81 | GoPath := os.Getenv("GOPATH") 82 | if GoPath == "" { 83 | GoPath = os.Getenv("HOME") + "/go" 84 | } 85 | return GoPath 86 | } 87 | -------------------------------------------------------------------------------- /utils/cmn_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "os" 7 | "testing" 8 | ) 9 | 10 | var () 11 | 12 | func TestCreateFile(t *testing.T) { 13 | t.Helper() 14 | dir, _ := ioutil.TempDir("", "") 15 | defer os.RemoveAll(dir) 16 | value := "test" 17 | buf := bytes.NewBufferString(value) 18 | filename := dir + "/test" 19 | 20 | //Create test file written in "test" 21 | if err := CreateFile(filename, *buf); err != nil { 22 | t.Fatalf("failed to call CreateFile(): %v", err) 23 | } 24 | 25 | //Read test file 26 | f, err := os.Open(filename) 27 | if err != nil { 28 | t.Fatalf("failed to oepn File: %v", err) 29 | } 30 | testbuf, err := ioutil.ReadAll(f) 31 | if err != nil { 32 | t.Fatalf("failed to read File: %v", err) 33 | } 34 | result := string(testbuf) 35 | if result != value { 36 | t.Fatalf("the result is not an expected value: %v != %v", result, value) 37 | } 38 | 39 | } 40 | --------------------------------------------------------------------------------