File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
1010const (
1111 deviceFormat = `
1212---
13- apiVersion: server .metal.equinix.com/v1alpha2
13+ apiVersion: devices .metal.equinix.jet.crossplane.io/v1alpha1
1414kind: Device
1515metadata:
1616 name: {{.Hostname}}
4747func many (s string ) string {
4848 return `{{range .}}` + s + `{{end}}`
4949}
50+
5051func Marshal (i interface {}) ([]byte , error ) {
51- var f = ""
52+ f : = ""
5253 switch i .(type ) {
5354 case * packngo.Device :
5455 f = deviceFormat
Original file line number Diff line number Diff line change 1+ # terraform import equinix_metal_device. {{.Hostname }} {{.ID }}
2+ resource " equinix_metal_device" " {{.Hostname}}" {
3+ plan = " {{.Plan.Slug}}"
4+ hostname = " {{.Hostname}}"
5+ billing_cycle = " {{.BillingCycle}}"
6+ metro = " {{.Metro.Code}}"
7+ operating_system = " {{.OS.Slug}}"
8+ project_id = " {{.Project.ID}}"
9+
10+ tags = {{.Tags }}
11+ }
Original file line number Diff line number Diff line change @@ -2,37 +2,43 @@ package terraform
22
33import (
44 "bytes"
5+ _ "embed"
56 "html/template"
7+ "path"
68
79 "github.com/packethost/packngo"
810)
911
10- const deviceFormat = `
11- # terraform import metal_device.{{.Hostname}} {{.ID}}
12- resource "metal_device" "{{.Hostname}}" {
13- plan = "{{.Plan.Slug}}"
14- hostname = "{{.Hostname}}"
15- billing_cycle = "{{.BillingCycle}}"
16- metro = "{{.Metro.Code}}"
17- operating_system = "{{.OS.Slug}}"
18- project_id = "{{.Project.ID}}"
12+ var (
13+ //go:embed device.tf.gotmpl
14+ deviceFormat string
1915
20- tags = {{.Tags}}
21- }
22- `
16+ //go:embed project.tf.gotmpl
17+ projectFormat string
18+ )
2319
2420func many (s string ) string {
2521 return `{{range .}}` + s + `{{end}}`
2622}
23+
2724func Marshal (i interface {}) ([]byte , error ) {
28- var f = ""
25+ f : = ""
2926 switch i .(type ) {
3027 case * packngo.Device :
3128 f = deviceFormat
3229 case []packngo.Device :
3330 f = many (deviceFormat )
31+ case * packngo.Project :
32+ f = projectFormat
33+ case []packngo.Project :
34+ f = many (projectFormat )
3435 }
35- tmpl , err := template .New ("terraform" ).Parse (f )
36+
37+ tmpl , err := template .New ("terraform" ).Funcs (template.FuncMap {
38+ "hrefToID" : func (href string ) string {
39+ return path .Base (href )
40+ },
41+ }).Parse (f )
3642 if err != nil {
3743 return nil , err
3844 }
Original file line number Diff line number Diff line change 1+ # terraform import equinix_metal_project. {{.Name }} {{.ID }}
2+ resource " equinix_metal_project" " {{.Name}}" {
3+ name = " {{.Name}}"
4+ organization_id = " {{.Organization.URL | hrefToID}}"
5+ # TODO: bgp_config
6+ }
7+
Original file line number Diff line number Diff line change @@ -96,7 +96,6 @@ func (c *Client) Retrieve() *cobra.Command {
9696 }
9797
9898 data := make ([][]string , 1 )
99-
10099 data [0 ] = []string {p .ID , p .Name , p .Created }
101100 header := []string {"ID" , "Name" , "Created" }
102101 return c .Out .Output (p , header , & data )
You can’t perform that action at this time.
0 commit comments