【问题标题】:Convert Output<string> to string for AssumeRolePolicy将 Output<string> 转换为 AssumeRolePolicy 的字符串
【发布时间】:2021-02-20 01:41:23
【问题描述】:

我正在尝试使用 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 将输出转换为输入?

【问题讨论】:

  • 我对此不太熟悉,但正在尝试重现编译器错误。你使用什么亚马逊包和命名空间?

标签: f# pulumi


【解决方案1】:

有一个辅助函数io可以将输出转换为输入

AssumeRolePolicy = io adminRolePolicy

您需要引用Pulumi.FSharp NuGet 包。

参见io sourcea usage example

【讨论】:

  • 谢谢你的回答,我才发现。我会把你标记为答案!感谢您为我在 pulumi 网站上的文档中苦苦挣扎的链接提供了链接,但这并不总是很明显。
  • 顺便感谢您在 f# 降临日历中的帖子,这让我为我的宠物项目尝试了 pulumi...
  • 太棒了!随时在slack.pulumi.com 或推特上联系我,很高兴帮助另一个 F#-er。
猜你喜欢
  • 2020-11-22
  • 1970-01-01
  • 2020-10-15
  • 1970-01-01
  • 2018-11-14
  • 1970-01-01
  • 2014-05-16
  • 1970-01-01
  • 2021-04-21
相关资源
最近更新 更多