Create or upload using Terraform
You can apply an NGINX configuration to your F5 Application Delivery Service deployment using the F5 ADS Terraform provider.
Use the f5ads_configuration resource in the F5Networks/f5ads Terraform provider to manage NGINX configurations for F5 Application Delivery Service.
Provide configuration files as base64-encoded content. Applying changes to the files creates a new configuration version.
Creating a configuration doesn’t attach it to a deployment. For Google Cloud deployments, follow Create a deployment to apply the configuration.
For Google Cloud deployments, meet the following prerequisites:
- Confirm that you meet the F5 ADS for Google Cloud prerequisites.
- Access to a Google Cloud project to manage your network resources.
- Access to the F5 ADS Console to create client credentials. See Automate access with client credentials.
- Install Terraform.
ImportantTheF5Networks/f5adsprovider is in alpha (0.1.0-alpha.7). Pin this exact version in yourrequired_providersblock, since breaking changes can occur between alpha releases.
Review the NGINX configuration rules and limits before you upload your files.
If you already configured the provider, use the same Terraform working directory. Otherwise, add the f5ads provider to your Terraform configuration and pin it to the exact alpha version:
terraform {
required_providers {
f5ads = {
source = "F5Networks/f5ads"
version = "0.1.0-alpha.7"
}
}
}
provider "f5ads" {
geo = "us"
}The provider needs your Application Delivery Service client credentials to authenticate. You can supply them in the provider block or with environment variables.
To supply credentials in the provider block, replace the previous provider block with the following example:
provider "f5ads" {
geo = "us"
client_id = "your-client-id"
client_secret = "your-client-secret"
}Alternatively, set the following environment variables:
export F5ADS_GEO="us"
export F5ADS_CLIENT_ID="your-client-id"
export F5ADS_CLIENT_SECRET="your-client-secret"The following example returns an HTTP 200 response on port 80.
locals {
nginx_conf = <<-EOT
user nginx;
worker_processes auto;
pid /run/nginx/nginx.pid;
worker_rlimit_nofile 524288;
events {
worker_connections 150000;
}
http {
server {
listen 80 backlog=2048 default_server;
http2 on;
server_name _;
location / {
return 200 "Hello from F5 ADS!";
}
}
}
EOT
}
resource "f5ads_configuration" "example" {
name = "example-config"
description = "Example F5 ADS configuration managed by Terraform."
configs = [
{
name = "/etc/nginx"
files = [
{
name = "nginx.conf"
contents = base64encode(local.nginx_conf)
},
]
},
]
lifecycle {
create_before_destroy = true
}
}Use these settings for your configuration files:
- For the main NGINX configuration file, set the directory
nameto/etc/nginxand the filenametonginx.conf. The provider requires this destination path. - Base64-encode file contents with
base64encode()for inline content orfilebase64()for local files. - Set either
nameorname_prefix, but not both.
For all arguments, see the f5ads_configuration resource documentation.
Add other files to files, or add directory entries to configs, as needed. Include every file that your NGINX configuration references.
terraform init
terraform plan
terraform applyTerraform creates the configuration.
Changes to configuration files create a new version without replacing the resource. Changes to name or name_prefix replace the resource itself.
For configurations referenced by a deployment, use the create_before_destroy Terraform lifecycle block so that Terraform creates a new configuration, updates the deployment, and then deletes the old configuration.
Replace the resource definition in Create a configuration with this example, keeping the locals block:
resource "f5ads_configuration" "example" {
name_prefix = "example-config"
description = "NGINX configuration uploaded with Terraform."
configs = [
{
name = "/etc/nginx"
files = [
{
name = "nginx.conf"
contents = base64encode(local.nginx_conf)
},
]
},
]
lifecycle {
create_before_destroy = true
}
}Review the replacement plan before applying it.