Skip to content

Commit 893e6a9

Browse files
committed
ci: get ci passing
1 parent cfdb868 commit 893e6a9

7 files changed

Lines changed: 55 additions & 9 deletions

File tree

.github/workflows/samples-terraform.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jobs:
3434
with:
3535
go-version: "stable"
3636
- run: go version
37+
- name: Install Dependencies
38+
working-directory: ${{ matrix.sample }}
39+
run: |
40+
go mod tidy
3741
- name: Build provider
3842
working-directory: ${{ matrix.sample }}
3943
run: go build -v ./...

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TerraformProviderCodegen.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,21 @@ public ModelsMap postProcessModels(ModelsMap objs) {
444444
for (ModelMap m : objs.getModels()) {
445445
CodegenModel model = m.getModel();
446446
for (CodegenProperty prop : model.vars) {
447+
// Ensure x-go-datatag is set for all model vars.
448+
// The parent AbstractGoCodegen only sets x-go-datatag on
449+
// inheritedProperties (oneOf/anyOf entries) when the model has
450+
// composed schemas without allOf, leaving model.vars without
451+
// json tags. We fix this by generating the tag here when missing.
452+
if (!prop.vendorExtensions.containsKey("x-go-datatag")) {
453+
String goDataTag = "json:\"" + prop.baseName;
454+
if (!prop.required) {
455+
goDataTag += ",omitempty";
456+
}
457+
goDataTag += "\"";
458+
goDataTag = " `" + goDataTag + "`";
459+
prop.vendorExtensions.put("x-go-datatag", goDataTag);
460+
}
461+
447462
// Add Terraform-specific vendor extensions
448463
if (prop.isReadOnly) {
449464
prop.vendorExtensions.put("x-terraform-computed", true);

modules/openapi-generator/src/main/resources/terraform-provider/README.mustache

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This Terraform provider was generated using [OpenAPI Generator](https://openapi-
55
## Requirements
66

77
- [Terraform](https://www.terraform.io/downloads.html) >= 1.0
8-
- [Go](https://golang.org/doc/install) >= 1.21
8+
- [Go](https://golang.org/doc/install) >= 1.22
99

1010
## Building The Provider
1111

@@ -39,6 +39,19 @@ If you wish to work on the provider, you'll first need [Go](http://www.golang.or
3939

4040
To compile the provider, run `go install`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
4141

42+
For local development and testing, add a `dev_overrides` block to your `~/.terraformrc` so that Terraform uses the locally built binary instead of fetching from the registry:
43+
44+
```hcl
45+
provider_installation {
46+
dev_overrides {
47+
"{{providerAddress}}" = "${GOPATH}/bin"
48+
}
49+
direct {}
50+
}
51+
```
52+
53+
With `dev_overrides` configured, you do not need to run `terraform init` for the provider.
54+
4255
To generate or update documentation, run `go generate`.
4356

4457
In order to run the full suite of Acceptance tests, run `make testacc`.

modules/openapi-generator/src/main/resources/terraform-provider/gitignore.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
*.tfstate
99
*.tfstate.*
1010
.terraform/
11-
terraform.tfvars
11+
*.tfvars
12+
*.tfvars.json
1213
terraform-provider-{{providerName}}

modules/openapi-generator/src/main/resources/terraform-provider/go.mod.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module {{gitHost}}/{{gitUserId}}/{{gitRepoId}}
22

3-
go 1.22
3+
go 1.24.0
44

55
toolchain go1.24.4
66

modules/openapi-generator/src/main/resources/terraform-provider/provider.mustache

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,16 @@ func (p *{{providerName}}Provider) Configure(ctx context.Context, req provider.C
7878
return
7979
}
8080

81-
endpoint := config.Endpoint.ValueString()
82-
if endpoint == "" {
83-
endpoint = "{{{basePath}}}"
81+
if config.Endpoint.IsUnknown() {
82+
resp.Diagnostics.AddWarning(
83+
"Unknown Endpoint Value",
84+
"The provider endpoint value is not yet known. Defaulting to the spec-defined base path.",
85+
)
86+
}
87+
88+
endpoint := "{{{basePath}}}"
89+
if !config.Endpoint.IsNull() && !config.Endpoint.IsUnknown() {
90+
endpoint = config.Endpoint.ValueString()
8491
}
8592

8693
c := client.NewClient(endpoint)

modules/openapi-generator/src/main/resources/terraform-provider/resource.mustache

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (r *{{resourceClassName}}Resource) Read(ctx context.Context, req resource.R
162162
{{/hasRead}}
163163
{{^hasRead}}
164164
func (r *{{resourceClassName}}Resource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
165-
resp.Diagnostics.AddError("Not Supported", "Read is not supported for {{resourceName}}")
165+
// No read endpoint available; keep existing state as-is.
166166
}
167167
{{/hasRead}}
168168

@@ -202,7 +202,13 @@ func (r *{{resourceClassName}}Resource) Update(ctx context.Context, req resource
202202
{{/hasUpdate}}
203203
{{^hasUpdate}}
204204
func (r *{{resourceClassName}}Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
205-
resp.Diagnostics.AddError("Not Supported", "Update is not supported for {{resourceName}}")
205+
// No update endpoint available; persist the planned values into state.
206+
var plan {{resourceClassName}}Model
207+
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
208+
if resp.Diagnostics.HasError() {
209+
return
210+
}
211+
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
206212
}
207213
{{/hasUpdate}}
208214

@@ -231,7 +237,7 @@ func (r *{{resourceClassName}}Resource) Delete(ctx context.Context, req resource
231237
{{/hasDelete}}
232238
{{^hasDelete}}
233239
func (r *{{resourceClassName}}Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
234-
resp.Diagnostics.AddError("Not Supported", "Delete is not supported for {{resourceName}}")
240+
// No delete endpoint available; remove the resource from state.
235241
}
236242
{{/hasDelete}}
237243

0 commit comments

Comments
 (0)