/
githubmirror
/
terraform
Обзор
Документация
Войти
/
githubmirror
/
terraform
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
internal/lang/funcs/sensitive.go
83 строки
2 KB
Kristin Laemmert
funcs: pow() and log() no longer panic when result is NaN (#38912)
27 июл 2026, 22:06
Не верифицирован
27 июл 2026, 22:06
12f1c19
Код
Авторство
О чём код?
// Copyright IBM Corp. 2014, 2026 // SPDX-License-Identifier: BUSL-1.1 package funcs import ( "github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty/function" "github.com/hashicorp/terraform/internal/lang/marks" ) // SensitiveFunc returns a value identical to its argument except that // Terraform will consider it to be sensitive. var SensitiveFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "value", Type: cty.DynamicPseudoType, AllowUnknown: true, AllowNull: true, AllowMarked: true, AllowDynamicType: true, }, }, Type: func(args []cty.Value) (cty.Type, error) { // This function only affects the value's marks, so the result // type is always the same as the argument type. return args[0].Type(), nil }, Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { return args[0].Mark(marks.Sensitive), nil }, }) // NonsensitiveFunc takes a sensitive value and returns the same value without // the sensitive marking, effectively exposing the value. var NonsensitiveFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "value", Type: cty.DynamicPseudoType, AllowUnknown: true, AllowNull: true, AllowMarked: true, AllowDynamicType: true, }, }, Type: func(args []cty.Value) (cty.Type, error) { // This function only affects the value's marks, so the result // type is always the same as the argument type. return args[0].Type(), nil }, Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { v, m := args[0].Unmark() delete(m, marks.Sensitive) // remove the sensitive marking return v.WithMarks(m), nil }, }) var IssensitiveFunc = function.New(&function.Spec{ Params: []function.Parameter{{ Name: "value", Type: cty.DynamicPseudoType, AllowUnknown: true, AllowNull: true, AllowMarked: true, AllowDynamicType: true, }}, Type: func(args []cty.Value) (cty.Type, error) { return cty.Bool, nil }, Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { switch v := args[0]; { case marks.Has(v, marks.Sensitive): return cty.True, nil case !v.IsKnown(): return cty.UnknownVal(cty.Bool), nil default: return cty.False, nil } }, })