# Copyright 2021 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.

apiVersion: v1
kind: ConfigMap
metadata:
  name: terraform
  annotations:
    config.kubernetes.io/local-config: "true"
    blueprints.cloud.google.com/syntax: "hcl"
    blueprints.cloud.google.com/flavor: "terraform"
data:
  README.md: |+
    # Google Cloud Foundation Blueprint

    This directory contains Terraform configuration for a foundational environment on Google Cloud.

    It includes a subset of resources configured via the [setup checklist](https://cloud.google.com/docs/enterprise/setup-checklist)
    and is based on the [security foundations blueprint](https://cloud.google.com/architecture/security-foundations).

    ## Prerequisites

    To run the commands described in this document, you need the following:

    1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/install) version 319.0.0 or later
    1. Install [Terraform](https://www.terraform.io/downloads.html) version 0.13.7 or later.
    1. Set up a Google Cloud
       [organization](https://cloud.google.com/resource-manager/docs/creating-managing-organization).
    1. Set up a Google Cloud
       [billing account](https://cloud.google.com/billing/docs/how-to/manage-billing-account).
    1. For the user who will run the Terraform install, grant the
       following roles:
       -  The `roles/billing.admin` role on the billing account.
       -  The `roles/resourcemanager.organizationAdmin` role on the Google
          Cloud organization.
       -  The `roles/resourcemanager.folderCreator` role on the Google
          Cloud organization.
       -  The `roles/resourcemanager.projectCreator` role on the Google
          Cloud organization.

    ## Deploying

    1. Run `terraform init`.
    1. Run `terraform plan` and review the output.
    1. Run `terraform apply`.

    ## Next steps

    Once you have the basic foundation deployed, you should explore:
    1. Building an [advanced foundation](https://github.com/terraform-google-modules/terraform-example-foundation) using the security blueprint
    2. Automatically deploying Terraform with [Cloud Build](https://cloud.google.com/architecture/managing-infrastructure-as-code)
  folders.tf: |+
    resource "google_folder" "test" {
      display_name = "Test Display"
      parent       = "organizations/${var.org_id}"
    }
  variables.tf: |+
    variable "org_id" {
      description = "The organization id for the associated resources"
      type        = string
      default     = "123456789012"
    }
  versions.tf: |+
    terraform {
      required_version = ">=0.13"

      required_providers {
        google = {
          source  = "hashicorp/google"
          version = ">= 4.0.0"
        }
      }
      provider_meta "google" {
        module_name = "blueprints/terraform/exported-krm/v0.1.0"
      }
    }
