Terraform Intitial MOP
Terraform Intitial MOP
The Hashicorp Terraform uses main.tf & variable.tf files in which you den define your
Tenant details along with its VRF, BD, Subnets, Application Profiles, Policies, and
Contracts.
You can push/remote the configuration on your ACI Fabric via APIC using a 4 step
procedure on Terraform:
1. Terraform Init - Terraform downloads all defined providers in your main.tf file.
2. Terraform Plan - Analyze your main.tf file and compare it to the state file
terraform.tfstate (if it exists) to determine what part of the plan must be deployed,
updated, or destroyed.
3. Terraform Apply - Apply the changes described by the plan command to the third-
party systems and update the terraform.tfstate file with the current configuration state
for the resources described in the plan.
4. Terraform Destroy - Remove or "unconfigure" all the resources previously deployed.
Terraform tracks those resources by using the state file terraform.tfstate.
Main.tf: Google:
/**
* you may not use this file except in compliance with the License.
* http://www.apache.org/licenses/LICENSE-2.0
* See the License for the specific language governing permissions and
*/
locals {
source_repos = setintersection(
toset(keys(var.app_infra_pipeline_service_accounts)),
toset(keys(var.sa_roles))
repo = repo
role = role
sa = var.app_infra_pipeline_service_accounts[repo]
]) : []
repo = repo
sa = var.app_infra_pipeline_service_accounts[repo]
]) : []
}
module "project" {
source = "terraform-google-modules/project-factory/google"
random_project_id = true
random_project_id_length = 4
name = "${var.project_prefix}-${var.business_code}-${local.env_code}-${var.project_suffix}"
org_id = var.org_id
billing_account = var.billing_account
folder_id = var.folder_id
svpc_host_project_id = var.shared_vpc_host_project_id
vpc_service_control_attach_enabled = var.vpc_service_control_attach_enabled
vpc_service_control_perimeter_name = var.vpc_service_control_perimeter_name
vpc_service_control_sleep_duration = var.vpc_service_control_sleep_duration
labels = {
environment = var.environment
application_name = var.application_name
billing_code = var.billing_code
business_code = var.business_code
env_code = local.env_code
vpc_type = var.vpc_type
budget_alert_pubsub_topic = var.project_budget.alert_pubsub_topic
budget_alert_spent_percents = var.project_budget.alert_spent_percents
budget_amount = var.project_budget.budget_amount
project = module.project.project_id
role = each.value.role
member = "serviceAccount:${each.value.sa}"
for_each = var.app_infra_pipeline_service_accounts
folder = var.folder_id
role = "roles/compute.networkViewer"
member = "serviceAccount:${each.value}"
provider = google-beta
role = "roles/compute.networkUser"
region = each.value.region
project = var.shared_vpc_host_project_id
member = "serviceAccount:${each.value.sa}"
Terraform AWS:
https://github.com/mdb/terraform-example/blob/master/terraform/main.tf
variable "region" {
default = "us-west-2"
variable "domain_name" {
default = "mikeball.me"
provider "aws" {
region = "${var.region}"
bucket = "${var.domain_name}"
region = "${var.region}"
acl = "public-read"
website {
index_document = "index.html"
error_document = "error.html"
policy = <<EOF
"Version": "2012-10-17",
"Statement": [{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": ["arn:aws:s3:::${var.domain_name}/*"]
}]
EOF
bucket = "www.${var.domain_name}"
region = "${var.region}"
acl = "public-read"
website {
redirect_all_requests_to = "${var.domain_name}"
bucket = "${var.domain_name}"
source = "../dist/index.html"
key = "index.html"
etag = "${md5(file("../dist/index.html"))}"
content_type = "text/html"
depends_on = [
"aws_s3_bucket.site"
bucket = "${var.domain_name}"
source = "../dist/error.html"
key = "error.html"
etag = "${md5(file("../dist/error.html"))}"
content_type = "text/html"
depends_on = [
"aws_s3_bucket.site"
bucket = "${var.domain_name}"
source = "../dist/assets/stylesheets/application.css"
key = "assets/stylesheets/application.css"
etag = "${md5(file("../dist/assets/stylesheets/application.css"))}"
content_type = "text/css"
depends_on = [
"aws_s3_bucket.site"
}
resource "aws_s3_bucket_object" "image_file" {
bucket = "${var.domain_name}"
source = "../dist/assets/images/scape_long.png"
key = "assets/images/scape_long.png"
etag = "${md5(file("../dist/assets/images/scape_long.png"))}"
content_type = "image/png"
depends_on = [
"aws_s3_bucket.site"
name = "${var.domain_name}"
zone_id = "${aws_route53_zone.primary.zone_id}"
name = "${var.domain_name}"
type = "A"
alias {
name = "${aws_s3_bucket.site.website_domain}"
zone_id = "${aws_s3_bucket.site.hosted_zone_id}"
evaluate_target_health = false
Variable.tf:
# variable.tf
# No default value
variable "instance_type" {
type = string
# No default value
variable "tag" {
type = string
variable "location" {
type = string
default = "eu-central1"