Skip to content

Commit

Permalink
Fix refresh on agent pools (#395)
Browse files Browse the repository at this point in the history
Fixes an issue where the AgentPool resource would lose the tokenValue
property on refresh. Also enables an existing example for agent pools
which would have highlighted the bug, but didn't because it wasn't
running :/

Fixes #379
  • Loading branch information
komalali authored Aug 26, 2024
1 parent 4af0df8 commit 08a172c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

- Fixes a bug where the `Environment` resource would print its contents on error. [#390](https://github.com/pulumi/pulumi-pulumiservice/pull/390)
- Fixes a bug where the `Environment` resource would error if a FileAsset was used. [#391](https://github.com/pulumi/pulumi-pulumiservice/pull/391)
- Fixes a bug where the `AgentPool` resource lost some outputs on `refresh`. [#395](https://github.com/pulumi/pulumi-pulumiservice/pull/395)

### Miscellaneous
14 changes: 14 additions & 0 deletions examples/examples_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@ func TestYamlEnvironmentsExample(t *testing.T) {
})
}

func TestYamlAgentPoolsExample(t *testing.T) {
cwd := getCwd(t)
digits := generateRandomFiveDigits()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: path.Join(cwd, ".", "yaml-agent-pools"),
Config: map[string]string{
"digits": digits,
},
PrepareProject: func(p *engine.Projinfo) error {
return nil
},
})
}

func TestYamlTemplateSourcesExample(t *testing.T) {
cwd := getCwd(t)
integration.ProgramTest(t, &integration.ProgramTestOptions{
Expand Down
2 changes: 1 addition & 1 deletion examples/yaml-agent-pools/Pulumi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resources:
type: pulumiservice:index:AgentPool
properties:
organizationName: service-provider-test-org
name: test-agent-pool
name: test-agent-pool-${digits}
description: Test agent pool

outputs:
Expand Down
4 changes: 2 additions & 2 deletions provider/pkg/internal/pulumiapi/agent_pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type AgentPoolClient interface {
type AgentPool struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Description string `json:"description,omitempty"`
TokenValue string `json:"tokenValue"`
}

Expand All @@ -42,7 +42,7 @@ type createAgentPoolResponse struct {

type createUpdateAgentPoolRequest struct {
Name string `json:"name"`
Description string `json:"description"`
Description string `json:"description,omitempty"`
}

func (c *Client) CreateAgentPool(ctx context.Context, orgName, name, description string) (*AgentPool, error) {
Expand Down
16 changes: 14 additions & 2 deletions provider/pkg/provider/agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ type PulumiServiceAgentPoolInput struct {
func GenerateAgentPoolProperties(input PulumiServiceAgentPoolInput, agentPool pulumiapi.AgentPool) (outputs *structpb.Struct, inputs *structpb.Struct, err error) {
inputMap := resource.PropertyMap{}
inputMap["name"] = resource.NewPropertyValue(input.Name)
inputMap["description"] = resource.NewPropertyValue(input.Description)
inputMap["organizationName"] = resource.NewPropertyValue(input.OrgName)
if input.Description != "" {
inputMap["description"] = resource.NewPropertyValue(input.Description)
}

outputMap := resource.PropertyMap{}
outputMap["agentPoolId"] = resource.NewPropertyValue(agentPool.ID)
outputMap["name"] = inputMap["name"]
outputMap["organizationName"] = inputMap["organizationName"]
outputMap["description"] = inputMap["description"]
outputMap["tokenValue"] = resource.NewPropertyValue(agentPool.TokenValue)
if input.Description != "" {
outputMap["description"] = inputMap["description"]
}

inputs, err = plugin.MarshalProperties(inputMap, plugin.MarshalOptions{})
if err != nil {
Expand Down Expand Up @@ -217,6 +221,14 @@ func (ap *PulumiServiceAgentPoolResource) Read(req *pulumirpc.ReadRequest) (*pul
return &pulumirpc.ReadResponse{}, nil
}

propertyMap, err := plugin.UnmarshalProperties(req.GetProperties(), plugin.MarshalOptions{KeepSecrets: true})
if err != nil {
return nil, err
}
if propertyMap["tokenValue"].HasValue() {
agentPool.TokenValue = getSecretOrStringValue(propertyMap["tokenValue"])
}

input := PulumiServiceAgentPoolInput{
OrgName: orgName,
Description: agentPool.Description,
Expand Down

0 comments on commit 08a172c

Please sign in to comment.