sparse-intern-71089
08/11/2021, 1:00 PMbored-table-20691
08/11/2021, 2:12 PMfast-florist-41572
08/11/2021, 6:48 PMfunc main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Read in an array of accounts to create
accounts, err := getConfigAccounts()
organizations.NewAccount(ctx, name, &organizations.AccountArgs{
Email: pulumi.String(email),
}, pulumi.DependsOn([]pulumi.Resource{org}))
// Create accounts
var createdAccounts []*organizations.Account
for _, a := range accounts.Accounts {
account, err := organizations.NewAccount(ctx, a.Name, &organizations.AccountArgs{
Email: pulumi.String(a.Email),
}, pulumi.DependsOn([]pulumi.Resource{org}))
if err != nil {
return err
}
createdAccounts = append(createdAccounts, account)
}
// Create a policy for KMS
// TODO I need to be able to get all the accounts ids and pass them into a JSON.marshal for policy creation
return nil
})
}
fast-florist-41572
08/11/2021, 6:51 PMpulumi.Input
and using a pulumi.All
seemed to work. Now the KMS Policy is expecting a pulumi.StrInputPointer
and that doesn't seem to work with a pulumi.All
bored-table-20691
08/11/2021, 7:25 PMpulumi.All
on the createdAccounts
slide can you give back a StringOutput
- does that work? Or is it that you’re not sure how to take that type and pass it to something that wants a StrInputPointer?fast-florist-41572
08/11/2021, 7:25 PMfast-florist-41572
08/11/2021, 7:26 PMbored-table-20691
08/11/2021, 7:32 PMpulumi.All
would be a canonical way.bored-table-20691
08/11/2021, 7:32 PMfast-florist-41572
08/11/2021, 7:33 PMCannot use 'pulumi.All()' (type ArrayOutput) as the type pulumi.StringPtrInput Type does not implement 'pulumi.StringPtrInput' as some methods are missing: ToStringPtrOutput() StringPtrOutput ToStringPtrOutputWithContext(ctx context.Context) StringPtrOutput
fast-florist-41572
08/11/2021, 7:36 PMAny
and All
. All requires a variadic input and also I get stuck on passing in an arbitrary array in All
whilst Any
seems to resolve in Outputs
within. But I can't find good docs on itbored-table-20691
08/11/2021, 7:41 PMAll
usage look roughly like this:
https://github.com/pulumi/examples/blob/ca40203279f393c0c159dadcadc97c6007122997/aws-go-console-slack-notification/main.go#L119bored-table-20691
08/11/2021, 7:43 PMsomeOutput := pulumi.All(input1, input2, …).ApplyT(func(args []interface{}) string {
// do something with args and return a string
})
and then you’d use someOutput
(it’s type will be pulumi.Output, b ut you can cast it to pulumi.StringOutput
if you know it’s a stringbored-table-20691
08/11/2021, 7:43 PMfast-florist-41572
08/11/2021, 7:44 PMpulumi.All(bucket.Bucket, callerIdentity.AccountId)
bored-table-20691
08/11/2021, 7:44 PMpulumi.All(mySlice…)
bored-table-20691
08/11/2021, 7:45 PMfast-florist-41572
08/11/2021, 7:46 PMfast-florist-41572
08/11/2021, 7:46 PMbored-table-20691
08/11/2021, 7:46 PMfast-florist-41572
08/11/2021, 7:47 PMArrayOuputs
and array of Ouputs?bored-table-20691
08/11/2021, 7:48 PMfast-florist-41572
08/11/2021, 7:48 PMbored-table-20691
08/11/2021, 7:48 PMApplyT
takes a single []interface{} as its argumentbored-table-20691
08/11/2021, 7:48 PMbored-table-20691
08/11/2021, 7:49 PMfast-florist-41572
08/11/2021, 7:50 PMfast-florist-41572
08/11/2021, 7:50 PMbored-table-20691
08/11/2021, 7:51 PMfast-florist-41572
08/12/2021, 10:08 AMfunc CreateKMSPolicy(logAccount *organizations.Account, org *organizations.Organization, accountIds []pulumi.IDOutput) pulumi.StringOutput {
type Principal struct {
AWS []string `json:"AWS,omitempty"`
Service string `json:"Service,omitempty"`
}
type Condition struct {
StringEquals map[string][]string `json:"StringEquals,omitempty"`
}
type Statement struct {
Sid string `json:"Sid"`
Effect string `json:"Effect"`
Principal Principal `json:"Principal"`
Action []string `json:"Action"`
Resource string `json:"Resource"`
Condition *Condition `json:"Condition,omitempty"`
}
type KeyPolicy struct {
Version string `json:"Version"`
ID string `json:"Id"`
Statements []Statement `json:"Statement"`
}
var inputs []interface{}
inputs = append(inputs, logAccount.ID())
inputs = append(inputs, org.MasterAccountId)
for _, a := range accountIds {
inputs = append(inputs, a)
}
policy := pulumi.All(inputs...).ApplyT(func(args []interface{}) (string, error) {
logAccountId := args[0].(pulumi.ID)
masterAccId := args[1].(string)
var encryptCondition []string
encryptCondition = append(encryptCondition, fmt.Sprintf("arn:aws:cloudtrail:*:%s:trail/*", masterAccId))
for i := 2; i < len(args); i++ {
accId := args[i].(pulumi.ID)
encryptCondition = append(encryptCondition, fmt.Sprintf("arn:aws:cloudtrail:*:%s:trail/*", accId))
}
rawKeyPolicy := &KeyPolicy{
Version: "2012-10-17",
ID: "Key policy for CloudTrail",
Statements: []Statement{
{
Sid: "Enable IAM User Permissions",
Effect: "Allow",
Action: []string{
"kms:*",
},
Resource: "*",
Principal: Principal{
AWS: []string{
fmt.Sprintf("arn:aws:iam::%s:root", logAccountId),
},
},
},
{
Sid: "Enable CloudTrail Encrypt Permissions",
Effect: "Allow",
Action: []string{
"kms:GenerateDataKey*",
},
Resource: "*",
Principal: Principal{
Service: "<http://cloudtrail.amazonaws.com|cloudtrail.amazonaws.com>",
},
Condition: &Condition{
StringEquals: map[string][]string{
"kms:EncryptionContext:aws:cloudtrail:arn": encryptCondition,
},
},
},
{
Sid: "Allow CloudTrail to describe key",
Effect: "Allow",
Action: []string{
"kms:DescribeKey",
},
Resource: "*",
Principal: Principal{
Service: "<http://cloudtrail.amazonaws.com|cloudtrail.amazonaws.com>",
},
},
},
}
keyPolicy, err := json.Marshal(rawKeyPolicy)
return string(keyPolicy), err
}).(pulumi.StringOutput)
return policy
}
fast-florist-41572
08/12/2021, 10:10 AMbored-table-20691
08/12/2021, 3:41 PMbored-table-20691
08/12/2021, 3:42 PMNo 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