Created
October 17, 2019 16:12
-
-
Save nickmoorman/0d883c2b5a7ede4f53c539d8fea7a76f to your computer and use it in GitHub Desktop.
Support files for terraform-providers/terraform-provider-google PR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
GCP_PROJECT="<REDACTED>" | |
function write_provider { | |
version=$1 | |
cat > provider.tf << EOF | |
provider "google" { | |
project = "$GCP_PROJECT" | |
region = "us-central1" | |
version = "~> $version" | |
} | |
EOF | |
} | |
function write_provider_no_version { | |
cat > provider.tf << EOF | |
provider "google" { | |
project = "$GCP_PROJECT" | |
region = "us-central1" | |
} | |
EOF | |
} | |
function bigtable_conf_1_cluster { | |
read -r -d '' bigtable_conf << EOF | |
resource "google_bigtable_instance" "test_instance" { | |
name = "test-instance" | |
cluster { | |
cluster_id = "cluster1" | |
zone = "us-central1-a" | |
num_nodes = 3 | |
storage_type = "SSD" | |
} | |
} | |
EOF | |
} | |
function bigtable_conf_4_clusters { | |
read -r -d '' bigtable_conf << EOF | |
resource "google_bigtable_instance" "test_instance" { | |
name = "test-instance" | |
cluster { | |
cluster_id = "cluster1" | |
zone = "us-central1-a" | |
num_nodes = 3 | |
storage_type = "SSD" | |
} | |
cluster { | |
cluster_id = "cluster2" | |
zone = "us-central1-a" | |
num_nodes = 3 | |
storage_type = "SSD" | |
} | |
cluster { | |
cluster_id = "cluster3" | |
zone = "us-central1-a" | |
num_nodes = 3 | |
storage_type = "SSD" | |
} | |
cluster { | |
cluster_id = "cluster4" | |
zone = "us-central1-a" | |
num_nodes = 3 | |
storage_type = "SSD" | |
} | |
} | |
EOF | |
} | |
function save_state { | |
filename=$1 | |
terraform state pull | jq '.modules[0].resources."google_bigtable_instance.test_instance"' > output/$filename | |
} | |
function run_test { | |
version=$1 | |
filename_part=$2 | |
echo "===== Running $filename_part test for v${version} =====" | |
if [[ $filename_part == "1cluster" ]]; then | |
bigtable_conf_1_cluster | |
else | |
bigtable_conf_4_clusters | |
fi | |
created_file_name=${version}_${filename_part}_created.json | |
migrated_file_name=${version}_${filename_part}_migrated.json | |
diff_file_name=${version}_${filename_part}.json.diff | |
echo "----- Initializing provider version -----" | |
write_provider $version | |
terraform init -backend-config=backend.conf | |
echo "----- Creating instance -----" | |
echo "$bigtable_conf" > bigtable.tf | |
terraform apply -auto-approve | |
echo "----- Saving state -----" | |
save_state $created_file_name | |
echo "----- Switching to local provider build -----" | |
rm .terraform/plugins/darwin_amd64/terraform-provider-google_v${version}_x4 | |
write_provider_no_version | |
terraform init -backend-config=backend.conf | |
echo "----- Migrating state -----" | |
terraform apply | |
echo "----- Saving state -----" | |
save_state $migrated_file_name | |
echo "----- Deleting instance -----" | |
rm bigtable.tf | |
terraform apply -auto-approve | |
echo "----- Writing diff file -----" | |
diff output/$created_file_name output/$migrated_file_name > output/$diff_file_name | |
} | |
function run_test_for_latest { | |
filename_part=$1 | |
echo "===== Running $filename_part test for latest build =====" | |
if [[ $filename_part == "1cluster" ]]; then | |
bigtable_conf_1_cluster | |
else | |
bigtable_conf_4_clusters | |
fi | |
created_file_name=latest_${filename_part}_created.json | |
echo "----- Switching to local provider build -----" | |
plugin_file_glob=.terraform/plugins/darwin_amd64/terraform-provider-google_v* | |
if [[ -f $plugin_file_glob ]]; then | |
rm $plugin_file_glob | |
fi | |
write_provider_no_version | |
terraform init -backend-config=backend.conf | |
echo "----- Creating instance -----" | |
echo "$bigtable_conf" > bigtable.tf | |
terraform apply -auto-approve | |
echo "----- Saving state -----" | |
save_state $created_file_name | |
echo "----- Deleting instance -----" | |
rm bigtable.tf | |
terraform apply -auto-approve | |
} | |
if [[ ! -d output ]]; then | |
mkdir output | |
fi | |
run_test 1.19.1 1cluster | |
for version in 2.13.0 2.14.0 2.15.0 2.16.0; do | |
for clusters in 1cluster 4clusters; do | |
run_test $version $clusters | |
done | |
done | |
for clusters in 1cluster 4clusters; do | |
run_test_for_latest $clusters | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8,12c8,11 | |
< "cluster.3909609229.cluster_id": "cluster1", | |
< "cluster.3909609229.num_nodes": "3", | |
< "cluster.3909609229.storage_type": "SSD", | |
< "cluster.3909609229.zone": "us-central1-a", | |
< "cluster_id": "", | |
--- | |
> "cluster.0.cluster_id": "cluster1", | |
> "cluster.0.num_nodes": "3", | |
> "cluster.0.storage_type": "SSD", | |
> "cluster.0.zone": "us-central1-a", | |
17,20c16,19 | |
< "num_nodes": "0", | |
< "project": "<REDACTED>", | |
< "storage_type": "SSD", | |
< "zone": "" | |
--- | |
> "project": "<REDACTED>" | |
> }, | |
> "meta": { | |
> "schema_version": "1" | |
22d20 | |
< "meta": {}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8,11c8,11 | |
< "cluster.3909609229.cluster_id": "cluster1", | |
< "cluster.3909609229.num_nodes": "3", | |
< "cluster.3909609229.storage_type": "SSD", | |
< "cluster.3909609229.zone": "us-central1-a", | |
--- | |
> "cluster.0.cluster_id": "cluster1", | |
> "cluster.0.num_nodes": "3", | |
> "cluster.0.storage_type": "SSD", | |
> "cluster.0.zone": "us-central1-a", | |
18c18,20 | |
< "meta": {}, | |
--- | |
> "meta": { | |
> "schema_version": "1" | |
> }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8,23c8,23 | |
< "cluster.274830331.cluster_id": "cluster4", | |
< "cluster.274830331.num_nodes": "3", | |
< "cluster.274830331.storage_type": "SSD", | |
< "cluster.274830331.zone": "us-central1-a", | |
< "cluster.3190147935.cluster_id": "cluster2", | |
< "cluster.3190147935.num_nodes": "3", | |
< "cluster.3190147935.storage_type": "SSD", | |
< "cluster.3190147935.zone": "us-central1-a", | |
< "cluster.3909609229.cluster_id": "cluster1", | |
< "cluster.3909609229.num_nodes": "3", | |
< "cluster.3909609229.storage_type": "SSD", | |
< "cluster.3909609229.zone": "us-central1-a", | |
< "cluster.974443182.cluster_id": "cluster3", | |
< "cluster.974443182.num_nodes": "3", | |
< "cluster.974443182.storage_type": "SSD", | |
< "cluster.974443182.zone": "us-central1-a", | |
--- | |
> "cluster.0.cluster_id": "cluster1", | |
> "cluster.0.num_nodes": "3", | |
> "cluster.0.storage_type": "SSD", | |
> "cluster.0.zone": "us-central1-a", | |
> "cluster.1.cluster_id": "cluster3", | |
> "cluster.1.num_nodes": "3", | |
> "cluster.1.storage_type": "SSD", | |
> "cluster.1.zone": "us-central1-a", | |
> "cluster.2.cluster_id": "cluster2", | |
> "cluster.2.num_nodes": "3", | |
> "cluster.2.storage_type": "SSD", | |
> "cluster.2.zone": "us-central1-a", | |
> "cluster.3.cluster_id": "cluster4", | |
> "cluster.3.num_nodes": "3", | |
> "cluster.3.storage_type": "SSD", | |
> "cluster.3.zone": "us-central1-a", | |
30c30,32 | |
< "meta": {}, | |
--- | |
> "meta": { | |
> "schema_version": "1" | |
> }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18c18,20 | |
< "meta": {}, | |
--- | |
> "meta": { | |
> "schema_version": "1" | |
> }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "google_bigtable_instance", | |
"depends_on": [], | |
"primary": { | |
"id": "test-instance", | |
"attributes": { | |
"cluster.#": "1", | |
"cluster.0.cluster_id": "cluster1", | |
"cluster.0.num_nodes": "3", | |
"cluster.0.storage_type": "SSD", | |
"cluster.0.zone": "us-central1-a", | |
"display_name": "test-instance", | |
"id": "test-instance", | |
"instance_type": "PRODUCTION", | |
"name": "test-instance", | |
"project": "<REDACTED>" | |
}, | |
"meta": { | |
"schema_version": "1" | |
}, | |
"tainted": false | |
}, | |
"deposed": [], | |
"provider": "provider.google" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "google_bigtable_instance", | |
"depends_on": [], | |
"primary": { | |
"id": "test-instance", | |
"attributes": { | |
"cluster.#": "4", | |
"cluster.0.cluster_id": "cluster1", | |
"cluster.0.num_nodes": "3", | |
"cluster.0.storage_type": "SSD", | |
"cluster.0.zone": "us-central1-a", | |
"cluster.1.cluster_id": "cluster2", | |
"cluster.1.num_nodes": "3", | |
"cluster.1.storage_type": "SSD", | |
"cluster.1.zone": "us-central1-a", | |
"cluster.2.cluster_id": "cluster3", | |
"cluster.2.num_nodes": "3", | |
"cluster.2.storage_type": "SSD", | |
"cluster.2.zone": "us-central1-a", | |
"cluster.3.cluster_id": "cluster4", | |
"cluster.3.num_nodes": "3", | |
"cluster.3.storage_type": "SSD", | |
"cluster.3.zone": "us-central1-a", | |
"display_name": "test-instance", | |
"id": "test-instance", | |
"instance_type": "PRODUCTION", | |
"name": "test-instance", | |
"project": "<REDACTED>" | |
}, | |
"meta": { | |
"schema_version": "1" | |
}, | |
"tainted": false | |
}, | |
"deposed": [], | |
"provider": "provider.google" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment