Skip to content

Commit

Permalink
Merge pull request #64 from terraform-google-modules/adrienthebo/lien…
Browse files Browse the repository at this point in the history
…-resource

Add lien support to project-factory
  • Loading branch information
morgante authored Dec 11, 2018
2 parents 5791b76 + 730bf88 commit 696a5a2
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ resource "google_project" "project" {
app_engine = "${local.app_engine_config["${local.app_engine_enabled ? "enabled" : "disabled"}"]}"
}

/******************************************
Project lien
*****************************************/
resource "google_resource_manager_lien" "lien" {
count = "${var.lien ? 1 : 0}"
parent = "projects/${google_project.project.number}"
restrictions = ["resourcemanager.projects.delete"]
origin = "project-factory"
reason = "Project Factory lien"
}

/******************************************
APIs configuration
*****************************************/
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/full/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module "project-factory" {
sa_role = "${var.sa_role}"
sa_group = "${var.sa_group}"
credentials_path = "${var.credentials_path}"
lien = "true"

activate_apis = [
"compute.googleapis.com",
Expand Down
29 changes: 29 additions & 0 deletions test/integration/full/controls/project-factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@
expect(service_accounts).to include extra_service_account_email
end
end

describe command("gcloud alpha resource-manager liens list --project #{project_id} --format=json") do
its('exit_status') { should be 0 }
its('stderr') { should eq '' }

let(:liens) do
if subject.exit_status == 0
JSON.parse(subject.stdout, symbolize_names: true)
else
[]
end
end

it "has one lien" do
expect(liens.count).to eq 1
end

it "sets the lien origin" do
expect(liens.first).to include(origin: 'project-factory')
end

it "sets the lien reason" do
expect(liens.first).to include(reason: 'Project Factory lien')
end

it "restricts the delete permission on the project" do
expect(liens.first).to include(restrictions: ['resourcemanager.projects.delete'])
end
end
end

control 'project-factory-sa-role' do
Expand Down
17 changes: 17 additions & 0 deletions test/integration/minimal/controls/minimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,21 @@

it { expect(service_accounts).to include service_account_email }
end

describe command("gcloud alpha resource-manager liens list --project #{project_id} --format=json") do
its('exit_status') { should be 0 }
its('stderr') { should eq '' }

let(:liens) do
if subject.exit_status == 0
JSON.parse(subject.stdout, symbolize_names: true)
else
[]
end
end

it "has no liens" do
expect(liens).to be_empty
end
end
end
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@ variable "app_engine" {
type = "map"
default = {}
}

variable "lien" {
description = "Add a lien on the project to prevent accidental deletion"
default = "false"
type = "string"
}

0 comments on commit 696a5a2

Please sign in to comment.