|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +page_title: "CloudStack: cloudstack_cni_configuration" |
| 4 | +sidebar_current: "docs-cloudstack-resource-cni_configuration" |
| 5 | +description: |- |
| 6 | + Creates and manages a CloudStack CNI (Container Network Interface) configuration |
| 7 | +--- |
| 8 | + |
| 9 | +# CloudStack: cloudstack_cni_configuration |
| 10 | + |
| 11 | +A `cloudstack_cni_configuration` resource manages a Container Network Interface (CNI) configuration for CloudStack Kubernetes Service (CKS) clusters. CNI configurations define how network connectivity is provided to Kubernetes pods. |
| 12 | + |
| 13 | +## Example Usage |
| 14 | + |
| 15 | +### Basic Calico CNI Configuration |
| 16 | + |
| 17 | +```hcl |
| 18 | +resource "cloudstack_cni_configuration" "calico" { |
| 19 | + name = "calico-cni-config" |
| 20 | + cni_config = base64encode(jsonencode({ |
| 21 | + "name" = "k8s-pod-network", |
| 22 | + "cniVersion" = "0.3.1", |
| 23 | + "plugins" = [ |
| 24 | + { |
| 25 | + "type" = "calico", |
| 26 | + "log_level" = "info", |
| 27 | + "datastore_type" = "kubernetes", |
| 28 | + "nodename" = "KUBERNETES_NODE_NAME", |
| 29 | + "mtu" = "CNI_MTU", |
| 30 | + "ipam" = { |
| 31 | + "type" = "calico-ipam" |
| 32 | + }, |
| 33 | + "policy" = { |
| 34 | + "type" = "k8s" |
| 35 | + }, |
| 36 | + "kubernetes" = { |
| 37 | + "kubeconfig" = "KUBECONFIG_FILEPATH" |
| 38 | + } |
| 39 | + }, |
| 40 | + { |
| 41 | + "type" = "portmap", |
| 42 | + "snat" = true, |
| 43 | + "capabilities" = { "portMappings" = true } |
| 44 | + } |
| 45 | + ] |
| 46 | + })) |
| 47 | + |
| 48 | + params = [ |
| 49 | + "KUBERNETES_NODE_NAME", |
| 50 | + "CNI_MTU", |
| 51 | + "KUBECONFIG_FILEPATH" |
| 52 | + ] |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Flannel CNI Configuration |
| 57 | + |
| 58 | +```hcl |
| 59 | +resource "cloudstack_cni_configuration" "flannel" { |
| 60 | + name = "flannel-cni-config" |
| 61 | + cni_config = base64encode(jsonencode({ |
| 62 | + "name" = "cbr0", |
| 63 | + "cniVersion" = "0.3.1", |
| 64 | + "plugins" = [ |
| 65 | + { |
| 66 | + "type" = "flannel", |
| 67 | + "delegate" = { |
| 68 | + "hairpinMode" = true, |
| 69 | + "isDefaultGateway" = true |
| 70 | + } |
| 71 | + }, |
| 72 | + { |
| 73 | + "type" = "portmap", |
| 74 | + "capabilities" = { |
| 75 | + "portMappings" = true |
| 76 | + } |
| 77 | + } |
| 78 | + ] |
| 79 | + })) |
| 80 | + |
| 81 | + params = ["FLANNEL_NETWORK", "FLANNEL_SUBNET"] |
| 82 | + |
| 83 | + domain_id = "domain-uuid" |
| 84 | + account = "admin" |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +## Argument Reference |
| 89 | + |
| 90 | +The following arguments are supported: |
| 91 | + |
| 92 | +### Required Arguments |
| 93 | + |
| 94 | +* `name` - (Required) The name of the CNI configuration. Must be unique within the account/domain. |
| 95 | +* `cni_config` - (Required) The CNI configuration in base64-encoded JSON format. This should contain the complete CNI plugin configuration according to the CNI specification. |
| 96 | + |
| 97 | +### Optional Arguments |
| 98 | + |
| 99 | +* `params` - (Optional) A list of parameter names that can be substituted in the CNI configuration. These parameters can be provided with actual values when creating a Kubernetes cluster using `cni_config_details`. |
| 100 | +* `domain_id` - (Optional) The domain ID for the CNI configuration. If not specified, uses the default domain. |
| 101 | +* `account` - (Optional) The account name for the CNI configuration. If not specified, uses the account of the authenticated user. |
| 102 | +* `project_id` - (Optional) The project ID to assign the CNI configuration to. |
| 103 | + |
| 104 | +## Attributes Reference |
| 105 | + |
| 106 | +In addition to all arguments above, the following attributes are exported: |
| 107 | + |
| 108 | +* `id` - The ID of the CNI configuration. |
| 109 | +* `created` - The timestamp when the CNI configuration was created. |
| 110 | +* `domain` - The domain name where the CNI configuration belongs. |
| 111 | +* `project` - The project name if the CNI configuration is assigned to a project. |
| 112 | + |
| 113 | +## CNI Configuration Format |
| 114 | + |
| 115 | +The `cni_config` should be a base64-encoded JSON string that follows the CNI specification. The configuration supports parameter substitution using placeholder names that can be defined in the `params` list. |
| 116 | + |
| 117 | +### Parameter Substitution |
| 118 | + |
| 119 | +Parameters in the CNI configuration can be specified as placeholders and will be replaced with actual values when the configuration is used in a Kubernetes cluster: |
| 120 | + |
| 121 | +```json |
| 122 | +{ |
| 123 | + "name": "k8s-pod-network", |
| 124 | + "cniVersion": "0.3.1", |
| 125 | + "plugins": [ |
| 126 | + { |
| 127 | + "type": "calico", |
| 128 | + "nodename": "KUBERNETES_NODE_NAME", |
| 129 | + "mtu": "CNI_MTU" |
| 130 | + } |
| 131 | + ] |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +The `KUBERNETES_NODE_NAME` and `CNI_MTU` placeholders will be replaced when creating a cluster using this configuration. |
| 136 | + |
| 137 | +### Supported CNI Plugins |
| 138 | + |
| 139 | +CloudStack supports various CNI plugins including: |
| 140 | + |
| 141 | +* **Calico** - Provides networking and network policy for Kubernetes |
| 142 | +* **Flannel** - Simple overlay network for Kubernetes |
| 143 | +* **Weave** - Container networking solution |
| 144 | +* **Custom plugins** - Any CNI-compliant plugin can be configured |
| 145 | + |
| 146 | +## Usage with Kubernetes Clusters |
| 147 | + |
| 148 | +CNI configurations are used with Kubernetes clusters by referencing the configuration ID: |
| 149 | + |
| 150 | +```hcl |
| 151 | +resource "cloudstack_kubernetes_cluster" "example" { |
| 152 | + name = "example-cluster" |
| 153 | + zone = "zone1" |
| 154 | + kubernetes_version = "1.25.0" |
| 155 | + service_offering = "Medium Instance" |
| 156 | + |
| 157 | + cni_configuration_id = cloudstack_cni_configuration.calico.id |
| 158 | + cni_config_details = { |
| 159 | + "CNI_MTU" = "1450" |
| 160 | + "KUBERNETES_NODE_NAME" = "spec.nodeName" |
| 161 | + "KUBECONFIG_FILEPATH" = "/etc/cni/net.d/calico-kubeconfig" |
| 162 | + } |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +## Import |
| 167 | + |
| 168 | +CNI configurations can be imported using the configuration ID: |
| 169 | + |
| 170 | +```shell |
| 171 | +$ terraform import cloudstack_cni_configuration.example <CNI_CONFIGURATION_ID> |
| 172 | +``` |
0 commit comments