Skip to content

Commit

Permalink
starlark: types, fix HCL int encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Apr 30, 2020
1 parent 6fc80cd commit 4225bbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions starlark/types/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ func appendTokensForValue(val starlark.Value, toks hclwrite.Tokens) hclwrite.Tok
Bytes: []byte(srcStr),
})
case starlark.Int:
bf := v.BigInt()
srcStr := bf.Text('2')
srcStr := fmt.Sprintf("%d", v)
toks = append(toks, &hclwrite.Token{
Type: hclsyntax.TokenNumberLit,
Bytes: []byte(srcStr),
Expand Down
12 changes: 12 additions & 0 deletions starlark/types/testdata/hcl.star
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ m.bucket = "main-storage"
m.role = "roles/storage.objectAdmin"
m.member = "serviceAccount:%s" % sa.email

addr = google.resource.compute_global_address("test")
addr.purpose = "VPC_PEERING"
addr.address_type = "INTERNAL"
addr.prefix_length = 16

# hcl with interpoaltion
assert.eq(hcl(google), "" +
'provider "google" {\n' + \
' alias = "default"\n' + \
' version = "3.16.0"\n' + \
'}\n' + \
'\n' + \
'resource "google_compute_global_address" "test" {\n' + \
' provider = google.default\n' + \
' address_type = "INTERNAL"\n' + \
' prefix_length = 16\n' + \
' purpose = "VPC_PEERING"\n' + \
'}\n' + \
'\n' + \
'resource "google_service_account" "sa" {\n' + \
' provider = google.default\n' + \
' account_id = "service-account"\n' + \
Expand Down

0 comments on commit 4225bbc

Please sign in to comment.