Skip to content

Commit 238cf0f

Browse files
authored
feat: commented the tf-apply step (#15)
* bumped the tf version to 1.8.0 * commented the tf-apply step * chnaged the working directory * added additional arg to ingore low, med sev issues * added additional arg to ingore low, med sev issues * added additional arg to ingore low, med sev issues * project arg added in subnet code
1 parent 67fa878 commit 238cf0f

10 files changed

+104
-42
lines changed

.github/workflows/gitops.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ on:
99
workflow_dispatch:
1010
defaults:
1111
run:
12-
working-directory: ./tf-variables/
12+
working-directory: ./tf-count/
1313
env:
1414
TERRAFORM_VER: 1.8.0
15-
TERRAFORM_DIR: "./tf-variables/"
15+
TERRAFORM_DIR: "./tf-count/"
1616
CLOUDSDK_VER: 480.0.0
1717
permissions:
1818
pull-requests: write
@@ -44,6 +44,7 @@ jobs:
4444
uses: aquasecurity/tfsec-action@v1.0.3
4545
with:
4646
working_directory: ${{ env.TERRAFORM_DIR }}
47+
additional_args: --minimum-severity HIGH
4748

4849
# Install the latest version of Google Cloud SDK
4950
- id: cloud_sdk_installation
@@ -128,10 +129,10 @@ jobs:
128129
})
129130

130131
# Executes the apply operation to deploy the actual infrastructure
131-
- name: Terraform Apply
132-
id: tf_apply
133-
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
134-
run: terraform apply -auto-approve
132+
# - name: Terraform Apply
133+
# id: tf_apply
134+
# if: github.ref == 'refs/heads/master' && github.event_name == 'push'
135+
# run: terraform apply -auto-approve
135136

136137
- name: Notify success
137138
if: success() # this step runs only if the previous steps succeeded.

tf-count/backend.tf

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
1. Create the GCS Bucket using Cloud SDK / Cloud Shell:
3+
> gcloud auth login
4+
> gcloud config set project PROJECT_ID
5+
> gsutil mb -c standard -l eu gs://bkt-tfstates-xxxxxx
6+
7+
2. Set the Bucket versioning.
8+
> gsutil versioning set on gs://bkt-tfstates-xxxxxx
9+
10+
3. Clean-up process
11+
> gcloud storage rm --recursive gs://bkt-tfstates-xxxxxx
12+
*/
13+
14+
// Configure Google Cloud Storage (GCS) Backend
15+
terraform {
16+
backend "gcs" {
17+
bucket = "bkt-tfstates-15062024"
18+
prefix = "tst/tf-count"
19+
}
20+
}

tf-count/gcp_network.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Resource block to deploy vpc network
1+
# Resource block to deploy vpc network
22
resource "google_compute_network" "tst_vpc" {
33
project = var.project_id
44
name = var.vpc_name
55
routing_mode = "GLOBAL"
66
auto_create_subnetworks = var.auto_create_subnetworks
77
delete_default_routes_on_create = var.delete_default_routes
8-
}
8+
}

tf-count/gcp_subnetwork.tf

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// Resource block to deploy Subnetwork
1+
# Resource block to deploy Subnetwork
22
resource "google_compute_subnetwork" "tst_vpc_subnet" {
33
count = length(var.subnet_name)
44

5+
project = var.project_id
56
name = var.subnet_name[count.index]
67
ip_cidr_range = var.subnet_cidr[count.index]
78
region = var.default_region
89
private_ip_google_access = true
910
network = google_compute_network.tst_vpc.id
10-
}
11+
}

tf-count/outputs.tf

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
// Resource outputs
1+
# Resource outputs
22
output "tst_vpc_subnet_all" {
33
description = "The VPC resource being created"
44
value = google_compute_subnetwork.tst_vpc_subnet
55
}
66

7-
/*************************************************
8-
Output using for expression
9-
*************************************************/
7+
# Output using for expression
108
output "tst_vpc_subnet_ids_01" {
119
description = "The IDs of the subnets being created."
1210
value = [
@@ -23,10 +21,8 @@ output "tst_vpc_subnet_details" {
2321
}
2422
}
2523

26-
/*************************************************
27-
Output using splat expression
28-
*************************************************/
24+
# Output using splat expression
2925
output "tst_vpc_subnet_ids_02" {
3026
description = "The IDs of the subnets being created."
3127
value = google_compute_subnetwork.tst_vpc_subnet[*].id
32-
}
28+
}

