Skip to content

Commit b1d5063

Browse files
committed
*: removed provider global in favor of tf
1 parent 74c404f commit b1d5063

File tree

15 files changed

+32
-26
lines changed

15 files changed

+32
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Terraform is a great tool, with support for almost everything you can imagine, m
1818
Creating am Amazon EC2 Instance is as easy as:
1919

2020
```pyhon
21-
aws = provider("aws", "2.13.0")
21+
aws = tf.provider("aws", "2.13.0")
2222
aws.region = "us-west-2"
2323
2424
aws.resource.instance(instance_type ="t2.micro", ami="ami-2757f631")
@@ -28,7 +28,7 @@ aws.resource.instance(instance_type ="t2.micro", ami="ami-2757f631")
2828
In this example we create 40 instances, 20 using ubuntu and 20 using ECS.
2929

3030
```python
31-
aws = provider("aws")
31+
aws = tf.provider("aws")
3232
aws.region = "us-west-2"
3333

3434
# It creates a new instance for the given name, distro and type.

_examples/aws.star

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
aws = provider("aws")
1+
aws = tf.provider("aws")
22
aws.region = "us-west-2"
33

44
# It creates a new instance for the given name, distro and type.

_examples/backend.star

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
b = backend("gcs")
2-
b.bucket = "tf-state-prod"
3-
b.prefix = "terraform/state"
1+
tf.backend = backend("gcs")
2+
tf.backend.bucket = "tf-state-prod"
3+
tf.backend.prefix = "terraform/state"

_examples/docker.star

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("experimental/docker", "docker")
22

3-
p = provider("docker", "2.7.0", "foo")
3+
p = tf.provider("docker", "2.7.0", "foo")
44

55
# using docker.image semver can be used to choose the docker image, `
66
golang = docker.image("golang", "1.13.x")
@@ -9,6 +9,4 @@ foo = p.resource.container("foo")
99
foo.name = "foo"
1010

1111
# version queries the docker repository and returns the correct tag.
12-
foo.image = golang.version(full=True)
13-
14-
print(hcl(p))
12+
foo.image = golang.version(full=True)

_examples/ignition.star

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ignition = provider("ignition", "1.1.0")
1+
ignition = tf.provider("ignition", "1.1.0")
22

33
user = ignition.data.user()
44
user.name = "foo"

cmd/run.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const (
2323
type RunCmd struct {
2424
commonCmd
2525

26-
ToHCL string `long:"to-hcl" description:"dumps context resources to a hcl file"`
26+
ToHCL string `long:"to-hcl" description:"dumps resources to a hcl file"`
27+
PrintHCL bool `long:"print-hcl" description:"print resources to a hcl file"`
2728
PositionalArgs struct {
2829
File string `positional-arg-name:"file" description:"starlark source file"`
2930
} `positional-args:"true" required:"1"`
@@ -47,12 +48,20 @@ func (c *RunCmd) Execute(args []string) error {
4748
}
4849

4950
func (c *RunCmd) dumpToHCL(ctx starlark.StringDict) error {
50-
if c.ToHCL == "" {
51+
if c.ToHCL == "" && !c.PrintHCL {
5152
return nil
5253
}
5354

5455
f := hclwrite.NewEmptyFile()
5556
c.runtime.Terraform.ToHCL(f.Body())
5657

58+
if c.PrintHCL {
59+
os.Stdout.Write(f.Bytes())
60+
}
61+
62+
if c.ToHCL == "" {
63+
return nil
64+
}
65+
5766
return ioutil.WriteFile(c.ToHCL, f.Bytes(), 0644)
5867
}

starlark/runtime/runtime.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func NewRuntime(pm *terraform.PluginManager) *Runtime {
5858
},
5959
predeclared: starlark.StringDict{
6060
"tf": tf,
61-
"provider": types.BuiltinProvider(pm),
6261
"provisioner": types.BuiltinProvisioner(pm),
6362
"backend": types.BuiltinBackend(pm),
6463
"hcl": types.BuiltinHCL(),

starlark/types/fixtures/aws.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,4 @@ resource "aws_vpc" "id_2" {
9999
cidr_block = "172.16.0.0/16"
100100
tags = { Name = "tf-example" }
101101
}
102+

starlark/types/provider_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ func doTest(t *testing.T, filename string) {
6464
pm := &terraform.PluginManager{".providers"}
6565

6666
predeclared := starlark.StringDict{
67-
"provider": BuiltinProvider(pm),
6867
"provisioner": BuiltinProvisioner(pm),
6968
"backend": BuiltinBackend(pm),
7069
"hcl": BuiltinHCL(),

starlark/types/testdata/computed.star

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("assert.star", "assert")
22

3-
aws = provider("aws", "2.13.0")
3+
aws = tf.provider("aws", "2.13.0")
44

55
# compute of scalar
66
web = aws.resource.instance()
@@ -30,7 +30,7 @@ assert.eq(str(aws.resource.instance().id), '"${aws_instance.id_7.id}"')
3030
# compute on resource
3131
assert.eq(str(aws.data.ami().id), '"${data.aws_ami.id_8.id}"')
3232

33-
gcp = provider("google", "3.13.0")
33+
gcp = tf.provider("google", "3.13.0")
3434

3535
# computed on list with MaxItem:1
3636
cluster = gcp.resource.container_cluster("foo")

0 commit comments

Comments
 (0)