Skip to content

Commit

Permalink
Merge pull request #1033 from Juniper/raw-json-make-id-optional
Browse files Browse the repository at this point in the history
Make `apstra_raw_json` 'id` attribute optional
  • Loading branch information
chrismarget-j authored Feb 5, 2025
2 parents 323aeb0 + 72c0912 commit 4e8528f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions apstra/raw/rawJson.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ type RawJson struct {
func (o *RawJson) ResourceAttributes() map[string]schema.Attribute {
return map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The ID of the raw JSON object.",
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
MarkdownDescription: "The ID of the raw JSON object. We attempt to determine the ID from the API response. " +
"If the ID can be anticipated, it is possible to specify it here.",
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"url": schema.StringAttribute{
MarkdownDescription: "The API URL associated with the raw JSON object.",
Expand Down
7 changes: 5 additions & 2 deletions apstra/resource_raw_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ func (o *resourceRawJson) Create(ctx context.Context, req resource.CreateRequest
return
}

plan.Id = types.StringPointerValue(idResponse.Id)
if plan.Id.IsUnknown() {
plan.Id = types.StringPointerValue(idResponse.Id)
}

if plan.Id.IsNull() {
resp.Diagnostics.AddWarning(
"ID is null",
"creation did not produce an error, but we failed to find an object ID in the API response",
"creation did not produce an error, but no ID was specified in the configuration and we failed to find one in the API response",
)
}

Expand Down
5 changes: 4 additions & 1 deletion docs/resources/raw_json.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ resource "apstra_raw_json" "example" {
- `payload` (String) JSON payload used to create and update the raw JSON object.
- `url` (String) The API URL associated with the raw JSON object.

### Optional

- `id` (String) The ID of the raw JSON object. We attempt to determine the ID from the API response. If the ID can be anticipated, it is possible to specify it here.

### Read-Only

- `id` (String) The ID of the raw JSON object.
- `update_method` (String) The method used to update the JSON object. Must be one of `PUT` or `PATCH`. Default: `PUT`


Expand Down

0 comments on commit 4e8528f

Please sign in to comment.