Skip to content

Commit

Permalink
Changes Revision and Config order fix. And provides needed check in
Browse files Browse the repository at this point in the history
unittest.
  • Loading branch information
anvial committed Feb 28, 2024
1 parent 3d3d4a3 commit 0474874
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
28 changes: 14 additions & 14 deletions internal/juju/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,20 @@ func (c applicationsClient) UpdateApplication(input *UpdateApplicationInput) err
return fmt.Errorf("no status returned for application: %s", input.AppName)
}

// Use the revision and channel info to create the
// corresponding SetCharm info.
if input.Revision != nil || input.Channel != "" {
setCharmConfig, err := c.computeSetCharmConfig(input, applicationAPIClient, charmsAPIClient, resourcesAPIClient)
if err != nil {
return err
}

err = applicationAPIClient.SetCharm(model.GenerationMaster, *setCharmConfig)
if err != nil {
return err
}
}

// process configuration
var auxConfig map[string]string
if input.Config != nil {
Expand Down Expand Up @@ -1020,20 +1034,6 @@ func (c applicationsClient) UpdateApplication(input *UpdateApplicationInput) err
}
}

// Use the revision and channel info to create the
// corresponding SetCharm info.
if input.Revision != nil || input.Channel != "" {
setCharmConfig, err := c.computeSetCharmConfig(input, applicationAPIClient, charmsAPIClient, resourcesAPIClient)
if err != nil {
return err
}

err = applicationAPIClient.SetCharm(model.GenerationMaster, *setCharmConfig)
if err != nil {
return err
}
}

return nil
}

Expand Down
4 changes: 3 additions & 1 deletion internal/provider/resource_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func TestAcc_ResourceApplication_UpdatesRevisionConfig(t *testing.T) {
}
modelName := acctest.RandomWithPrefix("tf-test-application")
appName := "github-runner"
configParamName := "runner-storage"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: frameworkProviderFactories,
Expand All @@ -161,9 +162,10 @@ func TestAcc_ResourceApplication_UpdatesRevisionConfig(t *testing.T) {
),
},
{
Config: testAccResourceApplicationWithRevisionAndConfig(modelName, appName, 95, ""),
Config: testAccResourceApplicationWithRevisionAndConfig(modelName, appName, 95, configParamName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("juju_application."+appName, "charm.0.revision", "95"),
resource.TestCheckResourceAttr("juju_application."+appName, "config."+configParamName, configParamName+"-value"),
),
},
},
Expand Down

0 comments on commit 0474874

Please sign in to comment.