func parseBlueprintRoles()

in cli/bpmetadata/tfconfig.go [399:446]


func parseBlueprintRoles(rolesFile *hcl.File) ([]*BlueprintRoles, error) {
	var r []*BlueprintRoles
	iamContent, _, diags := rolesFile.Body.PartialContent(rootSchema)
	err := hasHclErrors(diags)
	if err != nil {
		return nil, err
	}

	for _, block := range iamContent.Blocks {
		if block.Type != "locals" {
			continue
		}

		iamAttrs, diags := block.Body.JustAttributes()
		err := hasHclErrors(diags)
		if err != nil {
			return nil, err
		}

		for k := range iamAttrs {
			var iamRoles []string
			attrValue, _ := iamAttrs[k].Expr.Value(nil)
			if !attrValue.Type().IsTupleType() {
				continue
			}

			ie := attrValue.ElementIterator()
			for ie.Next() {
				_, v := ie.Element()
				iamRoles = append(iamRoles, v.AsString())
			}

			containerRoles := &BlueprintRoles{
				// TODO: (b/248123274) no good way to associate granularity yet
				Level: "Project",
				Roles: iamRoles,
			}

			r = append(r, containerRoles)
		}

		// because we're only interested in the top-level locals block
		break
	}

	sortBlueprintRoles(r)
	return r, nil
}