mirror of
https://github.com/mcuadros/ascode
synced 2024-11-26 06:01:08 +01:00
*: project renamed
Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
This commit is contained in:
parent
a339458eab
commit
a6e365eca5
14
main.go
14
main.go
@ -6,8 +6,10 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/ascode-dev/ascode/starlark/types"
|
||||
"github.com/ascode-dev/ascode/terraform"
|
||||
|
||||
"github.com/hashicorp/hcl2/hclwrite"
|
||||
"github.com/mcuadros/terra/provider"
|
||||
"go.starlark.net/repl"
|
||||
"go.starlark.net/resolve"
|
||||
"go.starlark.net/starlark"
|
||||
@ -16,19 +18,19 @@ import (
|
||||
func main() {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
|
||||
pm := &provider.PluginManager{".providers"}
|
||||
pm := &terraform.PluginManager{".providers"}
|
||||
resolve.AllowFloat = true
|
||||
|
||||
pro := starlark.NewBuiltin("provider", func(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
|
||||
provider := starlark.NewBuiltin("provider", func(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
|
||||
name := args.Index(0).(starlark.String)
|
||||
version := args.Index(1).(starlark.String)
|
||||
|
||||
return provider.MakeProvider(pm, string(name), string(version))
|
||||
return types.MakeProvider(pm, string(name), string(version))
|
||||
})
|
||||
|
||||
thread := &starlark.Thread{Name: "thread", Load: repl.MakeLoad()}
|
||||
predeclared := starlark.StringDict{
|
||||
"provider": pro,
|
||||
"provider": provider,
|
||||
}
|
||||
|
||||
out, err := starlark.ExecFile(thread, os.Args[1], nil, predeclared)
|
||||
@ -40,7 +42,7 @@ func main() {
|
||||
}
|
||||
|
||||
for _, v := range out {
|
||||
p, ok := v.(*provider.Provider)
|
||||
p, ok := v.(*types.Provider)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,10 +1,9 @@
|
||||
package provider
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
|
||||
"go.starlark.net/starlark"
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package types
|
||||
|
||||
import "testing"
|
||||
|
@ -1,10 +1,11 @@
|
||||
package provider
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/hcl2/hcl"
|
||||
"github.com/hashicorp/hcl2/hclwrite"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
"go.starlark.net/starlark"
|
||||
)
|
||||
|
||||
@ -31,6 +32,9 @@ func BuiltinHCL() starlark.Value {
|
||||
}
|
||||
|
||||
func (s *Provider) ToHCL(b *hclwrite.Body) {
|
||||
block := b.AppendNewBlock("provider", []string{s.name})
|
||||
block.Body().SetAttributeValue("version", cty.StringVal(string(s.meta.Version)))
|
||||
|
||||
s.dataSources.ToHCL(b)
|
||||
s.resources.ToHCL(b)
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
package provider
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/plugin/discovery"
|
||||
"github.com/ascode-dev/ascode/terraform"
|
||||
|
||||
"github.com/hashicorp/terraform/plugin"
|
||||
"github.com/hashicorp/terraform/plugin/discovery"
|
||||
"github.com/hashicorp/terraform/providers"
|
||||
"go.starlark.net/starlark"
|
||||
)
|
||||
@ -18,9 +19,11 @@ type Provider struct {
|
||||
|
||||
dataSources *MapSchema
|
||||
resources *MapSchema
|
||||
|
||||
r *Resource
|
||||
}
|
||||
|
||||
func MakeProvider(pm *PluginManager, name, version string) (*Provider, error) {
|
||||
func MakeProvider(pm *terraform.PluginManager, name, version string) (*Provider, error) {
|
||||
cli, meta := pm.Get(name, version)
|
||||
rpc, err := cli.Client()
|
||||
if err != nil {
|
||||
@ -40,6 +43,7 @@ func MakeProvider(pm *PluginManager, name, version string) (*Provider, error) {
|
||||
name: name,
|
||||
provider: provider,
|
||||
meta: meta,
|
||||
r: MakeResource("", ResourceK, response.Provider.Block, nil),
|
||||
dataSources: NewMapSchema(name, DataResourceK, response.DataSources),
|
||||
resources: NewMapSchema(name, ResourceK, response.ResourceTypes),
|
||||
}, nil
|
||||
@ -56,7 +60,6 @@ func (p *Provider) Type() string {
|
||||
func (p *Provider) Freeze() {}
|
||||
func (p *Provider) Truth() starlark.Bool { return true }
|
||||
func (p *Provider) Hash() (uint32, error) { return 1, nil }
|
||||
func (p *Provider) Name() string { return p.name }
|
||||
func (p *Provider) Attr(name string) (starlark.Value, error) {
|
||||
switch name {
|
||||
case "version":
|
@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/ascode-dev/ascode/terraform"
|
||||
"go.starlark.net/resolve"
|
||||
"go.starlark.net/starlark"
|
||||
"go.starlark.net/starlarktest"
|
||||
@ -43,7 +44,7 @@ func test(t *testing.T, filename string) {
|
||||
provider := starlark.NewBuiltin("provider", func(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
|
||||
name := args.Index(0).(starlark.String)
|
||||
version := args.Index(1).(starlark.String)
|
||||
return MakeProvider(&PluginManager{".providers"}, string(name), string(version))
|
||||
return MakeProvider(&terraform.PluginManager{".providers"}, string(name), string(version))
|
||||
})
|
||||
|
||||
predeclared := starlark.StringDict{
|
@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -13,7 +13,6 @@ web = aws.resource.instance(instance_type="t2.micro")
|
||||
#web.instance_type = "t2.micro"
|
||||
#web.ami = ami.id
|
||||
|
||||
|
||||
template = aws.resource.launch_template()
|
||||
template.name_prefix = "example"
|
||||
template.instance_type = "c5.larger"
|
||||
@ -26,12 +25,12 @@ group.min_size = 1
|
||||
group.mixed_instances_policy = {
|
||||
"launch_template": {
|
||||
"launch_template_specification": {
|
||||
"launch_template_id": "bar"
|
||||
}
|
||||
}
|
||||
"launch_template_id": "bar",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ami2 = aws.data.ami()
|
||||
ami2.most_recent = True
|
||||
|
||||
#print(hcl(aws))
|
||||
print(hcl(aws))
|
@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,4 +1,4 @@
|
||||
package provider
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"os"
|
Loading…
Reference in New Issue
Block a user