This provider is being deprecated in favor of https://github.com/mevansam/terraform-provider-cf which aims at moving to the https://github.com/terraform-providers github organization and becoming an official terraform provider.
The migration from terraform-provider-cloudfoundry
to terraform-provider-cf
can follow the procedure below:
terraform-provider-cloudfoundry
resource to terraform-provider-cf
resources. This can be made easier through IDE completion, see https://github.com/mevansam/terraform-provider-cf/pull/4terraform state list | grep cloudfoundry_domain | xargs -n 1 terraform state show
terraform-provider-cloudfoundry
resource from tfstate e.g. terraform state list | grep cloudfoundry_domain | xargs -n 1 terraform state remove
Potentially, such migration steps can be automated and scheduled into CI/CD such as https://github.com/ljfranklin/terraform-resource/issues/41
This terraform provider supports the use-case of managing a Cloud Foundry instance, with current support for:
You can also find useful terraform modules at https://github.com/orange-cloudfoundry/terraform-cloudfoundry-modules.
Requirements: You need, of course, terraform (>=0.8) which is available here: https://www.terraform.io/downloads.html
To install a specific version, set PROVIDER_CLOUDFOUNDRY_VERSION before executing the following command
$ export PROVIDER_CLOUDFOUNDRY_VERSION="v0.9.1"
$ bash -c "$(curl -fsSL https://raw.github.com/orange-cloudfoundry/terraform-provider-cloudfoundry/master/bin/install.sh)"
$ bash -c "$(wget https://raw.github.com/orange-cloudfoundry/terraform-provider-cloudfoundry/master/bin/install.sh -O -)"
Get the build for your system in releases: https://github.com/orange-cloudfoundry/terraform-provider-cloudfoundry/releases/latest
Create a providers
directory inside terraform user folder: mkdir -p ~/.terraform.d/providers
Move the provider previously downloaded in this folder: mv /path/to/download/directory/terraform-provider-cloudfoundry ~/.terraform.d/providers
Ensure provider is executable: chmod +x ~/.terraform.d/providers/terraform-provider-cloudfoundry
add providers
path to your .terraformrc
:
cat <<EOF > ~/.terraformrc
providers {
cloudfoundry = "/full/path/to/.terraform.d/providers/terraform-provider-cloudfoundry"
}
EOF
you can now performs any terraform action on Cloud Foundry resources
provider "cloudfoundry" {
api_endpoint = "https://api.of.your.cloudfoundry.com"
username = "user"
password = "mypassword"
skip_ssl_validation = true
enc_private_key = "${file("secring_b64.gpg")}"
enc_passphrase = "mypassphrase"
verbose = false
user_access_token = "bearer key"
user_refresh_token = "bearer key"
}
CF_API
) Your Cloud Foundry api url.null
, Env Var: CF_USERNAME
) The username of an admin user. (Optional if you use an access token)null
, Env Var: CF_PASSWORD
) The password of an admin user. (Optional if you use an access token)false
) Set to true to skip verification of the API endpoint. Not recommended!.null
, Env Var: CF_ENC_PRIVATE_KEY
) A GPG private key(s) generate from gpg --export-secret-key -a <real name>
. Need a passphrase with enc_passphrase
..null
, Env Var: CF_ENC_PASSPHRASE
) The passphrase for your gpg key.null
) Set to true to see requests sent to Cloud Foundry. (Use TF_LOG=1
to see them)null
, Env Var: CF_TOKEN
) The OAuth token used to connect to a Cloud Foundry. (Optional if you use 'username' and 'password')null
) The OAuth refresh token used to refresh your token.resource "cloudfoundry_organization" "org_mysuperorg" {
name = "mysuperorg"
is_system_domain = true
quota_id = "${cloudfoundry_quota.quota_mysuperquota.id}"
}
false
) set it to true only if this organization is a system_domain organization, it will prevent deletion on Cloud Foundry.null
) Give a quota id (created from resource cloudfoundry_quota) to set a quota on this org.Note: every parameters from resource which are not used here are marked as computed and will be filled.
data "cloudfoundry_organization" "org_mysuperorg" {
name = "mysuperorg"
// or by_id = "a-guid"
}
// get quota id for example: ${data.cloudfoundry_organization.cloudfoundry_organization.quota_id}
data "cloudfoundry_organizations" "available" {}
data "cloudfoundry_organization" "cloudfoundry_organization" {
name = "${data.cloudfoundry_organizations.available.names[0]}"
}
names
)resource "cloudfoundry_space" "space_mysuperspace" {
name = "mysuperspace"
org_id = "${cloudfoundry_organization.org_mysuperorg.id}"
quota_id = "${cloudfoundry_quota.quota_mysuperquota.id}"
sec_groups = ["${cloudfoundry_sec_group.sec_group_mysupersecgroup.id}"]
allow_ssh = true
}
true
) Set to false
to remove ssh access on app instances inside this space.null
) This is a list of security groups id created from cloudfoundry_sec_group, it will bind each security group on this space.null
) Give a quota id (created from resource cloudfoundry_quota) to set a quota on this space.Note: every parameters from resource which are not used here are marked as computed and will be filled.
data "cloudfoundry_space" "space_mysuperspace" {
name = "mysuperspace"
org_id = "${cloudfoundry_organization.org_mysuperorg.id}"
// or by_id = "a-guid"
}
data "cloudfoundry_spaces" "available" {
org_id = "${cloudfoundry_organization.org_mysuperorg.id}"
}
data "cloudfoundry_space" "space_mysuperspace" {
name = "${data.cloudfoundry_spaces.available.names[0]}"
org_id = "${cloudfoundry_organization.org_mysuperorg.id}"
}
names
)Note: There is two kinds of quotas inside Cloud Foundry: a space's quota, an organization's quota. This resource is able to find what kind of quota you defined. If you omit org_id
the resource will consider this
quota as an organization's quota. With it will consider it's a space's quota.
resource "cloudfoundry_quota" "quota_for_ahalet" {
name = "quotaAhalet"
org_id = "${cloudfoundry_organization.org_mysuperorg.id}"
total_memory = "10G"
instance_memory = "1G"
routes = 200
service_instances = 10
app_instances = -1
allow_paid_service_plans = true
reserved_route_ports = 0
}
null
) If set to an organization id created from resource or data source cloudfoundry_organization, it will be considered as organization quota, else it will be a space quota.20G
) Total amount of memory a space can have (e.g. 1024M, 1G, 10G).-1
) Maximum amount of memory an application instance can have (e.g. 1024M, 1G, 10G). -1 represents an unlimited amount.2000
) Total number of routes that a space can have.200
) Total number of service instances which can be created that a space can have.-1
) Total number of application instances that a space can have. -1 represents an unlimited amount.true
) Can provision instances of paid service plans.0
) Maximum number of routes that may be created with reserved ports in a space.Note: every parameters from resource which are not used here are marked as computed and will be filled.
data "cloudfoundry_quota" "quota_for_ahalet" {
name = "quotaAhalet"
org_id = "${cloudfoundry_organization.org_mysuperorg.id}"
// or by_id = "a-guid"
}
null
) If set to an organization id created from resource or data source cloudfoundry_organization, it will be considered as organization quota, else it will be a space quota.resource "cloudfoundry_sec_group" "sec_group_mysupersecgroup" {
name = "mysupersecgroup"
on_staging = false
on_running = false
rules {
protocol = "tcp"
destination = "10.0.0.2"
ports = "65000"
log = false
description = "my description"
}
rules {
protocol = "icmp"
destination = "192.0.2.0-192.0.1-4"
type = 3
code = 1
}
rules {
protocol = "all"
destination = "10.0.0.0/24"
log = true
}
}
false
) Set to true to apply this security group during staging an app.false
) Set to true to apply this security group during running an app.null
) Add rules as many as you need:
tcp
, udp
, icmp
, or all
null
) A single IP address, an IP address range (e.g. 192.0.2.0-192.0.1-4), or a CIDR block to allow network access to.null
) A single port, multiple comma-separated ports, or a single range of ports that can receive traffic, e.g. "443"
, "80,8080,8081"
, "8080-8081"
. Required when protocol
is tcp
or udp
. null
) ICMP code. Required when protocol
is icmp
. null
) ICMP type. Required when protocol
is icmp
. false
) Set to true
to enable logging. For more information about how to configure system logs to be sent to a syslog drain, see Using Log Management Services topic.null
) This is an optional field that contains useful text for operators to manage security group rules. This field is available in Cloud Foundry v238 and later.Note: every parameters from resource which are not used here are marked as computed and will be filled.
data "cloudfoundry_sec_group" "sec_group_mysupersecgroup" {
name = "mysupersecgroup"
// or by_id = "a-guid"
}
resource "cloudfoundry_buildpack" "buildpack_mysuperbuildpack" {
name = "mysuperbuildpack"
path = "https://github.com/cloudfoundry/staticfile-buildpack/releases/download/v1.3.13/staticfile_buildpack-cached-v1.3.13.zip"
position = 13
locked = false
enabled = false
}
php_buildpack
, java_buildpack
), so if you remove it from your tf file it will not be removed from your Cloud Foundry.null
) Path should be a zip file, a url to a zip file, or a local directory which contains your buildpack code.null
) Position is a positive integer, sets priority, and is sorted from lowest to highest.true
) Set to false
to disable the buildpack to be used for staging.false
) Set to true
to lock the buildpack to prevent updates.Note: every parameters from resource which are not used here are marked as computed and will be filled.
resource "cloudfoundry_buildpack" "buildpack_mysuperbuildpack" {
name = "mysuperbuildpack"
// or by_id = "a-guid"
}
resource "cloudfoundry_feature_flags" "feature_flags" {
diego_docker = true
custom_flag {
name = "my_flag"
enabled = true
}
}
List of default feature flags:
false
)true
)true
)true
)true
)true
)false
)true
)true
)false
)true
)true
)true
)Custom flags made for feature flags not in the default resource:
null
) Add cutom feature flags as many as you need:
true
to enable the feature in your cloud foundry.Feature flags cannot be used as data source
Service from marketplace:
resource "cloudfoundry_service" "svc_db" {
name = "my-db"
space_id = "${cloudfoundry_space.space_mysuperspace.id}"
service = "p-mysql"
plan = "100mb"
params = "{ \"my-param\": 1}"
update_params = "{ \"my-param\": 1}"
tags = [ "tag1", "tag2" ]
}
An user provided service:
resource "cloudfoundry_service" "svc_ups" {
name = "my-ups"
space_id = "${cloudfoundry_space.space_mysuperspace.id}"
user_provided = true
params = "{ \"my-credential\": 1}"
route_service_url = "http://my.route.com"
syslog_drain_url = "http://my.syslog.com"
tags = [ "tag1", "tag2" ]
}
false
) Set to true
to create an user provided service. Note: service
and plan
params will not be used.null
) Must be json, if it's an user provided service it will be credential for your service instead it will be params sent to service broker when creating service.null
) Must be json, Params sent to service broker when updating service.null
) list of tags for your service.null
) Only works for user provided, an url to create a route servicenull
) Only works for user provided, an url to drain logs as a service on an app.Note: every parameters from resource which are not used here are marked as computed and will be filled, except:
params
update_params
data "cloudfoundry_service" "svc_ups" {
name = "my-ups"
space_id = "${cloudfoundry_space.space_mysuperspace.id}"
// or by_id = "a-guid"
}
resource "cloudfoundry_domain" "domain_mydomain" {
name = "my.domain.com"
org_owner_id = "${cloudfoundry_organization.org_mysuperorg.id}"
router_group = "default-router"
orgs_shared_id = ["${cloudfoundry_organization.org_mysecondorg.id}"]
shared = false
}
null
) Set of organization id which can have access to domain. Note: Only can used when not a shared domainnull
) Routes for this domain will be configured only on the specified router group. Note: Only when when it's a shared domainfalse
) If True
this domain will be a shared domain.Note: every parameters from resource which are not used here are marked as computed and will be filled.
data "cloudfoundry_domain" "domain_mydomain" {
name = "my.domain.com"
org_owner_id = "${cloudfoundry_organization.org_mysuperorg.id}"
first = false
// or by_id = "a-guid"
}
first
param set to true
, default: null
) Your domain name.null
) If set to true
parameter name
or by_id
become unnecessary and will give the first domain found in your Cloud Foundry (it will be the first shared domain if org_owner_id
is not set).first
param set to true
or name
param set, default: null
) by_id of your domain.data "cloudfoundry_domains" "available" {
org_owner_id = "${cloudfoundry_organization.org_mysuperorg.id}"
}
data "cloudfoundry_domain" "space_mysuperspace" {
name = "${data.cloudfoundry_domains.available.names[0]}"
org_owner_id = "${cloudfoundry_organization.org_mysuperorg.id}"
}
names
)resource "cloudfoundry_route" "route_superroute" {
hostname = "superroute"
space_id = "${cloudfoundry_space.space_mysuperspace.id}"
domain_id = "${cloudfoundry_domain.domain_mydomain.id}"
port = -1
path = ""
service_id = "${cloudfoundry_service.svc_ups.id}"
service_params = "{ \"my-param\": 1}"
}
-1
) Set a port for your route (only works with a tcp domain). Note: If 0
a random port will be chosenull
) Set a path for your route (only works with a http(s) domain).null
) Set a service id created from resource or data source services this will bind a route service on your route. Note: It obviously needs a service which is a route service.null
) Must be in json, set params to send to service when binding on it.null
) This parameter is only for uri computed parameter it permits to override
the protocol when generating uri (generated uri will use always https
protocol when it's an http route, you can found useful to force in http
).Note: every parameters from resource which are not used here are marked as computed and will be filled, except:
service_params
resource "cloudfoundry_route" "route_superroute" {
hostname = "superroute"
domain_id = "${cloudfoundry_domain.domain_mydomain.id}"
port = -1
path = ""
// or by_id = "a-guid"
}
-1
) Set a port for your route (only works with a tcp domain). Note: If 0
a random port will be chosenull
) Set a path for your route (only works with a http(s) domain).null
) This parameter is only for uri computed parameter it permits to override
the protocol when generating uri (generated uri will use always https
protocol when it's an http route, you can found useful to force in http
).resource "cloudfoundry_isolation_segment" "my_isolation_segment" {
name = "isolation_segment_name_set_in_cf_deployment"
}
null
) You can pass a list of organization created from resource or data source cloudfoundry_organization, this will put those organizations in the isolation segment.Note: every parameters from resource which are not used here are marked as computed and will be filled.
data "cloudfoundry_isolation_segment" "my_isolation_segment" {
name = "isolation_segment_name_set_in_cf_deployment"
}
first
not set) Isolation segment that you have set on your cloud foundry deployment.shared
isolation segment.resource "cloudfoundry_isolation_segment_entitlement" "private_mysuperorg" {
segment_id = "${cloudfoundry_isolation_segment.my_isolation_segment.id}"
org_id = "${cloudfoundry_organization.org_mysuperorg.id}"
default = false
}
false
) Set this isolation segment as default segment for this organization.resource "cloudfoundry_isolation_segment_space" "private_mysuperspace" {
segment_id = "${cloudfoundry_isolation_segment.my_isolation_segment.id}"
space_id = "${cloudfoundry_organization.space_mysuperspace.id}"
}
Stacks cannot be used as a resource
Note: every parameters from resource which are not used here are marked as computed and will be filled.
data "cloudfoundry_stack" "my_stack" {
name = "cflinuxfs2"
first = false
// or by_id = "a-guid"
}
first
param set to true
, default: null
) Name of the stack.null
) If set to true
parameter name
become unnecessary and will give the first stack found in your Cloud Foundry.first
param set to true
or name
param set, default: null
) by_id of your stack.resource "cloudfoundry_env_var_group" "env_var_group" {
env_var {
key = "myvar1"
value = "myvalue1"
running = true
staging = true
}
env_var {
key = "myvar2"
value = "myvalue1"
running = true
staging = true
}
}
true
this env var will be use on all running app.true
this env var will be use during staging step when creating an app.Environment Variable Group cannot be used as a data source
resource "cloudfoundry_service_broker" "service_broker_mysuperbroker" {
name = "mysuperbroker"
url = "http://url.of.my.service.broker.com"
username = "user"
password = "mypassword"
service_access {
service = "service_name_from_service_broker_catalog"
plan = "plan_from_service_broker_catalog"
org_id = "${cloudfoundry_organization.org_mysuperorg.id}"
}
service_access {
service = "service_name_from_service_broker_catalog"
plan = "plan2_from_service_broker_catalog"
org_id = "${cloudfoundry_organization.org_mysuperorg.id}"
}
#...
}
null
) Username to authenticate to your service broker.null
) Password to authenticate to your service broker. Note: you can pass a base 64 encrypted gpg message if you enabled password encryption.null
) If set, your service broker will be created as a space-scoped service broker on this space.null
) Plan from your service broker catalog attached to this service to activate. Note: if no org_id
is given it will enable this plan on all orgs.null
) Org id created from resource or data source cloudfoundry_organization to activate this service. Note: if no plan
is given it will all plans on this org.BUG FOUND: if you set both plan
and org_id
in your service_access
Cloud Foundry will enable all plans on this org. It's maybe only on the version of Cloud Foundry I am. Feedbacks are needed on other versions.
Note: every parameters from resource which are not used here are marked as computed and will be filled, except:
username
password
resource "cloudfoundry_service_broker" "service_broker_mysuperbroker" {
name = "mysuperbroker"
// or by_id = "a-guid"
}
This resource is used in order to deploy and update an application. It can see changes between code you have locally and code you have in your cloud foundry to do the update fastly (It compares a checksum from a chunk of data between local and remotely)
By default, when updating, your app will never shutdown. It always use blue-green deployment when app bits changed, rename or scale number of instances instantly and do blue-green restage in all others modification.
As a terraform resource, creating an app give you more control but can also be more painful than using the cli.
To be painless, terraform modules can be use to deploy you app like you could do with a manifest.yml
file.
This can be found on https://github.com/orange-cloudfoundry/terraform-cloudfoundry-modules
resource "cloudfoundry_app" "myapp" {
name = "myapp"
stack_id = "${data.cloudfoundry_stack.my_stack.id}"
space_id = "${data.cloudfoundry_space.space_mysuperspace.id}"
started = true
instances = 2
memory = "64M"
disk_quota = "1G"
command = ""
path = "/path/to/folder"
diego = true
buildpack = "php_buildpack"
health_check_type = "port"
health_check_http_endpoint = ""
health_check_timeout = ""
docker_image = ""
enable_ssh = false
ports = [8080]
routes = ["${cloudfoundry_route.route_superroute.id}"]
services = ["${cloudfoundry_service.svc_db.id}"]
env_var = {
"MY_ENV_KEY" = "myvalue"
"MY_ENV_KEY2" = "myvalue2"
#...
}
}
true
) State of your application (should be start or not).1
) The number of instances of the app to run.512M
) The amount of memory each instance should have.1G
) The maximum amount of disk available to an instance of an app.NULL
) The command to start an app after it is staged.true
) Use diego to stage and to run when available (Diego should be always available because DEA is not supported anymore).NULL
) Buildpack to build the app. 3 options: a) Blank means autodetection; b) A Git Url pointing to a buildpack; c) Name of an installed buildpack.port
) Type of health check to perform. Others values are:
true
) when set to false app will not be started.NULL
) Endpoint called to determine if the app is healthy. (Can be use only when check type is http)NULL
) Timeout in seconds for health checking of an staged app when starting up.NULL
) Name of the Docker image containing the app. The "diego_docker" feature flag must be enabled in order to create Docker image apps.false
) Enable SSHing into the app. Supported for Diego only.8080
when diego is set to true
) List of ports on which application may listen. Overwrites previously configured ports.
Ports must be in range 1024-65535. Supported for Diego only. (Note: This is a copy of the default behaviour of cloud foundry cli, it always create a default port to 8080 when using diego backend)NULL
) List of route guid retrieve from resource or data source routes to attach routes to your app. NULL
) List of service guid retrieve from resource or data source services to bind services to your app.NULL
) Add any variable you want to the app environment.false
) If set to true
no blue green restage will be performed (it will restart the app).false
) If set to true
no blue green deployment will be performed.Note:
Note: every parameters from resource which are not used here are marked as computed and will be filled.
resource "cloudfoundry_service_broker" "myapp" {
name = "mysuperbroker"
space_id = "${data.cloudfoundry_space.space_mysuperspace.id}"
// or by_id = "a-guid"
}
space_id
set it will try to find the first matching app found in all spaces you have access to.null
) Space id created from resource or data source spaces.You can use gpg encryption to encrypt your service broker password.
Requirements: you will need to have gpg
on your system.
gpg --gen-key
, next steps will assume that you put cloudfoudry
as real name. (Do not forget to remember your passphrase!)gpg --export-secret-key -a cloudfoudry > private.key
private.key
and export CF_ENC_PRIVATE_KEY=content_of_private.key && export CF_ENC_PASSPHRASE=your_passphrase_that_you_remembered:)
):
provider "cloudfoundry" {
enc_private_key = "${file("private.key")}"
enc_passphrase = "your_passphrase_that_you_remembered:)"
}
gpg --export -a cloudfoudry > public.key
public.key
)gpg --import public.key
echo "mypassword" | gpg --encrypt --armor -r cloudfoudry > encrypted_pass.key
resource "cloudfoundry_service_broker" "service_broker_mysuperbroker" {
name = "mysuperbroker"
url = "http://url.of.my.service.broker.com"
username = "user"
password = "${file("encrypted_pass.key")}"
service_access {
service = "service_name_from_service_broker_catalog"
}
}