This message was deleted.
# getting-started
s
This message was deleted.
b
lease share your code
s
This is the component, the rest of the code is as the template at https://github.com/pulumi/pulumi-component-provider-go-boilerplate
Copy code
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     <http://www.apache.org/licenses/LICENSE-2.0>
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package provider

import (
	helmv3 "<http://github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/helm/v3|github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/helm/v3>"
	"<http://github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml|github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

// GrafanaAgentArgs : The set of arguments for creating a GrafanaAgent component resource.
type GrafanaAgentArgs struct {
	// Namespace for the agent deployment
	Namespace pulumi.StringInput `pulumi:"namespace"`
	Name      pulumi.StringInput `pulumi:"name"`
}

// The GrafanaAgent component resource.
type GrafanaAgent struct {
	pulumi.ResourceState

	Agent       pulumi.Output
	Operator    pulumi.Output
	BaseMetrics pulumi.Output
}

// NewGrafanaAgent creates a new GrafanaAgent component resource.
func NewGrafanaAgent(ctx *pulumi.Context,
	name string, args *GrafanaAgentArgs, opts ...pulumi.ResourceOption) (*GrafanaAgent, error) {
	if args == nil {
		args = &GrafanaAgentArgs{Namespace: pulumi.String("default")}
	} else {
		if ns, ok := args.Namespace.(pulumi.String); ok {
			if len(ns) == 0 {
				args.Namespace = pulumi.String("default")
			}
		}
	}

	ctx.Log.Debug("register component", &pulumi.LogArgs{})
	component := &GrafanaAgent{}
	err := ctx.RegisterComponentResource("observers:index:GrafanaAgent", name, component, opts...)
	if err != nil {
		return nil, err
	}

	operator, err := helmv3.NewChart(ctx, "grafana-agent-operator", helmv3.ChartArgs{
		Repo:      pulumi.String("grafana"),
		Chart:     pulumi.String("grafana-agent-operator"),
		Namespace: args.Namespace,
		FetchArgs: helmv3.FetchArgs{
			Repo: pulumi.String("<https://grafana.github.io/helm-charts>"),
		},
	}, append([]pulumi.ResourceOption{pulumi.Parent(component)}, opts...)...)
	if err != nil {
		return nil, err
	}

	agent, err := yaml.NewConfigFile(ctx, "grafana-agent", &yaml.ConfigFileArgs{
		File: "guestbook-all-in-one.yaml",
		Transformations: []yaml.Transformation{
			func(state map[string]interface{}, opts ...pulumi.ResourceOption) {
				state["spec"].(map[string]interface{})["prometheus"].(map[string]interface{})["externalLabels"].(map[string]interface{})["cloud_project"] = args.Name
			},
		},
	}, append([]pulumi.ResourceOption{pulumi.Parent(component), pulumi.DependsOn([]pulumi.Resource{operator})}, opts...)...)
	if err != nil {
		return nil, err
	}

	baseMetrics, err := helmv3.NewChart(ctx, "kube-state-metrics", helmv3.ChartArgs{
		Repo:      pulumi.String("prometheus-community"),
		Chart:     pulumi.String("kube-state-metrics"),
		Namespace: args.Namespace,
		FetchArgs: helmv3.FetchArgs{
			Repo: pulumi.String("<https://prometheus-community.github.io/helm-charts>"),
		},
	}, append([]pulumi.ResourceOption{pulumi.Parent(component), pulumi.DependsOn([]pulumi.Resource{operator})}, opts...)...)
	if err != nil {
		return nil, err
	}

	ctx.Log.Debug("get operator resource", &pulumi.LogArgs{})
	operatorResource := args.Namespace.ToStringOutput().ApplyT(func(ns string) pulumi.Output {
		return operator.GetResource("apps/v1/Deployment", "grafana-agent-operator", ns)
	})
	ctx.Log.Debug("get agent resource", &pulumi.LogArgs{})
	agentResource := args.Namespace.ToStringOutput().ApplyT(func(ns string) pulumi.Resource {
		return agent.GetResource("<http://monitoring.grafana.com/v1alpha1/GrafanaAgent|monitoring.grafana.com/v1alpha1/GrafanaAgent>", "grafana-agent", ns)
	})
	ctx.Log.Debug("get base metrics resource", &pulumi.LogArgs{})
	baseMetricsResource := args.Namespace.ToStringOutput().ApplyT(func(ns string) pulumi.Output {
		return baseMetrics.GetResource("<http://monitoring.coreos.com/v1/ServiceMonitor|monitoring.coreos.com/v1/ServiceMonitor>", "kube-state-metrics", ns)
	})
	ctx.Log.Debug("got all resources", &pulumi.LogArgs{})

	component.Agent = agentResource
	component.Operator = operatorResource
	component.BaseMetrics = baseMetricsResource
	ctx.Log.Debug("before registering output", &pulumi.LogArgs{})
	if err := ctx.RegisterResourceOutputs(component, pulumi.Map{
		"agent":       agentResource,
		"operator":    operatorResource,
		"baseMetrics": baseMetricsResource,
	}); err != nil {
		return nil, err
	}
	ctx.Log.Debug("after registering output", &pulumi.LogArgs{})

	return component, nil
}
b
Ah I see, it's hard to tell from here, but these types don't look correct to me:
Copy code
Agent       pulumi.Output
	Operator    pulumi.Output
	BaseMetrics pulumi.Output
s
I tried removing all of them
and still got the same error
none of the debug messages are ever printed
@billowy-army-68599 thanks for your support, I've found the problem. It was my mistake, I was updating the provider, but not publishing it, so I kept testing with the same version having all of those abstract output properties
and you're right it's the abstract properties the problem
b
awesome! if you need help getting this into the reigstry when it's done, let me know!
1
s
Hi @billowy-army-68599, I'd love to have this into "a" registry, I'm not sure it'd be ok for my company to put it in a public one. Is there a way to distribute the package/provider using a private registry?