我正在尝试使用 F# 来了解 pulumi,但我无法理解如何将从一种资源发出的输出值最终使用到另一种资源中。这是我的具体案例:
let infra() =
let adminsName = "admins"
let current =
Output.Create<System.Threading.Tasks.Task<GetCallerIdentityResult>>(GetCallerIdentity.InvokeAsync()).Apply<GetCallerIdentityResult>(fun x->
x
|> Async.AwaitTask
|> Async.RunSynchronously
)
let adminRoleName = sprintf "%s-eksClusterAdmin" adminsName
let adminRolePolicy =
current.Apply(fun id ->
@"{
""Version"": ""2012-10-17"",
""Statement"": [
{
""Action"": ""sts:AssumeRole"",
""Principal"": {
""AWS"": ""arn:aws:iam::" + id.AccountId + @":root""
},
""Effect"": ""Allow"",
""Sid"": """"
}
]
}"
)
let adminsIamRole =
Role (adminRoleName,
RoleArgs(AssumeRolePolicy= (adminRolePolicy.Apply(fun x -> x)))
)
我尝试移植到 f# 的以下演练给了我很大的启发
https://www.pulumi.com/docs/guides/crosswalk/kubernetes/identity/#create-an-iam-role-for-admins
当前构建的项目告诉我:
iam.fs(47,45): error FS0001: The type 'Output<string>' is not compatible with the type 'Input<string>'
iam.fs(47,44): error FS0193: Type constraint mismatch. The type 'Output<string>' is not compatible with type 'Input<string>'
如何使用 pulumi 将输出转换为输入?
最佳答案
有一个辅助函数io
将输出转换为输入
AssumeRolePolicy = io adminRolePolicy
您需要引用Pulumi.FSharp
NuGet 包。
参见io
source和 a usage example .
关于f# - 将 Output<string> 转换为 AssumeRolePolicy 的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66281998/