Created
June 25, 2020 07:18
-
-
Save EvanBoyle/3344dceb3f30b1c4022d5dfb84bb40df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reduntant type declarations in arrays: | |
package main | |
import ( | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
opt0 := true | |
opt1 := "^myami-\\d{3}" | |
_, err := aws.GetAmi(ctx, &aws.GetAmiArgs{ | |
ExecutableUsers: []string{ | |
"self", | |
}, | |
Filters: []aws.GetAmiFilter{ | |
aws.GetAmiFilter{ | |
Name: "name", | |
Values: []string{ | |
"myami-*", | |
}, | |
}, | |
aws.GetAmiFilter{ | |
Name: "root-device-type", | |
Values: []string{ | |
"ebs", | |
}, | |
}, | |
aws.GetAmiFilter{ | |
Name: "virtualization-type", | |
Values: []string{ | |
"hvm", | |
}, | |
}, | |
}, | |
MostRecent: &opt0, | |
NameRegex: &opt1, | |
Owners: []string{ | |
"self", | |
}, | |
}, nil) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} | |
long multi-line strings are a mess: | |
package main | |
import ( | |
"fmt" | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws" | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/s3" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
main, err := aws.GetBillingServiceAccount(ctx, nil, nil) | |
if err != nil { | |
return err | |
} | |
_, err = s3.NewBucket(ctx, "billingLogs", &s3.BucketArgs{ | |
Acl: pulumi.String("private"), | |
Policy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", " \"Id\": \"Policy\",\n", " \"Version\": \"2012-10-17\",\n", " \"Statement\": [\n", " {\n", " \"Action\": [\n", " \"s3:GetBucketAcl\", \"s3:GetBucketPolicy\"\n", " ],\n", " \"Effect\": \"Allow\",\n", " \"Resource\": \"arn:aws:s3:::my-billing-tf-test-bucket\",\n", " \"Principal\": {\n", " \"AWS\": [\n", " \"", main.Arn, "\"\n", " ]\n", " }\n", " },\n", " {\n", " \"Action\": [\n", " \"s3:PutObject\"\n", " ],\n", " \"Effect\": \"Allow\",\n", " \"Resource\": \"arn:aws:s3:::my-billing-tf-test-bucket/*\",\n", " \"Principal\": {\n", " \"AWS\": [\n", " \"", main.Arn, "\"\n", " ]\n", " }\n", " }\n", " ]\n", "}\n", "\n")), | |
}) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} | |
error trying to export prompt types returned from invoke calls | |
package main | |
import ( | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
current, err := aws.GetCallerIdentity(ctx, nil, nil) | |
if err != nil { | |
return err | |
} | |
ctx.Export("accountId", current.AccountId) | |
ctx.Export("callerArn", current.Arn) | |
ctx.Export("callerUser", current.UserId) | |
return nil | |
}) | |
} | |
no new vars on left side of := for _, err := | |
also, unexpectedly SID should be a *string even though the type not marked as optional | |
package main | |
import ( | |
"fmt" | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws" | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/iam" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
current, err := aws.GetPartition(ctx, nil, nil) | |
if err != nil { | |
return err | |
} | |
_, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{ | |
Statements: []iam.GetPolicyDocumentStatement{ | |
iam.GetPolicyDocumentStatement{ | |
Actions: []string{ | |
"s3:ListBucket", | |
}, | |
Resources: []string{ | |
fmt.Sprintf("%v%v%v", "arn:", current.Partition, ":s3:::my-bucket"), | |
}, | |
Sid: "1", | |
}, | |
}, | |
}, nil) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} | |
if the first statement is detected to be an unused var, we incorrectly omit := | |
package main | |
import ( | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/accessanalyzer" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
_, err = accessanalyzer.NewAnalyzer(ctx, "example", &accessanalyzer.AnalyzerArgs{ | |
AnalyzerName: pulumi.String("example"), | |
}) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} | |
Looks like tags recently changed from pulumi.Map to pulumi.StringMap | |
https://github.com/pulumi/pulumi-aws/blame/a9a2c4fa78bd695a201fd3a2219411caf7cbef3a/sdk/go/aws/mediapackage/channel.go#L52 | |
package main | |
import ( | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/acm" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
_, err = acm.NewCertificate(ctx, "cert", &acm.CertificateArgs{ | |
DomainName: pulumi.String("example.com"), | |
Tags: pulumi.Map{ | |
"Environment": pulumi.String("test"), | |
}, | |
ValidationMethod: pulumi.String("DNS"), | |
}) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} | |
another example of the general case of using := properly for first time var decl. | |
we should probably keep a map of LHS for var decl to determine if we've already | |
instantiated this particular combo: | |
package main | |
import ( | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/apigateway" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
myRestApi, err := apigateway.LookupRestApi(ctx, &apigateway.LookupRestApiArgs{ | |
Name: "my-rest-api", | |
}, nil) | |
if err != nil { | |
return err | |
} | |
_, err := apigateway.LookupResource(ctx, &apigateway.LookupResourceArgs{ | |
Path: "/endpoint/path", | |
RestApiId: myRestApi.Id, | |
}, nil) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} | |
the default type of map object seems to be pulumi.StringMap: | |
package main | |
import ( | |
"fmt" | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/apigateway" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
myDemoAPI, err := apigateway.NewRestApi(ctx, "myDemoAPI", &apigateway.RestApiArgs{ | |
Description: pulumi.String("This is my API for demonstration purposes"), | |
}) | |
if err != nil { | |
return err | |
} | |
myDemoResource, err := apigateway.NewResource(ctx, "myDemoResource", &apigateway.ResourceArgs{ | |
ParentId: myDemoAPI.RootResourceId, | |
PathPart: pulumi.String("mydemoresource"), | |
RestApi: myDemoAPI.ID(), | |
}) | |
if err != nil { | |
return err | |
} | |
myDemoMethod, err := apigateway.NewMethod(ctx, "myDemoMethod", &apigateway.MethodArgs{ | |
Authorization: pulumi.String("NONE"), | |
HttpMethod: pulumi.String("GET"), | |
ResourceId: myDemoResource.ID(), | |
RestApi: myDemoAPI.ID(), | |
}) | |
if err != nil { | |
return err | |
} | |
_, err = apigateway.NewIntegration(ctx, "myDemoIntegration", &apigateway.IntegrationArgs{ | |
CacheKeyParameters: pulumi.StringArray{ | |
pulumi.String("method.request.path.param"), | |
}, | |
CacheNamespace: pulumi.String("foobar"), | |
HttpMethod: myDemoMethod.HttpMethod, | |
RequestParameters: pulumi.Map{ | |
"integration.request.header.X-Authorization": pulumi.String("'static'"), | |
}, | |
RequestTemplates: pulumi.Map{ | |
"application/xml": pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v", "{\n", " \"body\" : ", "$", "input.json('", "$", "')\n", "}\n", "\n")), | |
}, | |
ResourceId: myDemoResource.ID(), | |
RestApi: myDemoAPI.ID(), | |
TimeoutMilliseconds: pulumi.Int(29000), | |
Type: pulumi.String("MOCK"), | |
}) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} | |
pulumi.Map where pulumi.BoolMap is expected: | |
package main | |
import ( | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/apigateway" | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/cognito" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
thisUserPools, err := cognito.GetUserPools(ctx, &cognito.GetUserPoolsArgs{ | |
Name: cognitoUserPoolName, | |
}, nil) | |
if err != nil { | |
return err | |
} | |
thisRestApi, err := apigateway.NewRestApi(ctx, "thisRestApi", nil) | |
if err != nil { | |
return err | |
} | |
thisResource, err := apigateway.NewResource(ctx, "thisResource", &apigateway.ResourceArgs{ | |
ParentId: thisRestApi.RootResourceId, | |
PathPart: pulumi.String("{proxy+}"), | |
RestApi: thisRestApi.ID(), | |
}) | |
if err != nil { | |
return err | |
} | |
thisAuthorizer, err := apigateway.NewAuthorizer(ctx, "thisAuthorizer", &apigateway.AuthorizerArgs{ | |
ProviderArns: toPulumiStringArray(thisUserPools.Arns), | |
RestApi: thisRestApi.ID(), | |
Type: pulumi.String("COGNITO_USER_POOLS"), | |
}) | |
if err != nil { | |
return err | |
} | |
_, err = apigateway.NewMethod(ctx, "any", &apigateway.MethodArgs{ | |
Authorization: pulumi.String("COGNITO_USER_POOLS"), | |
AuthorizerId: thisAuthorizer.ID(), | |
HttpMethod: pulumi.String("ANY"), | |
RequestParameters: pulumi.Map{ | |
"method.request.path.proxy": pulumi.Bool(true), | |
}, | |
ResourceId: thisResource.ID(), | |
RestApi: thisRestApi.ID(), | |
}) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} | |
func toPulumiStringArray(arr []string) pulumi.StringArray { | |
var pulumiArr pulumi.StringArray | |
for _, v := range arr { | |
pulumiArr = append(pulumiArr, pulumi.String(v)) | |
} | |
return pulumiArr | |
} | |
fairly simple example for pulumi.StringMap typing: | |
package main | |
import ( | |
"fmt" | |
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/apigateway" | |
"github.com/pulumi/pulumi/sdk/v2/go/pulumi" | |
) | |
func main() { | |
pulumi.Run(func(ctx *pulumi.Context) error { | |
main, err := apigateway.NewRestApi(ctx, "main", nil) | |
if err != nil { | |
return err | |
} | |
_, err = apigateway.NewResponse(ctx, "test", &apigateway.ResponseArgs{ | |
ResponseParameters: pulumi.Map{ | |
"gatewayresponse.header.Authorization": pulumi.String("'Basic'"), | |
}, | |
ResponseTemplates: pulumi.Map{ | |
"application/json": pulumi.String(fmt.Sprintf("%v%v%v", "{'message':", "$", "context.error.messageString}")), | |
}, | |
ResponseType: pulumi.String("UNAUTHORIZED"), | |
RestApiId: main.ID(), | |
StatusCode: pulumi.String("401"), | |
}) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment