Managing Enterprise File Storage with OVHcloud Terraform provider
Objective
Enterprise File Storage is a storage solution that allows you to provision NFS volumes that are fully managed by OVHcloud. Terraform is an infrastructure-as-code tool that automates resource provisioning.
In this guide, you will learn how to use OVHcloud Terraform provider to manage your EFS solution volumes, snapshots and more.
In this guide, a volume is also called share as in the OVHcloud API.
Learn how manage your EFS service using Terraform.
Requirements
- Terraform >= 0.17.1
- OVHcloud Terraform provider >= v2.5.0
- Access to the OVHcloud API
- An Enterprise File Storage service. A service can be ordered from the product page or from the OVHcloud Control Panel.
Instructions
Configure the OVHcloud Terraform provider
Generate API credentials
The OVHcloud Teraform Provider needs to be configured with an API token to be able to make calls to the OVHcloud API.
The API token information is needed because the OVHcloud Terraform Provider is making requests to the OVHcloud API in the backend.
Your API token will need to have the following rights:
- GET
/storage/netapp/* - POST
/storage/netapp/* - PUT
/storage/netapp/* - DELETE
/storage/netapp/*
Follow the First steps with the OVHcloud APIs guide to generate your API token.
Once your token is generated, save its information for later use with the OVHcloud Terraform provider.
Get your service ID
The ID of your Enterprise File Storage service can be obtained via the OVHcloud API or the OVHcloud Control Panel.
If you are not familiar with using the OVHcloud API, please refer to our guide on Getting started with the OVHcloud API.
- API method: Call
GET /storage/netapp.
- OVHcloud Control Panel method: Navigate to the Enteprise File Storage section.
Configure provider parameters
Create a provider.tf file defining the OVHcloud provider configuration:
Then create a variables.tf file definining the variables that will be used inside your .tf files:
About the ovh.endpoint variable: by default, ovh-eu is defined because we are making calls to the OVHcloud Europe API.
Other endpoints exists, depending on your needs:
ovh-eufor OVHcloud Europe APIovh-cafor OVHcloud America/Asia API
Finally, create a secrets.tfvars file containing the required variable values:
Don't forget to replace <application_key>, <application_secret> and <consumer_key> with your API token information obtained previously.
Now you need to initiliaze Terraform:
The init command will initialize your working directory which contains .tf configuration files.
It’s the first command to execute for a new configuration, or after doing a checkout of an existing configuration in a given git repository for example.
The init command will download the necessary providers and initialize the backend.
Once the initialization is successfull you are now able to manage Enterprise File Storage resources and data sources that are availalable inside the OVHcloud Terraform provider.
Service management
Get service information
Use the ovh_storage_efs data source to fetch service details.
Create a main.tf file:
Define outputs in an output.tf file:
Run terraform apply to view the outputs:
Volumes Management
OVHcloud Terraform Provider allows the following volume management operations: creation, modification and deletion.
ovh_storage_efs_share resource represents a volume.
Create a volume
Define a volume inside your main.tf file:
Additionnal properties:
- A custom mount path can be specified using
mount_pathproperty. - The volume can be created from an existing snapshot using
snapshot_idproperty.
Run terraform plan to create the execution plan:
Key points:
-
The
terraform plancommand will create an execution plan but won't execute it. Instead, it will determine what actions are necessary to create the configuration specified inside your configuration files. This will allow you to verifiy whether your execution plan matches exectations before making any changes to actual resources. -
The optional
-outparameter allows your to specifiy an output file for the plan. It will ensure that the plan you reviewed will be the same as what is applied.
Once you reviewed the execution plan, run terraform apply to make changes:
Your volume is now created.
Modify a volume
Volume name, description and size can be updated.
Once the value(s) are updated inside your main.tf file, apply the changes using terraform apply.
Delete a volume
To delete your volume use terraform destroy command.
If your volume has manual snapshots that are not referenced by Terraform, they must be deleted before the volume is deleted.
Get information about volume access paths
To retrieve information about one or all of the volume access paths use ovh_storage_efs_share_access_paths and ovh_storage_efs_share_access_path data sources respectively.
Create or add to an existing main.tf file the following content:
You can (re-)use a volume that already exists (within your Terraform configuration or not).
Define access path outputs in an output.tf file:
Run terraform apply to add your data source and create outputs:
Snapshots Management
OVHcloud Terraform Provider allows the following snapshot management operations: creation, modification and deletion.
ovh_storage_efs_share_snapshot represents a volume snapshot.
Create a snapshot
Define a snapshot inside main.tf file:
You can (re-)use a volume that already exists (within your Terraform configuration or not) to create your snapshot.
The time_sleep resource manages delay between snapshot and volume deletion. The snapshot has to be deleted before the volume can be deleted.
If you don't already have the hashicorp/time provider installed, you will need to run terraform init -upgrade to download it.
Run terraform plan to create the execution plan:
Key points:
-
The
terraform plancommand will create an execution plan but won't execute it. Instead, it will determine what actions are necessary to create the configuration specified inside your configuration files. This will allow you to verifiy whether your execution plan matches exectations before making any changes to actual resources. -
The optional
-outparameter allows your to specifiy an output file for the plan. It will ensure that the plan you reviewed will be the same as what is applied.
Once you reviewed the execution plan, run terraform apply to make changes:
Your snapshot is now available.
Modify a snapshot
Snapshot name and description properties can be updated.
Once the value(s) are updated inside your main.tf file, apply the changes using terraform apply.
Delete a snapshot
To delete your snapshot use the terraform destroy command.
ACLs management
OVHcloud Terraform Provider allows ACLs creation and deletion.
ovh_storage_efs_share_acl resource represents an ACL.
Create an ACL
Define an ACL inside main.tf file:
You can (re-)use a volume that already exists (within your Terraform configuration or not) to create your ACL.
Run terraform plan to create the execution plan:
Key points:
-
The
terraform plancommand will create an execution plan but won't execute it. Instead, it will determine what actions are necessary to create the configuration specified inside your configuration files. This will allow you to verifiy whether your execution plan matches exectations before making any changes to actual resources. -
The optional
-outparameter allows your to specifiy an output file for the plan. It will ensure that the plan you reviewed will be the same as what is applied.
Once you reviewed the execution plan, run terraform apply to make changes:
Your ACL is now available.
Delete an ACL
To delete your ACL use the terraform destroy command.
Troubleshooting
- Authentication Issues: Verify API credentials and permissions.
- Resource Limits: Check volume/snapshot quota usage in the OVHcloud Control Panel.
- Volume Deletion Issues: Ensure all
manualsnapshots are deleted before removing the volume.
Go further
If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for assisting you on your specific use case of your project.
Join our community of users.