diff --git a/docs/resources/application.md b/docs/resources/application.md index aa695e3d..aadb1d7f 100644 --- a/docs/resources/application.md +++ b/docs/resources/application.md @@ -19,30 +19,14 @@ resource "juju_application" "this" { model = juju_model.development.name charm { - name = "hello-kubecon" + name = "ubuntu" channel = "edge" - revision = 14 + revision = 24 series = "trusty" } units = 3 - config = { - external-hostname = "..." - } -} - -resource "juju_application" "placement_and_storage_example" { - name = "placement-example" - model = juju_model.development.name - charm { - name = "hello-kubecon" - channel = "edge" - revision = 14 - series = "trusty" - } - - units = 3 placement = "0,1,2" storage = { @@ -83,7 +67,7 @@ resource "juju_application" "placement_and_storage_example" { * If the charm revision or channel are not updated, then no changes will take place (juju does not have an "un-attach" command for resources). - `storage` (Attributes Set) Storage used by the application. (see [below for nested schema](#nestedatt--storage)) -- `storage_directives` (Map of String) Storage directives (constraints) for the juju application. The map key is the label of the storage defined by the charm, the map value is the storage directive in the form ,,. +- `storage_directives` (Map of String) Storage directives (constraints) for the juju application. The map key is the label of the storage defined by the charm, the map value is the storage directive in the form ,,. Changing an existing key/value pair will cause the application to be replaced. Adding a new key/value pair will add storage to the application on upgrade. - `trust` (Boolean) Set the trust for the application. - `units` (Number) The number of application units to deploy for the charm. @@ -136,7 +120,7 @@ Read-Only: - `count` (Number) The number of volumes. - `label` (String) The specific storage option defined in the charm. -- `pool` (String) Name of the storage pool to use. +- `pool` (String) Name of the storage pool. - `size` (String) The size of each volume. ## Import diff --git a/examples/resources/juju_application/resource.tf b/examples/resources/juju_application/resource.tf index c3039b12..bd0198fc 100644 --- a/examples/resources/juju_application/resource.tf +++ b/examples/resources/juju_application/resource.tf @@ -4,30 +4,14 @@ resource "juju_application" "this" { model = juju_model.development.name charm { - name = "hello-kubecon" + name = "ubuntu" channel = "edge" - revision = 14 + revision = 24 series = "trusty" } units = 3 - config = { - external-hostname = "..." - } -} - -resource "juju_application" "placement_and_storage_example" { - name = "placement-example" - model = juju_model.development.name - charm { - name = "hello-kubecon" - channel = "edge" - revision = 14 - series = "trusty" - } - - units = 3 placement = "0,1,2" storage = { diff --git a/internal/juju/applications.go b/internal/juju/applications.go index 7daa5b1a..c8ba9813 100644 --- a/internal/juju/applications.go +++ b/internal/juju/applications.go @@ -335,9 +335,6 @@ func (c applicationsClient) CreateApplication(ctx context.Context, input *Create return nil, err } - // print transformedInput.storage - c.Tracef("transformedInput.storage", map[string]interface{}{"transformedInput.storage": transformedInput.storage}) - applicationAPIClient := apiapplication.NewClient(conn) if applicationAPIClient.BestAPIVersion() >= 19 { err = c.deployFromRepository(applicationAPIClient, transformedInput) @@ -782,14 +779,14 @@ func (c applicationsClient) ReadApplicationWithRetryOnNotFound(ctx context.Conte return fmt.Errorf("ReadApplicationWithRetryOnNotFound: need %d machines, have %d", output.Units, len(machines)) } - // NOTE: Application can always have storage. However, they + // NOTE: Applications can always have storage. However, they // will not be listed right after the application is created. So - // we need to wait for the storages to be ready. And we need to + // we need to wait for the storage to be ready. And we need to // check if all storage constraints have pool equal "" and size equal 0 // to drop the error. for _, storage := range output.Storage { if storage.Pool == "" || storage.Size == 0 { - return fmt.Errorf("ReadApplicationWithRetryOnNotFound: no storages found in output") + return fmt.Errorf("ReadApplicationWithRetryOnNotFound: no storage found in output") } } @@ -832,8 +829,8 @@ func transformToStorageConstraints( case "filesystem": for _, fd := range filesystemDetailsSlice { if fd.Storage.StorageTag == storageDetails.StorageTag { - // Cut 'storage-' prefix from the storage tag and `-NUMBER` suffix - storageLabel := getStorageLabel(storageDetails) + // Cut PrefixStorage from the storage tag and `-NUMBER` suffix + storageLabel := getStorageLabel(storageDetails.StorageTag) storageCounters[storageLabel]++ storage[storageLabel] = jujustorage.Constraints{ Pool: fd.Info.Pool, @@ -845,7 +842,7 @@ func transformToStorageConstraints( case "block": for _, vd := range volumeDetailsSlice { if vd.Storage.StorageTag == storageDetails.StorageTag { - storageLabel := getStorageLabel(storageDetails) + storageLabel := getStorageLabel(storageDetails.StorageTag) storageCounters[storageLabel]++ storage[storageLabel] = jujustorage.Constraints{ Pool: vd.Info.Pool, @@ -859,8 +856,8 @@ func transformToStorageConstraints( return storage } -func getStorageLabel(storageDetails params.StorageDetails) string { - return strings.TrimSuffix(strings.TrimPrefix(storageDetails.StorageTag, "storage-"), "-0") +func getStorageLabel(storageTag string) string { + return strings.TrimSuffix(strings.TrimPrefix(storageTag, PrefixStorage), "-0") } func (c applicationsClient) ReadApplication(input *ReadApplicationInput) (*ReadApplicationResponse, error) { @@ -916,10 +913,6 @@ func (c applicationsClient) ReadApplication(input *ReadApplicationInput) (*ReadA } storages := transformToStorageConstraints(status.Storage, status.Filesystems, status.Volumes) - // Print storage to console - for k, v := range storages { - c.Tracef("StorageConstraints constraints", map[string]interface{}{"storage": k, "constraints": v}) - } allocatedMachines := set.NewStrings() for _, v := range appStatus.Units { diff --git a/internal/juju/client.go b/internal/juju/client.go index 9128ce78..807559eb 100644 --- a/internal/juju/client.go +++ b/internal/juju/client.go @@ -25,6 +25,7 @@ const ( PrefixUser = "user-" PrefixMachine = "machine-" PrefixApplication = "application-" + PrefixStorage = "storage-" UnspecifiedRevision = -1 connectionTimeout = 30 * time.Second ) diff --git a/internal/provider/resource_application.go b/internal/provider/resource_application.go index fe9dae9f..cf885ad0 100644 --- a/internal/provider/resource_application.go +++ b/internal/provider/resource_application.go @@ -170,9 +170,11 @@ func (r *applicationResource) Schema(_ context.Context, _ resource.SchemaRequest }, }, "storage_directives": schema.MapAttribute{ - Description: "Storage directives (constraints) for the juju application. " + - "The map key is the label of the storage defined by the charm, " + - "the map value is the storage directive in the form ,,.", + Description: "Storage directives (constraints) for the juju application." + + " The map key is the label of the storage defined by the charm," + + " the map value is the storage directive in the form ,,." + + " Changing an existing key/value pair will cause the application to be replaced." + + " Adding a new key/value pair will add storage to the application on upgrade.", ElementType: types.StringType, Optional: true, Validators: []validator.Map{ @@ -197,7 +199,7 @@ func (r *applicationResource) Schema(_ context.Context, _ resource.SchemaRequest Computed: true, }, "pool": schema.StringAttribute{ - Description: "Name of the storage pool to use.", + Description: "Name of the storage pool.", Computed: true, }, "count": schema.Int64Attribute{ diff --git a/internal/provider/resource_application_test.go b/internal/provider/resource_application_test.go index 1ba0ec11..798e5d65 100644 --- a/internal/provider/resource_application_test.go +++ b/internal/provider/resource_application_test.go @@ -96,10 +96,6 @@ func TestAcc_ResourceApplication_Updates(t *testing.T) { appName = "hello-kubecon" } - // trace plan - t.Log(testAccResourceApplicationUpdates(modelName, 1, true, "machinename")) - t.Log(testAccResourceApplicationUpdates(modelName, 2, true, "machinename")) - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: frameworkProviderFactories,