Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(interface): add more attributes/blocks/resources #756

Merged
merged 12 commits into from
Sep 15, 2023
118 changes: 116 additions & 2 deletions tests/interface/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ terraform {
}

resource "fastly_service_vcl" "interface-test-project" {
name = "interface-test-project"
activate = true
comment = "Fastly Terraform Provider: Interface Test Suite"
default_host = "interface-test-project.fastly-terraform.com"
default_ttl = 3600
force_destroy = true # Omitted `reuse` as it conflicts
http3 = false
name = "interface-test-project"
stale_if_error = false
stale_if_error_ttl = 43200
version_comment = "Fastly Terraform Provider: Version comment example"

acl {
name = "test_acl"
Expand All @@ -35,13 +44,28 @@ resource "fastly_service_vcl" "interface-test-project" {
type = "CACHE"
}

condition {
name = "test_prefetch_condition"
priority = 15
statement = "req.url~+\"index.html\""
type = "PREFETCH"
}

condition {
name = "test_req_condition"
priority = 5
statement = "req.url ~ \"^/foo/bar$\""
type = "REQUEST"
}

# Required for `waf` to work with no diff (see waf test file for details).
condition {
name = "test_req_condition_ALWAYS_FALSE"
priority = 10
statement = "!req.url"
type = "REQUEST"
}

condition {
name = "test_res_condition"
priority = 10
Expand Down Expand Up @@ -101,5 +125,95 @@ resource "fastly_service_vcl" "interface-test-project" {
window = 10
}

force_destroy = true
logging_bigquery {
account_name = "testloggingbigqueryaccountname"
dataset = "test_logging_bigquery_dataset"
email = "test_logging_bigquery@example.com"
name = "test_logging_bigquery"
project_id = "example-gcp-project"
secret_key = "<SECRET_KEY>"
table = "test_logging_bigquery_table"
template = "test_logging_bigquery_template"
}

product_enablement {
brotli_compression = false
domain_inspector = false
image_optimizer = false
origin_inspector = false
websockets = false
}

# rate_limiter {
# action = "response"
# client_key = "req.http.Fastly-Client-IP,req.http.User-Agent"
# feature_revision = 1
# http_methods = "POST,PUT,PATCH,DELETE"
# logger_type = "bigquery"
# name = "test_rate_limiter"
# penalty_box_duration = 30
#
# response {
# content = "test_rate_limiter_content"
# content_type = "plain/text"
# status = 429
# }
#
# response_object_name = "test_rate_limiter_response_object"
# rps_limit = 10
# # uri_dictionary_name = "test_dictionary" # Omitted as dictionary needs to exist before this is executed
# window_size = 60
# }

request_setting {
action = "pass"
bypass_busy_wait = true
default_host = "interface-test-project.fastly-terraform.com"
force_miss = true
force_ssl = false
geo_headers = false # DEPRECATED
hash_keys = "req.url.path, req.http.host" # Omitted because of error... Syntax error: Expected string variable or constant
max_stale_age = "300"
name = "test_request_setting"
request_condition = "test_req_condition"
timer_support = true
xff = "append"
}

response_object {
cache_condition = "test_cache_condition"
content = "test content"
content_type = "text/html"
name = "test_response_object"
request_condition = "test_req_condition"
response = "OK"
status = 200
}

response_object {
content = "content"
name = "test_response_object_waf"
request_condition = "test_req_condition_ALWAYS_FALSE"
response = "Forbidden"
status = "403"
}

snippet {
content = "if ( req.url ) { set req.http.different-header = \"true\"; }"
name = "recv_test"
priority = 110
type = "recv"
}

vcl {
content = "# some vcl here"
main = true
name = "test_vcl"
}

waf {
disabled = false
prefetch_condition = "test_prefetch_condition"
response_object = "test_response_object_waf"
}
}
28 changes: 15 additions & 13 deletions tests/interface/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

cd ./tests/interface/ || exit

echo DEPLOYING USING LATEST TERRAFORM VERSION
terraform init -upgrade
terraform apply -auto-approve

cleanup() {
# reset back to the installed provider so we can destroy the service
unset TF_CLI_CONFIG_FILE
terraform init
echo ""
echo "Running terraform destroy..."
terraform destroy -auto-approve
# reset back to the installed provider so we can destroy the service
unset TF_CLI_CONFIG_FILE
terraform init
echo ""
echo "Running terraform destroy..."
terraform destroy -auto-approve
}
trap cleanup EXIT

Expand All @@ -22,15 +23,16 @@ OVERRIDES_FILENAME=developer_overrides.tfrc
export TF_CLI_CONFIG_FILE="$BIN_DIR/$OVERRIDES_FILENAME"
cd - || exit

echo RUNNING PLAN USING TERRAFORM VERSION BUILT FROM THIS BRANCH
plan_output=$(terraform plan -no-color 2>&1)

if [[ "$plan_output" == *"No changes. Your infrastructure matches the configuration."* ]]; then
echo ""
echo "Terraform plan succeeded: No changes detected."
exit 0
echo ""
echo "Terraform plan succeeded: No changes detected."
exit 0
else
echo ""
echo "Terraform plan failed: Changes detected or unexpected output."
echo "$plan_output"
exit 1
echo ""
echo "Terraform plan failed: Changes detected or unexpected output."
echo "$plan_output"
exit 1
fi