| copyright |
|
||
|---|---|---|---|
| lastupdated | 2025-04-03 | ||
| subcollection | security-groups |
{{site.data.keyword.attribute-definition-list}}
{: #terraform-setup}
Terraform on {{site.data.keyword.cloud}} enables predictable and consistent provisioning of {{site.data.keyword.cloud_notm}} services so that you can rapidly build complex, multi-tier cloud environments following Infrastructure as Code (IaC) principles. Similar to using the {{site.data.keyword.cloud_notm}} CLI or API and SDKs, you can automate the provisioning, update, and deletion of your security group instances by using HashiCorp Configuration Language (HCL). {: shortdesc}
Looking for a managed Terraform on {{site.data.keyword.cloud}} solution? Try out {{site.data.keyword.bplong}}. With {{site.data.keyword.bpshort}}, you can use the Terraform scripting language that you are familiar with, but you don't have to worry about setting up and maintaining the Terraform command line and the {{site.data.keyword.cloud}} Provider plug-in. {{site.data.keyword.bpshort}} also provides pre-defined Terraform templates that you can easily install from the {{site.data.keyword.cloud}} catalog. {: tip}
{: #install-terraform}
Before you can create an authorization by using Terraform, make sure that you have completed the following:
- Make sure that you have the required access to create and work with security group resources.
- Install the Terraform CLI and configure the {{site.data.keyword.cloud_notm}} Provider plug-in for Terraform. For more information, see the tutorial for Getting started with Terraform on {{site.data.keyword.cloud}}. The plug-in abstracts the {{site.data.keyword.cloud_notm}} APIs that are used to complete this task.
- Create a Terraform configuration file that is named
main.tf. In this file, you define resources by using HashiCorp Configuration Language. For more information, see the Terraform documentation{: external}.
-
Create a security groups instance by using the
ibm_resource_instanceresource argument in yourmain.tffile.The security group resource in the following example is named
sg1. For more information, see the ibm_security_group{: external} usage example.resource "ibm_security_group" "sg1" { name = "sg1" description = "allow my app traffic" }
{: codeblock}
-
After you finish building your configuration file, initialize the Terraform CLI. For more information, see Initializing Working Directories{: external}.
terraform init
{: codeblock}
-
Provision the resources from the
main.tffile. For more information, see Provisioning Infrastructure with Terraform{: external}.-
Run
terraform planto generate a Terraform execution plan to preview the proposed actions.terraform plan
{: pre}
-
Run
terraform applyto create the resources that are defined in the plan.terraform apply
{: pre}
-
-
From the {{site.data.keyword.cloud_notm}} resource list{: external}, select the {{site.data.keyword.keymanagementserviceshort}} instance that you created and note the instance ID.
-
Verify that the access policy is successfully assigned. For more information, see Reviewing assigned access in the console.