While Terraform as a tool is a cloud agnostic (in it it will support everything that its API provides and has sufficient developer support to create a “provider” for it), Terraform alone will not be able to distract this at all, and I would seriously consider whether this is really a good idea if you do not have a really good use case.
If you need it, you need to put together a bunch of modules on top of things that abstract the cloud layer from the users of the module and just let them specify the cloud provider as a variable (potentially controlled by an external script).
As a basic example for abstract DNS, you might have something like this (untested):
modules / google / dns / record / main.tf
variable "count" = {}
variable "domain_name_record" = {}
variable "domain_name_zone" = {}
variable "domain_name_target" = {}
resource "google_dns_record_set" "frontend" {
count = "${variable.count}"
name = "${var.domain_name_record}.${var.domain_name_zone}"
type = "CNAME"
ttl = 300
managed_zone = "${var.domain_name_zone}"
rrdatas = ["${var.domain_name_target}"]
}
Modules / AWS / DNS / Record / main.tf
variable "count" = {}
variable "domain_name_record" = {}
variable "domain_name_zone" = {}
variable "domain_name_target" = {}
data "aws_route53_zone" "selected" {
count = "${variable.count}"
name = "${var.domain_name_zone}"
}
resource "aws_route53_record" "www" {
count = "${variable.count}"
zone_id = "${data.aws_route53_zone.selected.zone_id}"
name = "${var.domain_name_record}.${data.aws_route53_zone.selected.name}"
type = "CNAME"
ttl = "60"
records = [${var.domain_name_target}]
}
modules / general / dns / record / main.tf
variable "cloud_provider" = { default = "aws" }
variable "domain_name_record" = {}
variable "domain_name_zone" = {}
variable "domain_name_target" = {}
module "aws_dns_record" {
source = "../../aws/dns/record"
count = "${var.cloud_provider == "aws" ? 1 : 0}"
domain_name_record = "${var.domain_name_record}"
domain_name_zone = "${var.domain_name_zone}"
domain_name_target = "${var.domain_name_target}"
}
module "google_dns_record" {
source = "../../google/dns/record"
count = "${var.cloud_provider == "google" ? 1 : 0}"
domain_name_record = "${var.domain_name_record}"
domain_name_zone = "${var.domain_name_zone}"
domain_name_target = "${var.domain_name_target}"
}
, , , "" , . , , , , StackOverflow.