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

Fixed typing of check results in statefiles #101

Merged
merged 1 commit into from
Aug 30, 2023
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
6 changes: 0 additions & 6 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ func testParse(t *testing.T, filename string, typ reflect.Type) {
continue
}

// Skip this directory as this is a unique test that only tests a subset
// of attributes for a plan. The fixture is not entirely valid, but that's okay.
if e.Name() == "has_checks" {
continue
}

t.Run(e.Name(), func(t *testing.T) {
expected, err := ioutil.ReadFile(filepath.Join(testFixtureDir, e.Name(), filename))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion state.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type State struct {

// Checks contains the results of any conditional checks when Values was
// last updated.
Checks *CheckResultStatic `json:"checks,omitempty"`
Checks []CheckResultStatic `json:"checks,omitempty"`
}

// UseJSONNumber controls whether the State will be decoded using the
Expand Down
20 changes: 20 additions & 0 deletions testdata/has_checks/child_moodule/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "file_names" {
type = set(string)
default = [
"file1.txt",
]
}

resource "local_file" "foo" {
for_each = var.file_names
content = "Hello, World!"
filename = each.value

lifecycle {
postcondition {
condition = self.content == "Hello, World!"
error_message = "File content is not correct"
}
}
}

4 changes: 4 additions & 0 deletions testdata/has_checks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "files" {
source = "./child_module"
file_names = ["file1.txt", "file2.txt"]
}
2 changes: 1 addition & 1 deletion testdata/has_checks/plan.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"format_version":"1.1","terraform_version":"1.5.0","planned_values":{"root_module":{"resources":[{"address":"null_resource.foo","mode":"managed","type":"null_resource","name":"foo","provider_name":"registry.terraform.io/hashicorp/null","schema_version":0,"values":{"triggers":null},"sensitive_values":{}}]}},"resource_changes":[{"address":"null_resource.foo","mode":"managed","type":"null_resource","name":"foo","provider_name":"registry.terraform.io/hashicorp/null","change":{"actions":["create"],"before":null,"after":{"triggers":null},"after_unknown":{"id":true},"before_sensitive":false,"after_sensitive":{}}}],"configuration":{"provider_config":{"null":{"name":"null","full_name":"registry.terraform.io/hashicorp/null"}},"root_module":{"resources":[{"address":"null_resource.foo","mode":"managed","type":"null_resource","name":"foo","provider_config_key":"null","schema_version":0}]}},"checks":[{"//":"EXPERIMENTAL: see docs for details","address":{"kind":"resource","mode":"managed","module":"module.foo.module.bar","name":"this","to_display":"module.foo.module.bar.foobar.this","type":"foobar"},"status":"pass","instances":[{"address":{"instance_key":0,"module":"module.foo.module.bar","to_display":"module.foo.module.bar.foobar.this[0]"},"status":"pass"}]},{"//":"EXPERIMENTAL: see docs for details","address":{"kind":"resource","mode":"managed","module":"module.foo.module.bar","name":"this","to_display":"module.foo.module.bar.foobar.this","type":"foobar"},"status":"pass"}]}
{"format_version":"1.2","terraform_version":"1.5.4","planned_values":{"root_module":{"child_modules":[{"resources":[{"address":"module.files.local_file.foo[\"file1.txt\"]","mode":"managed","type":"local_file","name":"foo","index":"file1.txt","provider_name":"registry.terraform.io/hashicorp/local","schema_version":0,"values":{"content":"Hello, World!","content_base64":null,"directory_permission":"0777","file_permission":"0777","filename":"file1.txt","sensitive_content":null,"source":null},"sensitive_values":{}},{"address":"module.files.local_file.foo[\"file2.txt\"]","mode":"managed","type":"local_file","name":"foo","index":"file2.txt","provider_name":"registry.terraform.io/hashicorp/local","schema_version":0,"values":{"content":"Hello, World!","content_base64":null,"directory_permission":"0777","file_permission":"0777","filename":"file2.txt","sensitive_content":null,"source":null},"sensitive_values":{}}],"address":"module.files"}]}},"resource_changes":[{"address":"module.files.local_file.foo[\"file1.txt\"]","module_address":"module.files","mode":"managed","type":"local_file","name":"foo","index":"file1.txt","provider_name":"registry.terraform.io/hashicorp/local","change":{"actions":["create"],"before":null,"after":{"content":"Hello, World!","content_base64":null,"directory_permission":"0777","file_permission":"0777","filename":"file1.txt","sensitive_content":null,"source":null},"after_unknown":{"content_base64sha256":true,"content_base64sha512":true,"content_md5":true,"content_sha1":true,"content_sha256":true,"content_sha512":true,"id":true},"before_sensitive":false,"after_sensitive":{"sensitive_content":true}}},{"address":"module.files.local_file.foo[\"file2.txt\"]","module_address":"module.files","mode":"managed","type":"local_file","name":"foo","index":"file2.txt","provider_name":"registry.terraform.io/hashicorp/local","change":{"actions":["create"],"before":null,"after":{"content":"Hello, World!","content_base64":null,"directory_permission":"0777","file_permission":"0777","filename":"file2.txt","sensitive_content":null,"source":null},"after_unknown":{"content_base64sha256":true,"content_base64sha512":true,"content_md5":true,"content_sha1":true,"content_sha256":true,"content_sha512":true,"id":true},"before_sensitive":false,"after_sensitive":{"sensitive_content":true}}}],"configuration":{"provider_config":{"module.files:local":{"name":"local","full_name":"registry.terraform.io/hashicorp/local","module_address":"module.files"}},"root_module":{"module_calls":{"files":{"source":"./child_module","expressions":{"file_names":{"constant_value":["file1.txt","file2.txt"]}},"module":{"resources":[{"address":"local_file.foo","mode":"managed","type":"local_file","name":"foo","provider_config_key":"module.files:local","expressions":{"content":{"constant_value":"Hello, World!"},"filename":{"references":["each.value"]}},"schema_version":0,"for_each_expression":{"references":["var.file_names"]}}],"variables":{"file_names":{"default":["file1.txt"]}}}}}}},"checks":[{"address":{"to_display":"module.files.local_file.foo","kind":"resource","module":"module.files","mode":"managed","type":"local_file","name":"foo"},"status":"pass","instances":[{"address":{"to_display":"module.files.local_file.foo[\"file1.txt\"]","module":"module.files","instance_key":"file1.txt"},"status":"pass"},{"address":{"to_display":"module.files.local_file.foo[\"file2.txt\"]","module":"module.files","instance_key":"file2.txt"},"status":"pass"}]}],"timestamp":"2023-08-30T10:38:39Z"}
1 change: 1 addition & 0 deletions testdata/has_checks/schemas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"format_version":"1.0","provider_schemas":{"registry.terraform.io/hashicorp/local":{"provider":{"version":0,"block":{"description_kind":"plain"}},"resource_schemas":{"local_file":{"version":0,"block":{"attributes":{"content":{"type":"string","description":"Content to store in the file, expected to be a UTF-8 encoded string.\n Conflicts with `sensitive_content`, `content_base64` and `source`.\n Exactly one of these four arguments must be specified.","description_kind":"plain","optional":true},"content_base64":{"type":"string","description":"Content to store in the file, expected to be binary encoded as base64 string.\n Conflicts with `content`, `sensitive_content` and `source`.\n Exactly one of these four arguments must be specified.","description_kind":"plain","optional":true},"content_base64sha256":{"type":"string","description":"Base64 encoded SHA256 checksum of file content.","description_kind":"plain","computed":true},"content_base64sha512":{"type":"string","description":"Base64 encoded SHA512 checksum of file content.","description_kind":"plain","computed":true},"content_md5":{"type":"string","description":"MD5 checksum of file content.","description_kind":"plain","computed":true},"content_sha1":{"type":"string","description":"SHA1 checksum of file content.","description_kind":"plain","computed":true},"content_sha256":{"type":"string","description":"SHA256 checksum of file content.","description_kind":"plain","computed":true},"content_sha512":{"type":"string","description":"SHA512 checksum of file content.","description_kind":"plain","computed":true},"directory_permission":{"type":"string","description":"Permissions to set for directories created (before umask), expressed as string in\n [numeric notation](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation).\n Default value is `\"0777\"`.","description_kind":"plain","optional":true,"computed":true},"file_permission":{"type":"string","description":"Permissions to set for the output file (before umask), expressed as string in\n [numeric notation](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation).\n Default value is `\"0777\"`.","description_kind":"plain","optional":true,"computed":true},"filename":{"type":"string","description":"The path to the file that will be created.\n Missing parent directories will be created.\n If the file already exists, it will be overridden with the given content.","description_kind":"plain","required":true},"id":{"type":"string","description":"The hexadecimal encoding of the SHA1 checksum of the file content.","description_kind":"plain","computed":true},"sensitive_content":{"type":"string","description":"Sensitive content to store in the file, expected to be an UTF-8 encoded string.\n Will not be displayed in diffs.\n Conflicts with `content`, `content_base64` and `source`.\n Exactly one of these four arguments must be specified.\n If in need to use _sensitive_ content, please use the [`local_sensitive_file`](./sensitive_file.html)\n resource instead.","description_kind":"plain","deprecated":true,"optional":true,"sensitive":true},"source":{"type":"string","description":"Path to file to use as source for the one we are creating.\n Conflicts with `content`, `sensitive_content` and `content_base64`.\n Exactly one of these four arguments must be specified.","description_kind":"plain","optional":true}},"description":"Generates a local file with the given content.","description_kind":"plain"}},"local_sensitive_file":{"version":0,"block":{"attributes":{"content":{"type":"string","description":"Sensitive Content to store in the file, expected to be a UTF-8 encoded string.\n Conflicts with `content_base64` and `source`.\n Exactly one of these three arguments must be specified.","description_kind":"plain","optional":true,"sensitive":true},"content_base64":{"type":"string","description":"Sensitive Content to store in the file, expected to be binary encoded as base64 string.\n Conflicts with `content` and `source`.\n Exactly one of these three arguments must be specified.","description_kind":"plain","optional":true,"sensitive":true},"content_base64sha256":{"type":"string","description":"Base64 encoded SHA256 checksum of file content.","description_kind":"plain","computed":true},"content_base64sha512":{"type":"string","description":"Base64 encoded SHA512 checksum of file content.","description_kind":"plain","computed":true},"content_md5":{"type":"string","description":"MD5 checksum of file content.","description_kind":"plain","computed":true},"content_sha1":{"type":"string","description":"SHA1 checksum of file content.","description_kind":"plain","computed":true},"content_sha256":{"type":"string","description":"SHA256 checksum of file content.","description_kind":"plain","computed":true},"content_sha512":{"type":"string","description":"SHA512 checksum of file content.","description_kind":"plain","computed":true},"directory_permission":{"type":"string","description":"Permissions to set for directories created (before umask), expressed as string in\n [numeric notation](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation).\n Default value is `\"0700\"`.","description_kind":"plain","optional":true,"computed":true},"file_permission":{"type":"string","description":"Permissions to set for the output file (before umask), expressed as string in\n [numeric notation](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation).\n Default value is `\"0700\"`.","description_kind":"plain","optional":true,"computed":true},"filename":{"type":"string","description":"The path to the file that will be created.\n Missing parent directories will be created.\n If the file already exists, it will be overridden with the given content.","description_kind":"plain","required":true},"id":{"type":"string","description":"The hexadecimal encoding of the SHA1 checksum of the file content.","description_kind":"plain","computed":true},"source":{"type":"string","description":"Path to file to use as source for the one we are creating.\n Conflicts with `content` and `content_base64`.\n Exactly one of these three arguments must be specified.","description_kind":"plain","optional":true}},"description":"Generates a local file with the given sensitive content.","description_kind":"plain"}}},"data_source_schemas":{"local_file":{"version":0,"block":{"attributes":{"content":{"type":"string","description":"Raw content of the file that was read, as UTF-8 encoded string. Files that do not contain UTF-8 text will have invalid UTF-8 sequences in `content`\n replaced with the Unicode replacement character. ","description_kind":"plain","computed":true},"content_base64":{"type":"string","description":"Base64 encoded version of the file content (use this when dealing with binary data).","description_kind":"plain","computed":true},"content_base64sha256":{"type":"string","description":"Base64 encoded SHA256 checksum of file content.","description_kind":"plain","computed":true},"content_base64sha512":{"type":"string","description":"Base64 encoded SHA512 checksum of file content.","description_kind":"plain","computed":true},"content_md5":{"type":"string","description":"MD5 checksum of file content.","description_kind":"plain","computed":true},"content_sha1":{"type":"string","description":"SHA1 checksum of file content.","description_kind":"plain","computed":true},"content_sha256":{"type":"string","description":"SHA256 checksum of file content.","description_kind":"plain","computed":true},"content_sha512":{"type":"string","description":"SHA512 checksum of file content.","description_kind":"plain","computed":true},"filename":{"type":"string","description":"Path to the file that will be read. The data source will return an error if the file does not exist.","description_kind":"plain","required":true},"id":{"type":"string","description":"The hexadecimal encoding of the SHA1 checksum of the file content.","description_kind":"plain","computed":true}},"description":"Reads a file from the local filesystem.","description_kind":"plain"}},"local_sensitive_file":{"version":0,"block":{"attributes":{"content":{"type":"string","description":"Raw content of the file that was read, as UTF-8 encoded string. Files that do not contain UTF-8 text will have invalid UTF-8 sequences in `content`\n replaced with the Unicode replacement character.","description_kind":"plain","computed":true,"sensitive":true},"content_base64":{"type":"string","description":"Base64 encoded version of the file content (use this when dealing with binary data).","description_kind":"plain","computed":true,"sensitive":true},"content_base64sha256":{"type":"string","description":"Base64 encoded SHA256 checksum of file content.","description_kind":"plain","computed":true},"content_base64sha512":{"type":"string","description":"Base64 encoded SHA512 checksum of file content.","description_kind":"plain","computed":true},"content_md5":{"type":"string","description":"MD5 checksum of file content.","description_kind":"plain","computed":true},"content_sha1":{"type":"string","description":"SHA1 checksum of file content.","description_kind":"plain","computed":true},"content_sha256":{"type":"string","description":"SHA256 checksum of file content.","description_kind":"plain","computed":true},"content_sha512":{"type":"string","description":"SHA512 checksum of file content.","description_kind":"plain","computed":true},"filename":{"type":"string","description":"Path to the file that will be read. The data source will return an error if the file does not exist.","description_kind":"plain","required":true},"id":{"type":"string","description":"The hexadecimal encoding of the SHA1 checksum of the file content.","description_kind":"plain","computed":true}},"description":"Reads a file that contains sensitive data, from the local filesystem.","description_kind":"plain"}}}}}}
1 change: 1 addition & 0 deletions testdata/has_checks/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"format_version":"1.0","terraform_version":"1.5.4","values":{"root_module":{"child_modules":[{"resources":[{"address":"module.files.local_file.foo[\"file1.txt\"]","mode":"managed","type":"local_file","name":"foo","index":"file1.txt","provider_name":"registry.terraform.io/hashicorp/local","schema_version":0,"values":{"content":"Hello, World!","content_base64":null,"content_base64sha256":"3/1gIbsr1bCvZ2KQgJ7DpTGR3YHH9wpLKGiKNiGCmG8=","content_base64sha512":"N015SpXNz9izWZMYX++bo2jxYNja9DLQi6nx7R5avmzGkpHg+i/gAGpSVw7xjBne9OYXwzzlLvCm5fvjGMsDhw==","content_md5":"65a8e27d8879283831b664bd8b7f0ad4","content_sha1":"0a0a9f2a6772942557ab5355d76af442f8f65e01","content_sha256":"dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f","content_sha512":"374d794a95cdcfd8b35993185fef9ba368f160d8daf432d08ba9f1ed1e5abe6cc69291e0fa2fe0006a52570ef18c19def4e617c33ce52ef0a6e5fbe318cb0387","directory_permission":"0777","file_permission":"0777","filename":"file1.txt","id":"0a0a9f2a6772942557ab5355d76af442f8f65e01","sensitive_content":null,"source":null},"sensitive_values":{"sensitive_content":true}},{"address":"module.files.local_file.foo[\"file2.txt\"]","mode":"managed","type":"local_file","name":"foo","index":"file2.txt","provider_name":"registry.terraform.io/hashicorp/local","schema_version":0,"values":{"content":"Hello, World!","content_base64":null,"content_base64sha256":"3/1gIbsr1bCvZ2KQgJ7DpTGR3YHH9wpLKGiKNiGCmG8=","content_base64sha512":"N015SpXNz9izWZMYX++bo2jxYNja9DLQi6nx7R5avmzGkpHg+i/gAGpSVw7xjBne9OYXwzzlLvCm5fvjGMsDhw==","content_md5":"65a8e27d8879283831b664bd8b7f0ad4","content_sha1":"0a0a9f2a6772942557ab5355d76af442f8f65e01","content_sha256":"dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f","content_sha512":"374d794a95cdcfd8b35993185fef9ba368f160d8daf432d08ba9f1ed1e5abe6cc69291e0fa2fe0006a52570ef18c19def4e617c33ce52ef0a6e5fbe318cb0387","directory_permission":"0777","file_permission":"0777","filename":"file2.txt","id":"0a0a9f2a6772942557ab5355d76af442f8f65e01","sensitive_content":null,"source":null},"sensitive_values":{"sensitive_content":true}}],"address":"module.files"}]}},"checks":[{"address":{"to_display":"module.files.local_file.foo","kind":"resource","module":"module.files","mode":"managed","type":"local_file","name":"foo"},"status":"pass","instances":[{"address":{"to_display":"module.files.local_file.foo[\"file1.txt\"]","module":"module.files","instance_key":"file1.txt"},"status":"pass"},{"address":{"to_display":"module.files.local_file.foo[\"file2.txt\"]","module":"module.files","instance_key":"file2.txt"},"status":"pass"}]}]}