Skip to content

Commit

Permalink
refactor: Add version for terraform template (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeiminds committed Oct 17, 2023
1 parent 62ca979 commit c1e5cc6
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ import (
_resource: gotemplate.Execute(_resource_template, {
"name": naming.#UpperCamel & {"name": name}
"pkg": pkg
v: rs
"v": rs
properties: [
for i, pinfo in rs.models[name].properties {
gotemplate.Execute(_prop_template, {
name: naming.#Snake & {"name": pinfo.name}
v: pinfo
index: i + 1
"name": naming.#Snake & {"name": pinfo.name}
"v": pinfo
"index": i + 1
})
},
]
Expand All @@ -135,29 +135,29 @@ import (
_data_source: gotemplate.Execute(_data_source_template, {
"name": naming.#UpperCamel & {"name": name}
"pkg": pkg
v: rs
"v": rs
properties: [
for i, pinfo in rs.models[name].properties {
gotemplate.Execute(_prop_template, {
name: naming.#Snake & {"name": pinfo.name}
v: pinfo
index: i + 1
"name": naming.#Snake & {"name": pinfo.name}
"v": pinfo
"index": i + 1
})
},
]
})

_models: [
for mname, minfo in rs.models if mname != name {
for mname, minfo in (rs.models | *{}) if mname != name {
gotemplate.Execute(_model_template, {
name: naming.#UpperCamel & {"name": mname}
v: minfo
"name": naming.#UpperCamel & {"name": mname}
"v": minfo
properties: [
for i, pinfo in minfo.properties {
gotemplate.Execute(_prop_template, {
name: naming.#Snake & {"name": pinfo.name}
v: pinfo
index: i + 1
"name": naming.#Snake & {"name": pinfo.name}
"v": pinfo
"index": i + 1
})
},
]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package terraform
package v1

import (
gotemplate "text/template"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package datasource
import (
template "github.com/GuanceCloud/iacker/pkg/template/v1"
naming "github.com/GuanceCloud/iacker/pkg/helpers/naming"
builder "github.com/GuanceCloud/iacker/templates/terraform/builder"
builder "github.com/GuanceCloud/iacker/templates/terraform/v1/builder"
)

// Generate go types of resource model
for rsname, rsinfo in inputs.resources {
if (*rsinfo.meta.datasource | false) {
outputs: files: "internal/datasources/\((naming.#Snake & {"name": rsinfo.plural}).lower)/model.go": template.#File & {
_builder: builder.#StructBuilder & {
pkg: (naming.#Snake & {"name": rsinfo.plural}).lower
name: rsname
rs: rsinfo
isds: true
"pkg": (naming.#Snake & {"name": rsinfo.plural}).lower
"name": rsname
"rs": rsinfo
"isds": true
}
content: _builder.output
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package schema
import (
template "github.com/GuanceCloud/iacker/pkg/template/v1"
naming "github.com/GuanceCloud/iacker/pkg/helpers/naming"
builder "github.com/GuanceCloud/iacker/templates/terraform/builder"
builder "github.com/GuanceCloud/iacker/templates/terraform/v1/builder"
)

// Generate Terraform schema
for rsname, rsinfo in inputs.resources {
if (*rsinfo.meta.datasource | false) {
outputs: files: "internal/datasources/\((naming.#Snake & {"name": rsinfo.plural}).lower)/schema.go": template.#File & {
_builder: builder.#SchemaBuilder & {
pkg: (naming.#Snake & {"name": rsinfo.plural}).lower
name: rsname
rs: rsinfo
isds: true
"pkg": (naming.#Snake & {"name": rsinfo.plural}).lower
"name": rsname
"rs": rsinfo
"isds": true
}
content: _builder.output
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package terraform
package v1

import (
template "github.com/GuanceCloud/iacker/pkg/template/v1"
resource "github.com/GuanceCloud/iacker/templates/terraform/resource"
datasource "github.com/GuanceCloud/iacker/templates/terraform/datasource"
resource "github.com/GuanceCloud/iacker/templates/terraform/v1/resource"
datasource "github.com/GuanceCloud/iacker/templates/terraform/v1/datasource"
)

name: "terraform"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ outputs: files: "\(provider)/resources.go": template.#File & {
for rsname, rsinfo in inputs.resources {
if !(*rsinfo.meta.datasource | false) {
(rsname): naming.#UpperCamel & {
name: rsname
"name": rsname
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import (
"strings"

template "github.com/GuanceCloud/iacker/pkg/template/v1"
builder "github.com/GuanceCloud/iacker/templates/terraform/builder"
builder "github.com/GuanceCloud/iacker/templates/terraform/v1/builder"
)

// Generate go types of resource model
for rsname, rsinfo in inputs.resources {
if !(*rsinfo.meta.datasource | false) {
outputs: files: "internal/resources/\(strings.ToLower(rsname))/model.go": template.#File & {
_builder: builder.#StructBuilder & {
pkg: strings.ToLower(rsname)
name: rsname
rs: rsinfo
"pkg": strings.ToLower(rsname)
"name": rsname
"rs": rsinfo
}
content: _builder.output
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ for rsname, rsinfo in inputs.resources {
if !(*rsinfo.meta.datasource | false) {
outputs: files: "internal/resources/\(strings.ToLower(rsname))/resource.go": template.#File & {
content: gotemplate.Execute(_resource_operation_template, {
name: naming.#UpperCamel & {"name": rsname}
"name": naming.#UpperCamel & {"name": rsname}
})
}
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import (
"strings"

template "github.com/GuanceCloud/iacker/pkg/template/v1"
builder "github.com/GuanceCloud/iacker/templates/terraform/builder"
builder "github.com/GuanceCloud/iacker/templates/terraform/v1/builder"
)

// Generate Terraform schema
for rsname, rsinfo in inputs.resources {
if !(*rsinfo.meta.datasource | false) {
outputs: files: "internal/resources/\(strings.ToLower(rsname))/schema.go": template.#File & {
_builder: builder.#SchemaBuilder & {
pkg: strings.ToLower(rsname)
name: rsname
rs: rsinfo
"name": rsname
"pkg": strings.ToLower(rsname)
"rs": rsinfo
}
content: _builder.output
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package tests

import (
"github.com/GuanceCloud/iacker/examples/petstore"
"github.com/GuanceCloud/iacker/templates/terraform"
"github.com/GuanceCloud/iacker/templates/terraform/v1"
)

resources: petstore.resources
Expand Down

0 comments on commit c1e5cc6

Please sign in to comment.