mirror of
https://github.com/mcuadros/ascode
synced 2024-11-22 17:02:03 +01:00
*: removed provider global in favor of tf
This commit is contained in:
parent
74c404f8e3
commit
b1d50635de
@ -18,7 +18,7 @@ Terraform is a great tool, with support for almost everything you can imagine, m
|
||||
Creating am Amazon EC2 Instance is as easy as:
|
||||
|
||||
```pyhon
|
||||
aws = provider("aws", "2.13.0")
|
||||
aws = tf.provider("aws", "2.13.0")
|
||||
aws.region = "us-west-2"
|
||||
|
||||
aws.resource.instance(instance_type ="t2.micro", ami="ami-2757f631")
|
||||
@ -28,7 +28,7 @@ aws.resource.instance(instance_type ="t2.micro", ami="ami-2757f631")
|
||||
In this example we create 40 instances, 20 using ubuntu and 20 using ECS.
|
||||
|
||||
```python
|
||||
aws = provider("aws")
|
||||
aws = tf.provider("aws")
|
||||
aws.region = "us-west-2"
|
||||
|
||||
# It creates a new instance for the given name, distro and type.
|
||||
|
@ -1,4 +1,4 @@
|
||||
aws = provider("aws")
|
||||
aws = tf.provider("aws")
|
||||
aws.region = "us-west-2"
|
||||
|
||||
# It creates a new instance for the given name, distro and type.
|
||||
|
@ -1,3 +1,3 @@
|
||||
b = backend("gcs")
|
||||
b.bucket = "tf-state-prod"
|
||||
b.prefix = "terraform/state"
|
||||
tf.backend = backend("gcs")
|
||||
tf.backend.bucket = "tf-state-prod"
|
||||
tf.backend.prefix = "terraform/state"
|
@ -1,6 +1,6 @@
|
||||
load("experimental/docker", "docker")
|
||||
|
||||
p = provider("docker", "2.7.0", "foo")
|
||||
p = tf.provider("docker", "2.7.0", "foo")
|
||||
|
||||
# using docker.image semver can be used to choose the docker image, `
|
||||
golang = docker.image("golang", "1.13.x")
|
||||
@ -9,6 +9,4 @@ foo = p.resource.container("foo")
|
||||
foo.name = "foo"
|
||||
|
||||
# version queries the docker repository and returns the correct tag.
|
||||
foo.image = golang.version(full=True)
|
||||
|
||||
print(hcl(p))
|
||||
foo.image = golang.version(full=True)
|
@ -1,4 +1,4 @@
|
||||
ignition = provider("ignition", "1.1.0")
|
||||
ignition = tf.provider("ignition", "1.1.0")
|
||||
|
||||
user = ignition.data.user()
|
||||
user.name = "foo"
|
||||
|
13
cmd/run.go
13
cmd/run.go
@ -23,7 +23,8 @@ const (
|
||||
type RunCmd struct {
|
||||
commonCmd
|
||||
|
||||
ToHCL string `long:"to-hcl" description:"dumps context resources to a hcl file"`
|
||||
ToHCL string `long:"to-hcl" description:"dumps resources to a hcl file"`
|
||||
PrintHCL bool `long:"print-hcl" description:"print resources to a hcl file"`
|
||||
PositionalArgs struct {
|
||||
File string `positional-arg-name:"file" description:"starlark source file"`
|
||||
} `positional-args:"true" required:"1"`
|
||||
@ -47,12 +48,20 @@ func (c *RunCmd) Execute(args []string) error {
|
||||
}
|
||||
|
||||
func (c *RunCmd) dumpToHCL(ctx starlark.StringDict) error {
|
||||
if c.ToHCL == "" {
|
||||
if c.ToHCL == "" && !c.PrintHCL {
|
||||
return nil
|
||||
}
|
||||
|
||||
f := hclwrite.NewEmptyFile()
|
||||
c.runtime.Terraform.ToHCL(f.Body())
|
||||
|
||||
if c.PrintHCL {
|
||||
os.Stdout.Write(f.Bytes())
|
||||
}
|
||||
|
||||
if c.ToHCL == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(c.ToHCL, f.Bytes(), 0644)
|
||||
}
|
||||
|
@ -58,7 +58,6 @@ func NewRuntime(pm *terraform.PluginManager) *Runtime {
|
||||
},
|
||||
predeclared: starlark.StringDict{
|
||||
"tf": tf,
|
||||
"provider": types.BuiltinProvider(pm),
|
||||
"provisioner": types.BuiltinProvisioner(pm),
|
||||
"backend": types.BuiltinBackend(pm),
|
||||
"hcl": types.BuiltinHCL(),
|
||||
|
@ -99,3 +99,4 @@ resource "aws_vpc" "id_2" {
|
||||
cidr_block = "172.16.0.0/16"
|
||||
tags = { Name = "tf-example" }
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,6 @@ func doTest(t *testing.T, filename string) {
|
||||
pm := &terraform.PluginManager{".providers"}
|
||||
|
||||
predeclared := starlark.StringDict{
|
||||
"provider": BuiltinProvider(pm),
|
||||
"provisioner": BuiltinProvisioner(pm),
|
||||
"backend": BuiltinBackend(pm),
|
||||
"hcl": BuiltinHCL(),
|
||||
|
4
starlark/types/testdata/computed.star
vendored
4
starlark/types/testdata/computed.star
vendored
@ -1,6 +1,6 @@
|
||||
load("assert.star", "assert")
|
||||
|
||||
aws = provider("aws", "2.13.0")
|
||||
aws = tf.provider("aws", "2.13.0")
|
||||
|
||||
# compute of scalar
|
||||
web = aws.resource.instance()
|
||||
@ -30,7 +30,7 @@ assert.eq(str(aws.resource.instance().id), '"${aws_instance.id_7.id}"')
|
||||
# compute on resource
|
||||
assert.eq(str(aws.data.ami().id), '"${data.aws_ami.id_8.id}"')
|
||||
|
||||
gcp = provider("google", "3.13.0")
|
||||
gcp = tf.provider("google", "3.13.0")
|
||||
|
||||
# computed on list with MaxItem:1
|
||||
cluster = gcp.resource.container_cluster("foo")
|
||||
|
2
starlark/types/testdata/hcl.star
vendored
2
starlark/types/testdata/hcl.star
vendored
@ -1,6 +1,6 @@
|
||||
load("assert.star", "assert")
|
||||
|
||||
helm = provider("helm", "1.0.0", "default")
|
||||
helm = tf.provider("helm", "1.0.0", "default")
|
||||
helm.kubernetes.token = "foo"
|
||||
|
||||
# hcl
|
||||
|
4
starlark/types/testdata/hcl_integration.star
vendored
4
starlark/types/testdata/hcl_integration.star
vendored
@ -1,7 +1,7 @@
|
||||
load("os", "os")
|
||||
load("assert.star", "assert")
|
||||
|
||||
aws = provider("aws", "2.13.0")
|
||||
aws = tf.provider("aws", "2.13.0")
|
||||
aws.region = "us-west-2"
|
||||
|
||||
# Based on:
|
||||
@ -71,4 +71,4 @@ example.ami = "ami-2757f631"
|
||||
example.instance_type = "t2.micro"
|
||||
example.depends_on(bucket)
|
||||
|
||||
assert.eq(hcl(aws), os.read_file("fixtures/aws.tf"))
|
||||
assert.eq(hcl(tf), os.read_file("fixtures/aws.tf"))
|
||||
|
2
starlark/types/testdata/nested.star
vendored
2
starlark/types/testdata/nested.star
vendored
@ -1,6 +1,6 @@
|
||||
load("assert.star", "assert")
|
||||
|
||||
p = provider("aws", "2.13.0")
|
||||
p = tf.provider("aws", "2.13.0")
|
||||
d = p.data.ami()
|
||||
|
||||
assert.eq(type(d.filter), "ResourceCollection<nested.filter>")
|
||||
|
6
starlark/types/testdata/provider.star
vendored
6
starlark/types/testdata/provider.star
vendored
@ -1,6 +1,6 @@
|
||||
load("assert.star", "assert")
|
||||
|
||||
p = provider("aws", "2.13.0")
|
||||
p = tf.provider("aws", "2.13.0")
|
||||
assert.eq(p.version, "2.13.0")
|
||||
|
||||
assert.eq(len(dir(p.data)), 131)
|
||||
@ -19,11 +19,11 @@ assert.eq(len(p.resource.instance), 2)
|
||||
p.region = "us-west-2"
|
||||
assert.eq(p.region, "us-west-2")
|
||||
|
||||
alias = provider("aws", "2.13.0", "alias")
|
||||
alias = tf.provider("aws", "2.13.0", "alias")
|
||||
assert.eq(alias.alias, "alias")
|
||||
assert.eq(alias.version, "2.13.0")
|
||||
|
||||
kwargs = provider("aws", region="foo")
|
||||
kwargs = tf.provider("aws", region="foo")
|
||||
assert.eq(kwargs.region, "foo")
|
||||
|
||||
# compare
|
||||
|
4
starlark/types/testdata/resource.star
vendored
4
starlark/types/testdata/resource.star
vendored
@ -1,6 +1,6 @@
|
||||
load("assert.star", "assert")
|
||||
|
||||
p = provider("ignition", "1.1.0")
|
||||
p = tf.provider("ignition", "1.1.0")
|
||||
|
||||
# attr
|
||||
qux = p.data.user()
|
||||
@ -21,7 +21,7 @@ assert.eq(type(qux.id), "Computed")
|
||||
assert.eq(str(qux.id), '"${data.ignition_user.id_2.id}"')
|
||||
|
||||
# attr output assignation
|
||||
aws = provider("aws", "2.13.0")
|
||||
aws = tf.provider("aws", "2.13.0")
|
||||
def invalidOutput(): aws.data.instance().public_dns = "foo"
|
||||
assert.fails(invalidOutput, "aws_instance: can't set computed public_dns attribute")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user