|
| 1 | +.. _mcli-atlas-networking-peering-create-azure-cmd: |
| 2 | + |
| 3 | +============================================== |
| 4 | +mongocli atlas networking peering azure create |
| 5 | +============================================== |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +.. include:: /includes/styles/corrections.rst |
| 16 | + |
| 17 | +The ``networking peering create azure`` command creates a peering |
| 18 | +connection between the |service| VNet and your Azure VNet |
| 19 | +for a given |service| project. |
| 20 | + |
| 21 | +The ``networking peering create azure`` command checks if a VNet exists |
| 22 | +in the region you specify for your |service| project. If one exists, |
| 23 | +this command creates the peering connection between that VNet and your |
| 24 | +VNet. If an |service| VNet does not exist, this command creates one and |
| 25 | +creates a connection between it and your VNet. |
| 26 | + |
| 27 | +Prerequisites |
| 28 | +------------- |
| 29 | + |
| 30 | +.. note:: |
| 31 | + |
| 32 | + For details about how |service| creates |
| 33 | + :wikipedia:`Network Peering </Virtual_private_cloud>` |
| 34 | + connections with Azure VNets, see the ``Azure`` tab in |
| 35 | + :atlas:`Set up a Network Peering Connection |
| 36 | + </security-vpc-peering/>` in the |service| documentation. |
| 37 | + |
| 38 | +You must complete the following steps before you create each Azure |
| 39 | +network peering connection: |
| 40 | + |
| 41 | +1. Run the following Azure CLI command to create a service principal |
| 42 | + using the specified |service| peering application ID: |
| 43 | + |
| 44 | + .. code-block:: sh |
| 45 | + |
| 46 | + az ad sp create --id e90a1407-55c3-432d-9cb1-3638900a9d22 |
| 47 | + |
| 48 | + You only have to do this once for each subscription. If you receive |
| 49 | + the following message, the service principal with the |service| |
| 50 | + peering application ID already exists. Proceed to the next step. |
| 51 | + |
| 52 | + .. code-block:: sh |
| 53 | + :copyable: false |
| 54 | + |
| 55 | + Another object with the same value for property servicePrincipalNames already exists. |
| 56 | + |
| 57 | +#. Copy the following example ``peering-role.json`` file and save it |
| 58 | + to your current working directory: |
| 59 | + |
| 60 | + .. code-block:: json |
| 61 | + :linenos: |
| 62 | + |
| 63 | + { |
| 64 | + "Name":"AtlasPeering/<azureSubscriptionId>/<resourceGroupName>/<vnetName>", |
| 65 | + "IsCustom":true, |
| 66 | + "Description":"Grants MongoDB access to manage peering connections on network /subscriptions/<azureSubscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Network/virtualNetworks/<vnetName>", |
| 67 | + "Actions":[ |
| 68 | + "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/read", |
| 69 | + "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/write", |
| 70 | + "Microsoft.Network/virtualNetworks/virtualNetworkPeerings/delete", |
| 71 | + "Microsoft.Network/virtualNetworks/peer/action" |
| 72 | + ], |
| 73 | + "AssignableScopes":[ |
| 74 | + "/subscriptions/<azureSubscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Network/virtualNetworks/<vnetName>" |
| 75 | + ] |
| 76 | + } |
| 77 | + |
| 78 | +#. Replace the variables in the ``peering-role.json`` with details |
| 79 | + about the Azure VNet to which you want to create a peering |
| 80 | + connection: |
| 81 | + |
| 82 | + .. list-table:: |
| 83 | + :header-rows: 1 |
| 84 | + :widths: 30 70 |
| 85 | + |
| 86 | + * - Variable |
| 87 | + - Description |
| 88 | + |
| 89 | + * - ``azureSubscriptionId`` |
| 90 | + - Unique identifer of the Azure subscription in which the |
| 91 | + VNet resides. |
| 92 | + |
| 93 | + * - ``resourceGroupName`` |
| 94 | + - Name of your Azure resource group. |
| 95 | + |
| 96 | + * - ``vnetName`` |
| 97 | + - Name of your Azure VNet. |
| 98 | + |
| 99 | +#. Run the following Azure CLI command to create the role definition |
| 100 | + using the ``peering-role.json`` file: |
| 101 | + |
| 102 | + .. code-block:: sh |
| 103 | + |
| 104 | + az role definition create --role-definition peering-role.json |
| 105 | + |
| 106 | +#. Run the Azure CLI command shown below to assign the role you created |
| 107 | + to the service principal. |
| 108 | + |
| 109 | + Replace the variables with the same values you used in the |
| 110 | + ``peering-role.json`` file. |
| 111 | + |
| 112 | + .. code-block:: sh |
| 113 | + |
| 114 | + az role assignment create \ |
| 115 | + --role "AtlasPeering/<azureSubscriptionId>/<resourceGroupName>/<vnetName>" \ |
| 116 | + --assignee "e90a1407-55c3-432d-9cb1-3638900a9d22" \ |
| 117 | + --scope "/subscriptions/<azureSubscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Network/virtualNetworks/<vnetName>" |
| 118 | + |
| 119 | +Syntax |
| 120 | +------ |
| 121 | + |
| 122 | +.. code-block:: text |
| 123 | + |
| 124 | + mongocli atlas networking peering azure create |
| 125 | + [ --atlasCidrBlock <atlas-cidr-block> ] |
| 126 | + --directoryId <azure-ad-tenant-id> |
| 127 | + [ --output|-o <output-format> ] |
| 128 | + [ --profile|-P <profile-name> ] |
| 129 | + [ --projectId <project-ID> ] |
| 130 | + --region <azure-region-id> |
| 131 | + --resourceGroup <azure-resource-group-name> |
| 132 | + --subscriptionId <azure-subscription-id> |
| 133 | + --vnet <azure-vnet-name> |
| 134 | + |
| 135 | +.. include:: /includes/fact-command-line-help.rst |
| 136 | + |
| 137 | +.. _atlas-networking-peering-create-azure-options: |
| 138 | + |
| 139 | +Options |
| 140 | +------- |
| 141 | + |
| 142 | +.. list-table:: |
| 143 | + :widths: 20 10 60 10 |
| 144 | + :header-rows: 1 |
| 145 | + |
| 146 | + * - Option |
| 147 | + - Type |
| 148 | + - Description |
| 149 | + - Required? |
| 150 | + |
| 151 | + * - ``--atlasCidrBlock`` |
| 152 | + - string |
| 153 | + - CIDR block that |service| uses for your clusters. Required only |
| 154 | + if you do not already have an |service| VNet. |
| 155 | + |
| 156 | + .. include:: /includes/fact-peering-azure-atlas-cidr-block.rst |
| 157 | + - no |
| 158 | + |
| 159 | + * - ``--directoryId`` |
| 160 | + - string |
| 161 | + - Unique identifier for your Azure Active Directory tenant. |
| 162 | + - yes |
| 163 | + |
| 164 | + * - ``--output``, ``-o`` |
| 165 | + - string |
| 166 | + - .. include:: /includes/extracts/fact-basic-options-output.rst |
| 167 | + - no |
| 168 | + |
| 169 | + * - ``--profile``, ``-P`` |
| 170 | + - string |
| 171 | + - Name of the profile where the public and private |
| 172 | + keys for the project are saved. If omitted, uses the |
| 173 | + {+default-profile+}. To learn more about creating a |
| 174 | + profile, see :ref:`mcli-configure`. |
| 175 | + - no |
| 176 | + |
| 177 | + * - ``--projectId`` |
| 178 | + - string |
| 179 | + - Unique identifier of the project for which you want to add |
| 180 | + the peering connection. If omitted, uses the |
| 181 | + project ID in the profile or :ref:`environment variable |
| 182 | + <mcli-env-var>`. |
| 183 | + - no |
| 184 | + |
| 185 | + * - ``--region`` |
| 186 | + - string |
| 187 | + - Azure region in which the peer VPC resides. See the |
| 188 | + :atlas:`Atlas documentation </reference/microsoft-azure/>` for a list |
| 189 | + of supported regions. |
| 190 | + - no |
| 191 | + |
| 192 | + * - ``--resourceGroup`` |
| 193 | + - string |
| 194 | + - Name of the Azure resource group that contains the VNet that you |
| 195 | + want to peer. |
| 196 | + - yes |
| 197 | + |
| 198 | + * - ``--subscriptionId`` |
| 199 | + - string |
| 200 | + - Unique identifier of the Azure subscription that contains the |
| 201 | + VNet that you want to peer. |
| 202 | + - yes |
| 203 | + |
| 204 | + * - ``--vnet`` |
| 205 | + - string |
| 206 | + - Name of the VNet that you want to peer. |
| 207 | + - yes |
| 208 | + |
| 209 | +.. _atlas-networking-peering-create-azure-output: |
| 210 | + |
| 211 | +Output |
| 212 | +------ |
| 213 | + |
| 214 | +If the command succeeds, it returns the following output in the default |
| 215 | +format. If the command returns errors, see |
| 216 | +:ref:`Troubleshooting <troubleshooting>` for recommended solutions. |
| 217 | + |
| 218 | +.. code-block:: sh |
| 219 | + :copyable: false |
| 220 | + |
| 221 | + Network peering connection '<peering-connection-id>' created. |
| 222 | + |
| 223 | +.. include:: /includes/fact-default-output.rst |
| 224 | + |
| 225 | +- :atlas:`Atlas API </reference/api/vpc-create-peering-connection/#request-body-parameters>` |
| 226 | + |
| 227 | +Example |
| 228 | +------- |
| 229 | + |
| 230 | +.. tabs:: |
| 231 | + |
| 232 | + .. tab:: Default Output |
| 233 | + :tabid: default-output |
| 234 | + |
| 235 | + The following command creates a peering connection between the |
| 236 | + |service| VNet and your Azure VNet for a project using the |
| 237 | + {+default-profile+}, which contains credentials and the project |
| 238 | + ID. The output is returned in the default format. |
| 239 | + |
| 240 | + .. code-block:: sh |
| 241 | + |
| 242 | + mongocli atlas networking peering create azure --atlasCidrBlock 192.168.0.0/21 \ |
| 243 | + --directoryId 56657fdb-ca45-40dc-fr56-77fd8b6d2b37 \ |
| 244 | + --subscriptionId 345654f3-77cf-4084-9e06-8943a079ed75 \ |
| 245 | + --resourceGroup mongocli-test --region US_EAST_2 --vnet mongocli-test |
| 246 | + |
| 247 | + The previous command prints the following to the terminal. |
| 248 | + |
| 249 | + .. code-block:: sh |
| 250 | + :copyable: false |
| 251 | + |
| 252 | + Network peering connection '5f621a5669a49208c2160f40' created. |
| 253 | + |
| 254 | + .. tab:: JSON Output |
| 255 | + :tabid: json-output |
| 256 | + |
| 257 | + The following command creates a peering connection between the |
| 258 | + |service| VNet and your Azure VNet for a project using the |
| 259 | + {+default-profile+}, which contains credentials and the project |
| 260 | + ID. The output is returned in |json| format. |
| 261 | + |
| 262 | + .. code-block:: sh |
| 263 | + |
| 264 | + mongocli atlas networking peering create azure --atlasCidrBlock 192.168.0.0/21 \ |
| 265 | + --directoryId 56657fdb-ca45-40dc-fr56-77fd8b6d2b37 \ |
| 266 | + --subscriptionId 345654f3-77cf-4084-9e06-8943a079ed75 \ |
| 267 | + --resourceGroup mongocli-test --region US_EAST_2 --vnet mongocli-test \ |
| 268 | + --output json |
| 269 | + |
| 270 | + The previous command prints the following to the terminal in |
| 271 | + |json| format. |
| 272 | + |
| 273 | + .. code-block:: json |
| 274 | + :copyable: false |
| 275 | + |
| 276 | + { |
| 277 | + "containerId": "5f3a84b1242d9c2dc7cf244a", |
| 278 | + "id": "5f621a5669a49208c2160f40", |
| 279 | + "azureDirectoryId": "56657fdb-ca45-40dc-fr56-77fd8b6d2b37", |
| 280 | + "azureSubscriptionId": "345654f3-77cf-4084-9e06-8943a079ed75", |
| 281 | + "resourceGroupName": "mongocli-test", |
| 282 | + "vnetName": "mongocli-test", |
| 283 | + "status": "ADDING_PEER" |
| 284 | + } |
0 commit comments