```package aks import ( "fmt" "<http://githu...
# golang
b
Copy code
package aks

import (
  "fmt"

  "<http://github.com/pulumi/pulumi-azure-native/sdk/go/azure/containerservice|github.com/pulumi/pulumi-azure-native/sdk/go/azure/containerservice>"
  "<http://github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core|github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core>"
  "<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

type Aks struct {
  pulumi.ResourceState
  resourceId pulumi.StringOutput
  name       pulumi.StringOutput
}

type AksArgs struct {
  EnableRBAC        pulumi.BoolInput
  ResourceName      pulumi.StringInput
  KubernetesVersion pulumi.StringInput
  NodeResourceGroup pulumi.StringInput
  ResourceGroup     pulumi.StringInput
  NodeCount         pulumi.IntInput
  Location          pulumi.StringInput
}

func CreateAks(ctx *pulumi.Context, name string, args *AksArgs, opts ...pulumi.ResourceOption) (*Aks, error) {
  aks := &Aks{}

  err := ctx.RegisterComponentResource("resource:index:Aks", name, aks, opts...)
  if err != nil {
    return nil, err
  }

  rgs, err := core.NewResourceGroup(ctx, "resourceGroups", &core.ResourceGroupArgs{
    Name:     args.ResourceGroup,
    Location: args.Location,
  }, pulumi.Parent(aks))

  if err != nil {
    return nil, fmt.Errorf("error creating resource group: %v", err)
  }

  k8s, err := containerservice.NewManagedCluster(ctx, "akss", &containerservice.ManagedClusterArgs{
    Location: rgs.Location,
    AgentPoolProfiles: containerservice.ManagedClusterAgentPoolProfileArray{
      &containerservice.ManagedClusterAgentPoolProfileArgs{
        Count:              args.NodeCount,
        EnableAutoScaling:  pulumi.Bool(false),
        EnableNodePublicIP: pulumi.Bool(true),
        Mode:               pulumi.String("System"),
        Name:               pulumi.String("default"),
        OsType:             pulumi.String("Linux"),
        Type:               pulumi.String("VirtualMachineScaleSets"),
        VmSize:             pulumi.String("Standard_B2s"),
      },
    },
    DnsPrefix:         pulumi.String("akss"),
    EnableRBAC:        args.EnableRBAC,
    Identity:          &containerservice.ManagedClusterIdentityArgs{Type: containerservice.ResourceIdentityTypeSystemAssigned},
    KubernetesVersion: args.KubernetesVersion,
    NodeResourceGroup: args.NodeResourceGroup,
    ResourceGroupName: rgs.Name,
    ResourceName:      args.ResourceName,
    Sku: &containerservice.ManagedClusterSKUArgs{
      Name: pulumi.String("Basic"),
      Tier: pulumi.String("Free"),
    },
  }, pulumi.Parent(rgs))

  if err != nil {
    return nil, fmt.Errorf("error creating cluster: %v", err)
  }

  ctx.RegisterResourceOutputs(aks, pulumi.Map{
    "resourceId": k8s.ID(),
    "name":       k8s.Name,
  })
  return aks, nil
}
q
you need to
ctx.Export()
them from your pulumi main function that uses your
NewAks
b
you have some sample somewhere?
@quiet-laptop-13439 if you want to use this output as input for another function you also should do this in the main function right?
q
no, you create a field in your Aks struct and access that field directly
e.g. aks, err := NewAks(...)
somethingElseArgs:= { AksId: aks.ID() }
if you want k8s.Name there, just create Name in Aks struct, and at the end of your NewAks assign
aks.Name = k8s.Name.ToStringOutput()
, or something similar
b
Also when i have two different pacackes? aks.go and acr.go are in different packages
In the main.go file i reference those functions
So if i want to use output between functions i can do this directly?
q
cant make too many assumptions about your package structure, but if you can pass outputs via args after assignment, similar to terraform
b
Yeah terraform is referencing outputs through main
b
b
@billowy-army-68599 the complete code is at https://github.com/dkooll/pulumi-go-webapp
Will have a look at your examples
my main question would be how to use for example something like a aks cluster ID as input in the ACR package with the current package structure using different functions and packages
resource components should be ok in this sample right?
@billowy-army-68599 you have some time to look? 😀
b
If I do it won't be for a couple days I'm afraid
b
@quiet-laptop-13439, @billowy-army-68599 i got a working output now using
Copy code
aksnames := k8s.Name.ApplyT(func(aksname string) string {
    return aksname
  }).(pulumi.StringOutput)

  aks.AksNames = aksnames

  if err := ctx.RegisterResourceOutputs(aks, pulumi.Map{
    "aksnames": aksnames,
  }); err != nil {
    return nil, err
  }

  ctx.Export("AksNames", aks.AksNames)
  return aks, nil
}
you have any idea how i get the id instead of the name
q
you dont need that applyt, it does nothing
b
ahk.. thanks.. according to the docs Id should be available as output
q
for id just do the same assignment
as for the name, just type is different
b
it give me a
k8s.Id undefined (type *containerservice.ManagedCluster has no field or method Id)
using
Copy code
aksnames := k8s.Id.ApplyT(func(aksname string) string {
    return aksname
  }).(pulumi.StringOutput)
am i missing something
q
im not following why did you do that
first, as i said, you dont need that applyt
id is k8s.ID()
b
can you provide a more complete sample to make this a output using component resources, cause this aint helping much
q
I'm on a phone
do you intend aksnames to be an array?
Copy code
aks.AksNames = k8s.Name
then
Copy code
aks.ResourceId := k8s.ID() // make sure Aks struct field is ResourceId
remove ctx.Export from the module, do it in main
Copy code
ctx.Export("k8s_resource_id", aks.ResourceId)
b
hmm thanks.. only getting a
expected identifier on left side of :=
on this one aks.ResourceId := k8s.ID()
for example
aks.ResourceState := k8s.State()
works, but
aks.ResourceId := k8s.ID()
gives me a
expected identifier on left side of :=
@quiet-laptop-13439 if i remove the semicolon i get a
cannot use k8s.ID() (value of type pulumi.IDOutput) as pulumi.StringOutput value in assignment
so this one works
aks.ResourceId = k8s.ID().ToStringOutput()
so this is working.. now how to pass this output which is in the aks package as input to a resource in the acr package?
do i have to pass this in my main function?