tf-count/providers.tf

-12
This file was deleted.

tf-count/providers.tf.disabled

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Locals block to hold and modify the values
2+
locals {
3+
tf_sa = var.terraform_service_account
4+
}
5+
6+
provider "google" {
7+
alias = "tokengen"
8+
}
9+
10+
data "google_service_account_access_token" "default" {
11+
provider = google.tokengen
12+
target_service_account = local.tf_sa
13+
14+
// To see, edit, configure, and delete your Google Cloud data
15+
scopes = ["https://www.googleapis.com/auth/cloud-platform"]
16+
lifetime = "600s"
17+
}
18+
19+
/******************************************
20+
GA Provider credential configuration
21+
*****************************************/
22+
23+
provider "google" {
24+
// configure the default project and region.
25+
project = var.project_id
26+
region = var.default_region
27+
zone = var.default_zone
28+
29+
// A temporary OAuth 2.0 access token obtained from the Google Authorization server
30+
// used to authenticate HTTP requests to GCP APIs.
31+
access_token = data.google_service_account_access_token.default.access_token
32+
}
33+
34+
/******************************************
35+
Beta Provider credential configuration
36+
*****************************************/
37+
38+
provider "google-beta" {
39+
// configure the default project and region.
40+
project = var.project_id
41+
region = var.default_region
42+
zone = var.default_zone
43+
44+
// A temporary OAuth 2.0 access token obtained from the Google Authorization server
45+
// used to authenticate HTTP requests to GCP APIs.
46+
access_token = data.google_service_account_access_token.default.access_token
47+
}

tf-count/terraform.tfvars

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// Variables definition
2-
project_id = "prj-tf-training"
3-
default_region = "us-central1"
4-
default_zone = "us-central1-a"
1+
# Variables definition
2+
project_id = "tidy-interface-421310"
3+
default_region = "us-central1"
4+
default_zone = "us-central1-a"
5+
terraform_service_account = "infra-prov-svc-acc@tidy-interface-421310.iam.gserviceaccount.com"
6+
57
vpc_name = "fdn-tst-vpc-01"
68
auto_create_subnetworks = "false"
79
delete_default_routes = false
810
subnet_name = ["fdn-tst-subnet-01", "fdn-tst-subnet-02"]
9-
subnet_cidr = ["10.0.40.0/24", "10.0.42.0/24"]
11+
subnet_cidr = ["10.0.40.0/24", "10.0.42.0/24"]

tf-count/variables.tf

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Variables declaration
1+
# Variables declaration
22
variable "project_id" {
33
type = string
44
description = "The ID of the google project to house the resources."
@@ -14,6 +14,13 @@ variable "default_zone" {
1414
description = "The default zone to create the google cloud zonal resources."
1515
}
1616

17+
variable "terraform_service_account" {
18+
type = string
19+
description = "Terraform service account to execute the terraform code."
20+
# Make sure to give "roles/iam.serviceAccountTokenCreator" role to an identity (who will trigger the terraform code) on this service account for the impersonation to succeed.
21+
}
22+
23+
1724
variable "vpc_name" {
1825
description = "The name of the VPC network being created."
1926
type = string
@@ -44,4 +51,4 @@ variable "subnet_name" {
4451
variable "subnet_cidr" {
4552
type = list(string)
4653
description = "The list of the CIDR range of the subnets."
47-
}
54+
}

tf-count/versions.tf

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
// Terraform block to configure terraform and provider version
1+
# Terraform block to configure terraform and provider version
22
terraform {
3-
required_version = "~> 1.3.6"
3+
required_version = "~> 1.8.0"
44

55
required_providers {
66
google = {
77
source = "hashicorp/google"
8-
version = "~> 4.55.0"
8+
version = "~> 5.33.0"
99
}
1010
google-beta = {
1111
source = "hashicorp/google-beta"
12-
version = "~> 4.55.0"
12+
version = "~> 5.33.0"
1313
}
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)