Skip to content

Commit 20af507

Browse files
committed
ref: only fetch catalog plugin version when desired version is the latest
1 parent c64894e commit 20af507

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

internal/resources/cloud/resource_cloud_plugin_installation.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ func listStackPlugins(ctx context.Context, client *gcom.APIClient, data *ListerD
9595
func resourcePluginInstallationCreate(ctx context.Context, d *schema.ResourceData, client *gcom.APIClient) diag.Diagnostics {
9696
stackSlug := d.Get("stack_slug").(string)
9797
pluginSlug := d.Get("slug").(string)
98-
version := "latest"
99-
if v, ok := d.GetOk("version"); ok {
100-
version = v.(string)
101-
}
98+
version := d.Get("version").(string)
10299

103100
req := gcom.PostInstancePluginsRequest{
104101
Plugin: pluginSlug,
@@ -140,15 +137,20 @@ func resourcePluginInstallationRead(ctx context.Context, d *schema.ResourceData,
140137
if err, shouldReturn := common.CheckReadError("plugin", d, err); shouldReturn {
141138
return err
142139
}
143-
catalogPlugin, _, err := client.PluginsAPI.GetPlugin(ctx, pluginSlug.(string)).Execute()
144-
if err, shouldReturn := common.CheckReadError("plugin", d, err); shouldReturn {
145-
return err
140+
desiredVersion := d.Get("version").(string)
141+
catalogVersion := ""
142+
if desiredVersion == LatestVersion {
143+
catalogPlugin, _, err := client.PluginsAPI.GetPlugin(ctx, pluginSlug.(string)).Execute()
144+
if err, shouldReturn := common.CheckReadError("plugin", d, err); shouldReturn {
145+
return err
146+
}
147+
catalogVersion = catalogPlugin.Version
146148
}
147149

148150
d.Set("stack_slug", installation.InstanceSlug)
149151
d.Set("slug", installation.PluginSlug)
150-
desiredVersion := d.Get("version").(string)
151-
if desiredVersion == LatestVersion && installation.Version == catalogPlugin.Version {
152+
153+
if desiredVersion == LatestVersion && installation.Version == catalogVersion {
152154
d.Set("version", LatestVersion)
153155
} else {
154156
d.Set("version", installation.Version)

0 commit comments

Comments
 (0)