Skip to content

Commit

Permalink
Changed module generation to enable unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jetvova committed Aug 12, 2022
1 parent 187cc77 commit cfb9121
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions pkg/tf2pulumi/convert/tf12.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ type resource struct {
rangeVariable *model.Variable
isCounted bool
isConditional bool
isModule bool

block *model.Block
}
Expand Down Expand Up @@ -417,19 +418,11 @@ func (b *tf12binder) declareFile(input *syntax.File) (*file, hcl.Diagnostics) {
variableType = model.NewListType(terraformType)
}

// The source attribute serves the same "package" role that ordinary resource tokens do.
// Obtaining and saving source path for easy access in the future.
firstSourceExpression := item.Body.Attributes["source"].Expr.(*hclsyntax.TemplateExpr)
secondSourceExpression := firstSourceExpression.Parts[0].(*hclsyntax.LiteralValueExpr)
sourcePath := secondSourceExpression.Val.AsString()

// Ignoring the source attribute so that it doesn't get processed during code generation
delete(item.Body.Attributes, "source")

r := &resource{
isModule: true,
syntax: item,
name: item.Labels[0],
token: sourcePath,
token: "Terraform Child Module",
terraformType: terraformType,
variableType: variableType,
}
Expand Down Expand Up @@ -1612,7 +1605,10 @@ func (b *tf12binder) genResource(w io.Writer, r *resource) hcl.Diagnostics {

item := model.BodyItem(r.block)
if !r.isDataSource {
r.block.Labels = []string{r.pulumiName, r.token}
r.block.Labels = []string{r.pulumiName}
if !r.isModule {
r.block.Labels = append(r.block.Labels, r.token)
}

if r.isConditional {
options := r.block.Body.Blocks("options")[0]
Expand Down

0 comments on commit cfb9121

Please sign in to comment.