Skip to content

Instantly share code, notes, and snippets.

@erikmd
Forked from jmsdnns/tf_file_type.ml
Created March 7, 2025 14:04
Show Gist options
  • Save erikmd/7f1f138d84734f507549ab2f332e85b5 to your computer and use it in GitHub Desktop.
Save erikmd/7f1f138d84734f507549ab2f332e85b5 to your computer and use it in GitHub Desktop.
pattern matching on terraform json variations
(* val type_ : Yojson.Safe.t -> [ `Plan | `State | `Unknown ] *)
let type_ json =
let module Plan = struct
type t = {
terraform_version : string;
planned_values : Yojson.Safe.t;
}
[@@deriving of_yojson { strict = false }]
end in
let module State = struct
type t = {
terraform_version : string;
root_module : Yojson.Safe.t;
}
[@@deriving of_yojson { strict = false }]
end in
match (Plan.of_yojson json, State.of_yojson json) with
| Ok _, Ok _ -> `Unknown
| Ok _, _ -> `Plan
| _, Ok _ -> `State
| _ -> `Unknown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment