sparse-intern-71089
11/28/2022, 4:34 PMbillowy-army-68599
apply
- you need to invoke apply and interpolate in the correct place, there are examples here https://github.com/jaxxstorm/pulumi-examples/blob/main/typescript/aws/s3-cloudfront/index.ts#L50-L66lively-needle-84406
11/28/2022, 4:57 PMapply
example.
export const clusterAutoScalingPolicy = new aws.iam.Policy("clusterAutoScalingPolicy", {
policy: pulumi
.all([cluster.core.cluster.name])
.apply(([clusterName]) => {
JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Sid: "VisualEditor0",
Effect: "Allow",
Action: [
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup"
],
Resource: "*",
Condition: {
StringEquals: {
[clusterName]: "owned"
}
}
},
{
Sid: "VisualEditor1",
Effect: "Allow",
Action: [
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeAutoScalingGroups",
"ec2:DescribeLaunchTemplateVersions",
"autoscaling:DescribeTags",
"autoscaling:DescribeLaunchConfigurations"
],
Resource: "*"
}
]
})
})
}, {
dependsOn: [cluster]
});
I like this method, but the issue is that the policy argument for aws.iam.Policy
needs to be of type string | PolicyDocument
, But, the response of pulumi.all.apply
is of type OutputInstance<void>
. Any ideas of how to resolve the type conflict?billowy-army-68599
lively-needle-84406
11/28/2022, 6:00 PMerror: aws:iam/policy:Policy resource 'clusterAutoScalingPolicy' has a problem: Missing required argument: The argument "policy" is required, but no definition was found.. Examine values at 'Policy.Policy'.
Code:
export const clusterAutoScalingPolicy = new aws.iam.Policy("clusterAutoScalingPolicy", {
policy: pulumi
.all([cluster.core.cluster.name])
.apply(([clusterName]) => {
JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Sid: "VisualEditor0",
Effect: "Allow",
Action: [
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup"
],
Resource: "*",
Condition: {
StringEquals: {
[`aws:ResourceTag/k8s.io/cluster-autoscaler/${clusterName}`]: "owned"
}
}
},
{
Sid: "VisualEditor1",
Effect: "Allow",
Action: [
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeAutoScalingGroups",
"ec2:DescribeLaunchTemplateVersions",
"autoscaling:DescribeTags",
"autoscaling:DescribeLaunchConfigurations"
],
Resource: "*"
}
]
})
}) as unknown as aws.iam.PolicyDocument
}, {
dependsOn: [cluster]
});
lively-needle-84406
11/28/2022, 6:01 PMpolicy
value to unknown first because of this error:
Conversion of type 'OutputInstance<void>' to type 'PolicyDocument' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
lively-needle-84406
11/29/2022, 6:43 PMbillowy-army-68599
lively-needle-84406
12/05/2022, 4:12 PMbillowy-army-68599
const policyDoc = cluster.core.cluster.name.apply((name) =>
JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Sid: "VisualEditor0",
Effect: "Allow",
Action: [
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup",
],
Resource: "*",
Condition: {
StringEquals: {
[`aws:ResourceTag/k8s.io/cluster-autoscaler/${name}`]: "owned",
},
},
},
{
Sid: "VisualEditor1",
Effect: "Allow",
Action: [
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeAutoScalingGroups",
"ec2:DescribeLaunchTemplateVersions",
"autoscaling:DescribeTags",
"autoscaling:DescribeLaunchConfigurations",
],
Resource: "*",
},
],
})
);
export const clusterAutoScalingPolicy = new aws.iam.Policy(
"clusterAutoScalingPolicy",
{
policy: policyDoc,
}, {
dependsOn: [cluster],
}
);
No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by