Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 tcp checker type #4

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/monitor_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type MonitorRequest struct {
Assertions json.RawMessage `json:"assertions,omitempty"`
Timeout int `json:"timeout"`
DegradedAfter int `json:"degradedAfter"`
Type string `json:"jobType,omitempty"`
}

func CreateMonitor(ctx context.Context, c *hreq.Client, request MonitorRequest) (*MonitorRequest, error) {
Expand Down
14 changes: 13 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ provider "openstatus" {
}


resource "openstatus_monitor" "my_monitor" {
resource "openstatus_monitor" "my_http_monitor" {
url = "https://www.openstatus.dev"
regions = ["iad", "jnb", "ams"]
periodicity = "10m"
Expand Down Expand Up @@ -62,6 +62,18 @@ resource "openstatus_monitor" "my_monitor" {
]
}

resource "openstatus_monitor" "my_tcp_monitor" {
url = "openstatus.dev:443"
regions = ["iad", "jnb", "ams"]
periodicity = "10m"
name = "test-monitor-terraform-tcp"
degraded_after = 30
timeout = 13
active = false
description = "This is a test monitor"
type = "tcp"
}

```


Expand Down
7 changes: 6 additions & 1 deletion internal/provider/monitor_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (r *monitorResource) Create(ctx context.Context, req resource.CreateRequest
Timeout: int(timeout),
DegradedAfter: int(degradedAfter),
Assertions: t,
Type: data.Type.ValueString(),
})

if err != nil {
Expand Down Expand Up @@ -181,6 +182,7 @@ func (r *monitorResource) Read(ctx context.Context, req resource.ReadRequest, re
data.Name = types.StringValue(monitor.Name)
data.Periodicity = types.StringValue(monitor.Periodicity)
data.Method = types.StringValue(monitor.Method)
data.Type = types.StringValue(monitor.Type)
}

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down Expand Up @@ -309,7 +311,7 @@ func (r *monitorResource) Update(ctx context.Context, req resource.UpdateRequest
data.Method = types.StringValue(out.Method)
data.DegradedAfter = types.NumberValue(big.NewFloat(float64(out.DegradedAfter)))
data.Timeout = types.NumberValue(big.NewFloat(float64(out.Timeout)))

data.Type = types.StringValue(out.Type)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)

}
Expand Down Expand Up @@ -370,6 +372,9 @@ func bindObject(ctx context.Context, monitor *resource_monitor.MonitorModel) dia
return diags
}
}
if monitor.Type.IsUnknown() {
monitor.Type = types.StringNull()
}
if monitor.Headers.IsUnknown() || monitor.Headers.IsNull() {
monitor.Headers = types.ListNull(resource_monitor.HeadersValue{}.Type(ctx))
} else if !monitor.Headers.IsNull() {
Expand Down
10 changes: 10 additions & 0 deletions internal/resource_monitor/monitor_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ func MonitorResourceSchema(ctx context.Context) schema.Schema {
Description: "The url to monitor",
MarkdownDescription: "The url to monitor",
},
"type": schema.StringAttribute{
Optional: true,
Computed: true,
Description: "The type of the monitor",
MarkdownDescription: "The type of the monitor",
Validators: []validator.String{stringvalidator.OneOf(
"http", "tcp",
)},
},
},
}
}
Expand All @@ -210,6 +219,7 @@ type MonitorModel struct {
Regions types.List `tfsdk:"regions"`
Timeout types.Number `tfsdk:"timeout"`
Url types.String `tfsdk:"url"`
Type types.String `tfsdk:"type"`
}

var _ basetypes.ObjectTypable = AssertionsType{}
Expand Down
17 changes: 15 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ provider "openstatus" {
}


resource "openstatus_monitor" "my_monitor" {
resource "openstatus_monitor" "my_second_monitor" {
url = "https://www.openstatus.dev"
regions = ["iad", "jnb", "ams"]
periodicity = "10m"
name = "test-monitor"
name = "test-monitor-terraform-http"
degraded_after = 30
timeout = 13
active = false
Expand Down Expand Up @@ -44,3 +44,16 @@ resource "openstatus_monitor" "my_monitor" {
}
]
}


resource "openstatus_monitor" "my_monitor" {
url = "openstatus.dev:443"
regions = ["iad", "jnb", "ams"]
periodicity = "10m"
name = "test-monitor-terraform-tcp"
degraded_after = 30
timeout = 13
active = false
description = "This is a test monitor"
type = "tcp"
}