Skip to content

Commit

Permalink
Merge pull request #94 from hrmsk66/hrmsk66/output-block
Browse files Browse the repository at this point in the history
Add output block for Fastly service URL
  • Loading branch information
hrmsk66 authored Apr 7, 2024
2 parents 3bbc344 + afaa524 commit 9d6b31d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/tfconf/tfconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ func (tfconf *TFConf) RewriteResources(serviceProp prop.TFBlock, props []prop.TF
}
}

// Append output block
appendOutputBlock(tfconf, serviceProp)

return sensitiveAttrs, nil
}

Expand Down Expand Up @@ -909,6 +912,12 @@ func rewriteWAFResource(block *hclwrite.Block, serviceProp prop.TFBlock) error {
return nil
}

func appendOutputBlock(tfconf *TFConf, serviceProp prop.TFBlock) {
tfconf.Body().AppendNewline()
p := tfconf.Body().AppendNewBlock("output", []string{"fastly_service_url"})
p.Body().SetAttributeRaw("value", buildServiceURL(serviceProp))
}

func appendFastlyPackageHashBlock(tfconf *TFConf, serviceProp prop.TFBlock, config *cli.Config) {
tfconf.Body().AppendNewline()
p := tfconf.Body().AppendNewBlock("data", []string{"fastly_package_hash", serviceProp.GetNormalizedName()})
Expand Down Expand Up @@ -1023,6 +1032,16 @@ func buildServiceIDRef(serviceProp prop.TFBlock) hcl.Traversal {
}
}

func buildServiceURL(serviceProp prop.TFBlock) hclwrite.Tokens {
return hclwrite.Tokens{
{Type: hclsyntax.TokenOQuote, Bytes: []byte{'"'}},
{Type: hclsyntax.TokenStringLit, Bytes: []byte("https://cfg.fastly.com/${")},
{Type: hclsyntax.TokenStringLit, Bytes: []byte(serviceProp.GetRef())},
{Type: hclsyntax.TokenStringLit, Bytes: []byte(".id}")},
{Type: hclsyntax.TokenCQuote, Bytes: []byte{'"'}},
}
}

func buildVariableRef(varName string) hcl.Traversal {
return hcl.Traversal{
hcl.TraverseRoot{Name: "var"},
Expand Down

0 comments on commit 9d6b31d

Please sign in to comment.