https://pulumi.com logo
#golang
Title
# golang
e

early-oil-32855

05/31/2023, 3:44 PM
Hi everyone, anyone using Pulumi Go in combination with Azure Container Registry Tasks? It seems that
pulumi import
generates invalid Go code for us:
Copy code
package main

import (
	"<http://github.com/pulumi/pulumi-azure-native/sdk/go/azure/containerregistry|github.com/pulumi/pulumi-azure-native/sdk/go/azure/containerregistry>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := containerregistry.NewTask(ctx, "myTask", &containerregistry.TaskArgs{
			AgentConfiguration: &containerregistry.AgentPropertiesArgs{
				Cpu: <http://pulumi.Int|pulumi.Int>(2),
			},
			IsSystemTask: pulumi.Bool(false),
			Location:     pulumi.String("germanywestcentral"),
			Platform: &containerregistry.PlatformPropertiesArgs{
				Architecture: pulumi.String("amd64"),
				Os:           pulumi.String("linux"),
			},
			RegistryName:      pulumi.String("myRegistry"),
			ResourceGroupName: pulumi.String("myResourceGroup"),
			Status:            pulumi.String("Enabled"),
			Step: containerregistry.EncodedTaskStep{
				EncodedTaskContent: "dmVyc2lvbjogdjEuMS4wCnN0ZXBzOiAKICAtIGNtZDogYWNyIHB1cmdlIC0tYWdvIDkwZCAtLXVudGFnZ2VkCiAgICBkaXNhYmxlV29ya2luZ0RpcmVjdG9yeU92ZXJyaWRlOiB0cnVlCiAgICB0aW1lb3V0OiAzNjAwCg==",
				Type:               "EncodedTask",
			},
			TaskName: pulumi.String("myTask"),
			Timeout:  <http://pulumi.Int|pulumi.Int>(3600),
			Trigger: &containerregistry.TriggerPropertiesArgs{
				BaseImageTrigger: &containerregistry.BaseImageTriggerArgs{
					BaseImageTriggerType:     pulumi.String("Runtime"),
					Name:                     pulumi.String("defaultBaseimageTriggerName"),
					Status:                   pulumi.String("Enabled"),
					UpdateTriggerPayloadType: pulumi.String("Default"),
				},
				TimerTriggers: containerregistry.TimerTriggerArray{
					&containerregistry.TimerTriggerArgs{
						Name:     pulumi.String("t1"),
						Schedule: pulumi.String("0 0 * * 0"),
						Status:   pulumi.String("Enabled"),
					},
				},
			},
		}, pulumi.Protect(true))
		if err != nil {
			return err
		}
		return nil
	})
}
The problematic line is
Step: containerregistry.EncodedTaskStep{
where the Go compiler expects
pulumi.Input
instead. Is this a Go related bug perhaps? Also the API documentation suggests different types with non of them implement `pulumi.Input`: https://www.pulumi.com/registry/packages/azure-native/api-docs/containerregistry/task/#step_go Happy for any insights, thanks!
So I got a little further with following changes:
Copy code
package main

import (
	"<http://github.com/pulumi/pulumi-azure-native/sdk/go/azure/containerregistry|github.com/pulumi/pulumi-azure-native/sdk/go/azure/containerregistry>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := containerregistry.NewTask(ctx, "myTask", &containerregistry.TaskArgs{
			AgentConfiguration: &containerregistry.AgentPropertiesArgs{
				Cpu: <http://pulumi.Int|pulumi.Int>(2),
			},
			IsSystemTask: pulumi.Bool(false),
			Location:     pulumi.String("germanywestcentral"),
			Platform: &containerregistry.PlatformPropertiesArgs{
				Architecture: pulumi.String("amd64"),
				Os:           pulumi.String("linux"),
			},
			RegistryName:      pulumi.String("myRegistry"),
			ResourceGroupName: pulumi.String("myResourceGroup"),
			Status:            pulumi.String("Enabled"),
			Step: pulumi.Map{
				"EncodedTaskContent": pulumi.String("dmVyc2lvbjogdjEuMS4wCnN0ZXBzOiAKICAtIGNtZDogYWNyIHB1cmdlIC0tYWdvIDkwZCAtLXVudGFnZ2VkCiAgICBkaXNhYmxlV29ya2luZ0RpcmVjdG9yeU92ZXJyaWRlOiB0cnVlCiAgICB0aW1lb3V0OiAzNjAwCg=="),
				"Type":               pulumi.String("EncodedTask"),
			},
			TaskName: pulumi.String("myTask"),
			Timeout:  <http://pulumi.Int|pulumi.Int>(3600),
			Trigger: &containerregistry.TriggerPropertiesArgs{
				BaseImageTrigger: &containerregistry.BaseImageTriggerArgs{
					BaseImageTriggerType:     pulumi.String("Runtime"),
					Name:                     pulumi.String("defaultBaseimageTriggerName"),
					Status:                   pulumi.String("Enabled"),
					UpdateTriggerPayloadType: pulumi.String("Default"),
				},
				TimerTriggers: containerregistry.TimerTriggerArray{
					&containerregistry.TimerTriggerArgs{
						Name:     pulumi.String("t1"),
						Schedule: pulumi.String("0 0 * * 0"),
						Status:   pulumi.String("Enabled"),
					},
				},
			},
		}, pulumi.Protect(true))
		if err != nil {
			return err
		}
		return nil
	})
}
When passing
Step:
this way at least the Go compiler is not complaining about the type but when running:
Copy code
pulumi up --yes --skip-preview -v=9 --debug --logtostderr --logflow
I can observe in that the API call's payload is empty for `step:`:
Copy code
PUT /subscriptions/[redacted]/resourceGroups/[redacted]/providers/Microsoft.ContainerRegistry/registries/[redacted]/tasks/purge?api-version=2019-06-01-preview HTTP/1.1
    Host: <http://management.azure.com|management.azure.com>
    User-Agent: Go/go1.19.8 (amd64-linux) go-autorest/v14.2.1 pulumi-azure-native/1.102.0 pid-a90539d8-a7a6-5826-95c4-1fbef22d4b22
    Content-Length: 213
    Content-Type: application/json; charset=utf-8
    {"location":"germanywestcentral","properties":{"isSystemTask":false,"platform":{"architecture":"amd64","os":"Linux"},"step":{},"timeout":3600,"trigger":{"timerTriggers":[{"name":"purge","schedule":"0 0 * * 0"}]}}}
    ===================================================== HTTP Request End PUT <https://management.azure.com/subscriptions/[redacted]/resourceGroups/[redacted]/providers/Microsoft.ContainerRegistry/registries/[redacted]/tasks/purge?api-version=2019-06-01-preview>
    I0601 14:21:21.557388   33178 provider.go:1820] HTTP Response Begin PUT [<https://management.azure.com/subscriptions/[redacted]/resourceGroups/[redacted]/providers/Microsoft.ContainerRegistry/registries/[redacted]/tasks/purge?api-version=2019-06-01-preview> ===================================================
    HTTP/2.0 400 Bad Request
    Content-Length: 271
    Cache-Control: no-cache
    Content-Type: application/json; charset=utf-8
    Date: Thu, 01 Jun 2023 12:21:20 GMT
    Expires: -1
    Pragma: no-cache
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    X-Content-Type-Options: nosniff
    X-Ms-Correlation-Request-Id: cd0f9096-6d88-48bc-82d6-322f0fbec091
    X-Ms-Ratelimit-Remaining-Subscription-Writes: 1199
    X-Ms-Request-Id: 852082d4-7e98-4959-af45-e2e5c96c1f44
    X-Ms-Routing-Request-Id: GERMANYNORTH:20230601T122121Z:cd0f9096-6d88-48bc-82d6-322f0fbec091
    {"error":{"code":"InvalidRequestBody","message":"The request body is required for this request. Check if the body is not empty. If the request expects a polymorphic type, check if it has the discriminator property and is one of the described values.","target":"request"}}
    ===================================================== HTTP Response End PUT <https://management.azure.com/subscriptions/[redacted]/resourceGroups/[redacted]/providers/Microsoft.ContainerRegistry/registries/[redacted]/tasks/purge?api-version=2019-06-01-preview>
Finally found the solution after some digging and consulting the upstream docs (https://learn.microsoft.com/en-us/rest/api/containerregistry/tasks/create?tabs=HTTP#encodedtaskstep). Changing
Steps:
to the following did the trick:
Copy code
Step: pulumi.Map{
				"encodedTaskContent": pulumi.String("dmVyc2lvbjogdjEuMS4wCnN0ZXBzOiAKICAtIGNtZDogYWNyIHB1cmdlIC0tYWdvIDkwZCAtLXVudGFnZ2VkCiAgICBkaXNhYmxlV29ya2luZ0RpcmVjdG9yeU92ZXJyaWRlOiB0cnVlCiAgICB0aW1lb3V0OiAzNjAwCg=="),
				"type":               pulumi.String("EncodedTask"),
			},