From 0474874b9436fa4bba1b83a34310399548a06fe1 Mon Sep 17 00:00:00 2001 From: Vitaly Antonenko Date: Wed, 28 Feb 2024 13:17:17 +0300 Subject: [PATCH] Changes Revision and Config order fix. And provides needed check in unittest. --- internal/juju/applications.go | 28 +++++++++---------- .../provider/resource_application_test.go | 4 ++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/internal/juju/applications.go b/internal/juju/applications.go index 75ad1d09..08f13350 100644 --- a/internal/juju/applications.go +++ b/internal/juju/applications.go @@ -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 { @@ -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 } diff --git a/internal/provider/resource_application_test.go b/internal/provider/resource_application_test.go index 867b688f..2da3ac37 100644 --- a/internal/provider/resource_application_test.go +++ b/internal/provider/resource_application_test.go @@ -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, @@ -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"), ), }, },