Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
Fix folder_iam logic to use the correct updater (#764)
Browse files Browse the repository at this point in the history
* Fix folder_iam logic to use the correct updater

* Attempt to use new folder for tests

* Revert "Attempt to use new folder for tests"

This reverts commit 2a919c6.

* Fix compare functions in tests to only consider expected iam members
  • Loading branch information
roaks3 authored Jun 16, 2022
1 parent 193a1e9 commit ccac12c
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 1 deletion.
2 changes: 1 addition & 1 deletion converters/google/resources/folder_iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func newFolderIamAsset(

func FetchFolderIamPolicy(d TerraformResourceData, config *Config) (Asset, error) {
return fetchIamPolicy(
NewProjectIamUpdater,
NewFolderIamUpdater,
d,
config,
"//cloudresourcemanager.googleapis.com/{{folder}}",
Expand Down
1 change: 1 addition & 0 deletions test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestCLI(t *testing.T) {
{name: "sql"},
{name: "example_compute_forwarding_rule"},
{name: "example_compute_instance"},
{name: "example_folder_iam_member", compareConvertOutput: compareMergedIamMemberOutput},
{name: "example_project_create", constraints: []constraint{alwaysViolate, {name: "project_match_target", wantViolation: false, wantOutputRegex: ""}}},
{name: "example_project_update", constraints: []constraint{alwaysViolate, {name: "project_match_target", wantViolation: true, wantOutputRegex: "Constraint GCPAlwaysViolatesConstraintV1.always_violates_project_match_target on resource"}}},
{name: "example_project_iam_binding", compareConvertOutput: compareMergedIamBindingOutput},
Expand Down
1 change: 1 addition & 0 deletions test/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestReadPlannedAssetsCoverage(t *testing.T) {
}{
// read-only, the following tests are not in cli_test or
// have unique parameters that separate them
{name: "example_folder_iam_member"},
{name: "example_project_create"},
{name: "example_project_update"},
{name: "example_project_iam_binding"},
Expand Down
17 changes: 17 additions & 0 deletions testdata/templates/example_folder_iam_member.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"name": "//cloudresourcemanager.googleapis.com/folders/{{.FolderID}}",
"asset_type": "cloudresourcemanager.googleapis.com/Folder",
"ancestry_path": "{{.Ancestry}}",
"iam_policy": {
"bindings": [
{
"role": "roles/editor",
"members": [
"user:[email protected]"
]
}
]
}
}
]
34 changes: 34 additions & 0 deletions testdata/templates/example_folder_iam_member.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> {{.Provider.version}}"
}
}
}

provider "google" {
{{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
}

resource "google_folder_iam_member" "editor" {
folder = "folders/{{.FolderID}}"
role = "roles/editor"
member = "user:[email protected]"
}
92 changes: 92 additions & 0 deletions testdata/templates/example_folder_iam_member.tfplan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"format_version": "1.0",
"terraform_version": "1.1.9",
"planned_values": {
"root_module": {
"resources": [
{
"address": "google_folder_iam_member.editor",
"mode": "managed",
"type": "google_folder_iam_member",
"name": "editor",
"provider_name": "registry.terraform.io/hashicorp/google",
"schema_version": 0,
"values": {
"condition": [],
"folder": "folders/{{.FolderID}}",
"member": "user:[email protected]",
"role": "roles/editor"
},
"sensitive_values": {
"condition": []
}
}
]
}
},
"resource_changes": [
{
"address": "google_folder_iam_member.editor",
"mode": "managed",
"type": "google_folder_iam_member",
"name": "editor",
"provider_name": "registry.terraform.io/hashicorp/google",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"condition": [],
"folder": "folders/{{.FolderID}}",
"member": "user:[email protected]",
"role": "roles/editor"
},
"after_unknown": {
"condition": [],
"etag": true,
"id": true
},
"before_sensitive": false,
"after_sensitive": {
"condition": []
}
}
}
],
"configuration": {
"provider_config": {
"google": {
"name": "google",
"expressions": {
"project": {
"constant_value": "{{.Provider.project}}"
}
}
}
},
"root_module": {
"resources": [
{
"address": "google_folder_iam_member.editor",
"mode": "managed",
"type": "google_folder_iam_member",
"name": "editor",
"provider_config_key": "google",
"expressions": {
"folder": {
"constant_value": "folders/{{.FolderID}}"
},
"member": {
"constant_value": "user:[email protected]"
},
"role": {
"constant_value": "roles/editor"
}
},
"schema_version": 0
}
]
}
}
}

0 comments on commit ccac12c

Please sign in to comment.