-
-
Save erikmd/7f1f138d84734f507549ab2f332e85b5 to your computer and use it in GitHub Desktop.
pattern matching on terraform json variations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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