Skip to content

Commit 6510bc9

Browse files
authored
Use a provider's stable version when bundling schemas (#1860)
1 parent 05b9a20 commit 6510bc9

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: BUG FIXES
2+
body: Use a provider's stable version when bundling schemas
3+
time: 2024-11-11T13:10:48.339488+01:00
4+
custom:
5+
Issue: "1860"
6+
Repository: terraform-ls

internal/schemas/gen/gen.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,6 @@ func schemaForProvider(ctx context.Context, client registry.Client, input Inputs
262262
return nil, fmt.Errorf("unable to create workspace dir: %w", err)
263263
}
264264

265-
dataDir := filepath.Join(input.DataDirPath,
266-
input.Provider.Addr.Hostname.String(),
267-
input.Provider.Addr.Namespace,
268-
input.Provider.Addr.Type,
269-
pVersion.String())
270-
err = os.MkdirAll(dataDir, 0755)
271-
if err != nil {
272-
return nil, fmt.Errorf("unable to create data dir: %w", err)
273-
}
274-
275265
type templateData struct {
276266
TerraformVersion string
277267
LocalName string
@@ -283,7 +273,6 @@ func schemaForProvider(ctx context.Context, client registry.Client, input Inputs
283273
required_providers {
284274
{{ .LocalName }} = {
285275
source = "{{ .Source }}"
286-
{{ with .Version }}version = "{{ . }}"{{ end }}
287276
}
288277
}
289278
}
@@ -354,7 +343,12 @@ func schemaForProvider(ctx context.Context, client registry.Client, input Inputs
354343
return nil, fmt.Errorf("provider version not found for %q", input.Provider.Addr.ForDisplay())
355344
}
356345
if !pv.Equal(pVersion) {
357-
return nil, fmt.Errorf("expected provider version %s to match %s", pv, pVersion)
346+
// The Terraform registry currently returns pre-release versions as the latest available version,
347+
// although Terraform defaults to the latest stable version. In this case, we'll ignore the
348+
// latest version from the registry until they implement a filter for stable versions.
349+
log.Printf("%s: registry version doesn't match installed version: %s != %s. Using %s",
350+
input.Provider.Addr.ForDisplay(), pVersion, pv, pv)
351+
pVersion = pv
358352
}
359353
}
360354

@@ -364,6 +358,16 @@ func schemaForProvider(ctx context.Context, client registry.Client, input Inputs
364358
return nil, err
365359
}
366360

361+
dataDir := filepath.Join(input.DataDirPath,
362+
input.Provider.Addr.Hostname.String(),
363+
input.Provider.Addr.Namespace,
364+
input.Provider.Addr.Type,
365+
pVersion.String())
366+
err = os.MkdirAll(dataDir, 0755)
367+
if err != nil {
368+
return nil, fmt.Errorf("unable to create data dir: %w", err)
369+
}
370+
367371
f, err := os.Create(filepath.Join(dataDir, "schema.json.gz"))
368372
if err != nil {
369373
return nil, fmt.Errorf("failed to create schema file: %w", err)

0 commit comments

Comments
 (0)