https://pulumi.com logo
#general
Title
# general
s

sparse-knife-40442

09/19/2022, 8:00 PM
Hello Pulumi community, Im creating DNS records and zones using pulumi cloudflare provider, im getting an issue when trying to get the zone Id output as an input for my record creation, something very simple like
Copy code
func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		conf := config.New(ctx, "")
		accountID := conf.Require("accountId")
		
		zone, err := cloudflare.NewZone(ctx, "<http://zone.io|zone.io>", &cloudflare.ZoneArgs{
			AccountId: pulumi.String(accountID),
			Plan:      pulumi.String("free"),
			Zone:      pulumi.String("<http://zone.io|zone.io>"),
		}, pulumi.Protect(true))
		if err != nil {
			return err
		}
		_, err := cloudflare.NewRecord(ctx, "test_record", &cloudflare.RecordArgs{
			ZoneId: zone.Id,
			Name:    pulumi.String("test"),
			Value:   pulumi.String("0.0.0.0"),
			Type:    pulumi.String("A"),
			Ttl:     <http://pulumi.Int|pulumi.Int>(1),
			Proxied: pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		return nil
	})

}
Im constantly getting the error
./main.go:56:21: zone.Id undefined (type *cloudflare.Zone has no field or method Id)
But as per provider documentation the Id output actually exists and if I change Zone.Id for another output like zone.Status it works , Could this be a provider bug or am I doing something wrong?
b

billowy-army-68599

09/19/2022, 8:08 PM
zone.ID()
s

sparse-knife-40442

09/19/2022, 8:11 PM
Have tried that but it results into another issue
Copy code
/main.go:56:16: cannot use zone.ID (value of type func() pulumi.IDOutput) as type pulumi.StringInput in struct literal:
        func() pulumi.IDOutput does not implement pulumi.StringInput (missing ElementType method)
b

billowy-army-68599

09/19/2022, 8:19 PM
This compiles for me
Copy code
zone, err := cloudflare.NewZone(ctx, "<http://zone.io|zone.io>", &cloudflare.ZoneArgs{
			AccountId: pulumi.String("foo"),
			Plan:      pulumi.String("free"),
			Zone:      pulumi.String("<http://leebriggs.io|leebriggs.io>"),
		})
		if err != nil {
			return err
		}

		record, err := cloudflare.NewRecord(ctx, "test_record", &cloudflare.RecordArgs{
			ZoneId:  zone.ID(),
			Name:    pulumi.String("test"),
			Value:   pulumi.String("0.0.0.0"),
			Type:    pulumi.String("A"),
			Ttl:     <http://pulumi.Int|pulumi.Int>(1),
			Proxied: pulumi.Bool(true),
		})
I think you’re missing the func return, so you’re passing
zone.ID
instead of
zone.ID()
s

sparse-knife-40442

09/19/2022, 8:22 PM
You right, works now! Thanks for your help, appreciate it
b

billowy-army-68599

09/19/2022, 8:25 PM
if you aren’t using an IDE like vscode, it’ll really help you catch errors like this and fix them automatically
s

sparse-knife-40442

09/19/2022, 8:29 PM
Cool, is that a pulumi extension for Vscode¿
b

billowy-army-68599

09/19/2022, 8:30 PM
it’s just the standard Go extension
👍 1
3 Views