couchbasecloud / terraform-provider-couchbase-capella

Terraform Couchbase Capella Provider: Deploy, update, and manage Couchbase Capella infrastructure as code through HashiCorp Terraform
Apache License 2.0
32 stars 4 forks source link

AV-78889 - VNET peering azure #216

Closed PaulomeeCb closed 1 month ago

PaulomeeCb commented 3 months ago

Jira

Description

Please include a summary of the fix/feature/change, including any relevant motivation and context.

Type of Change

Manual Testing Approach

How was this change tested and do you have evidence? (REQUIRED: Select at least 1)

Testing

Get Azure VNET Peering CLI Command API-

  1. Error received when trying to access the command without admin consent granted-
Planning failed. Terraform encountered an error while generating this plan.
╷
│ Error: Error Reading Azure network peer command
│ 
│   with data.couchbase-capella_azure_network_peer_command.azure_network_peer_command,
│   on get_network_peer_command.tf line 5, in data "couchbase-capella_azure_network_peer_command" "azure_network_peer_command":
│    5: data "couchbase-capella_azure_network_peer_command" "azure_network_peer_command" {
│ 
│ Could not read Azure network peer command: unexpected code: 422, expected: 200, body: {"code":4061,"hint":"Returned when trying to retrieve command when the admin consent has not been granted by the customer or the consent
│ granted by the customer has not been successfully verified.","httpStatusCode":422,"message":"Unable to retrieve role assignment command. Admin consent not granted or failed to verify admin consent granted to the AD app for vnet
│ peering.  Please try granting the admin consent and retry retrieving command again."}null
╵
Screen Shot 2024-08-21 at 12 10 52 PM

Terraform apply-

 terraform apply
╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - couchbasecloud/couchbase-capella in /Users/paulomee.de/go/bin
│ 
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
data.couchbase-capella_azure_network_peer_command.azure_network_peer_command: Reading...
data.couchbase-capella_azure_network_peer_command.azure_network_peer_command: Read complete after 0s

Changes to Outputs:
  + azure_network_peer_command = {
      + cluster_id                     = "ffffffff-aaaa-1414-eeee-000000000000"
      + command                        = "az role assignment create --assignee-object-id ffffffff-aaaa-1414-eeee-000000000000 --role \"Network Contributor\" --scope /subscriptions/ffffffff-aaaa-1414-eeee-000000000000/resourceGroups/peerer_test/providers/Microsoft.Network/VirtualNetworks/vnet-test --assignee-principal-type ServicePrincipal"
      + organization_id                = "ffffffff-aaaa-1414-eeee-000000000000"
      + project_id                     = "ffffffff-aaaa-1414-eeee-000000000000"
      + resource_group                 = "peerer_test"
      + subscription_id                = "ffffffff-aaaa-1414-eeee-000000000000"
      + tenant_id                      = "ffffffff-aaaa-1414-eeee-000000000000"
      + vnet_id                        = "vnet-test"
      + vnet_peering_service_principal = "ffffffff-aaaa-1414-eeee-000000000000"
    }

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

azure_network_peer_command = {
  "cluster_id" = "ffffffff-aaaa-1414-eeee-000000000000"
  "command" = "az role assignment create --assignee-object-id ffffffff-aaaa-1414-eeee-000000000000 --role \"Network Contributor\" --scope /subscriptions/ffffffff-aaaa-1414-eeee-000000000000/resourceGroups/peerer_test/providers/Microsoft.Network/VirtualNetworks/vnet-test --assignee-principal-type ServicePrincipal"
  "organization_id" = "ffffffff-aaaa-1414-eeee-000000000000"
  "project_id" = "ffffffff-aaaa-1414-eeee-000000000000"
  "resource_group" = "peerer_test"
  "subscription_id" = "ffffffff-aaaa-1414-eeee-000000000000"
  "tenant_id" = "ffffffff-aaaa-1414-eeee-000000000000"
  "vnet_id" = "vnet-test"
  "vnet_peering_service_principal" = "ffffffff-aaaa-1414-eeee-000000000000"
}
Screen Shot 2024-08-22 at 5 01 28 PM Screen Shot 2024-08-22 at 5 01 14 PM

Create Network Peering API-

terraform plan

terraform plan
╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - couchbasecloud/couchbase-capella in /Users/paulomee.de/go/bin
│ 
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
data.couchbase-capella_network_peers.existing_network_peers: Reading...
data.couchbase-capella_network_peers.existing_network_peers: Read complete after 0s

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # couchbase-capella_network_peer.new_network_peer will be created
  + resource "couchbase-capella_network_peer" "new_network_peer" {
      + audit           = (known after apply)
      + cluster_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + commands        = (known after apply)
      + id              = (known after apply)
      + name            = "VNETPeerTFTestAZURE"
      + organization_id = "ffffffff-aaaa-1414-eeee-00000000000"
      + project_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + provider_config = {
          + azure_config = {
              + cidr            = "10.6.0.0/16"
              + provider_id     = (known after apply)
              + resource_group  = "test-rg"
              + subscription_id = "ffffffff-aaaa-1414-eeee-00000000000"
              + tenant_id       = "ffffffff-aaaa-1414-eeee-00000000000"
              + vnet_id         = "test-vnet"
            }
        }
      + provider_type   = "azure"
      + status          = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + network_peers_list = {
      + cluster_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + data            = [
          + {
              + audit           = {
                  + created_at  = "2024-08-23 23:30:39.790107885 +0000 UTC"
                  + created_by  = "s10qrydhDaic9GsWZ6BYpJfSK7wARDCv"
                  + modified_at = "2024-08-23 23:35:39.359925093 +0000 UTC"
                  + modified_by = "ffffffff-aaaa-1414-eeee-00000000000"
                  + version     = 6
                }
              + id              = "ffffffff-aaaa-1414-eeee-00000000000"
              + name            = "VNETPeerTFTestAZURE"
              + provider_config = {
                  + aws_config   = null
                  + azure_config = {
                      + cidr            = "10.6.0.0/16"
                      + provider_id     = ""
                      + resource_group  = "\"test-rg\""
                      + subscription_id = "\"ffffffff-aaaa-1414-eeee-00000000000\""
                      + tenant_id       = "\"ffffffff-aaaa-1414-eeee-00000000000\""
                      + vnet_id         = "\"test-vnet\""
                    }
                  + gcp_config   = null
                }
              + status          = {
                  + reasoning = ""
                  + state     = "failed"
                }
            },
        ]
      + organization_id = "ffffffff-aaaa-1414-eeee-00000000000"
      + project_id      = "ffffffff-aaaa-1414-eeee-00000000000"
    }
  + new_network_peer   = {
      + audit           = (known after apply)
      + cluster_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + commands        = (known after apply)
      + id              = (known after apply)
      + name            = "VNETPeerTFTestAZURE"
      + organization_id = "ffffffff-aaaa-1414-eeee-00000000000"
      + project_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + provider_config = {
          + aws_config   = null
          + azure_config = {
              + cidr            = "10.6.0.0/16"
              + provider_id     = (known after apply)
              + resource_group  = "test-rg"
              + subscription_id = "ffffffff-aaaa-1414-eeee-00000000000"
              + tenant_id       = "ffffffff-aaaa-1414-eeee-00000000000"
              + vnet_id         = "test-vnet"
            }
          + gcp_config   = null
        }
      + provider_type   = "azure"
      + status          = (known after apply)
    }
  + peer_id            = (known after apply)

terraform apply

terraform apply
╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - couchbasecloud/couchbase-capella in /Users/paulomee.de/go/bin
│ 
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
data.couchbase-capella_network_peers.existing_network_peers: Reading...
data.couchbase-capella_network_peers.existing_network_peers: Read complete after 0s

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # couchbase-capella_network_peer.new_network_peer will be created
  + resource "couchbase-capella_network_peer" "new_network_peer" {
      + audit           = (known after apply)
      + cluster_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + commands        = (known after apply)
      + id              = (known after apply)
      + name            = "VNETPeerTFTestAZURE"
      + organization_id = "ffffffff-aaaa-1414-eeee-00000000000"
      + project_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + provider_config = {
          + azure_config = {
              + cidr            = "10.6.0.0/16"
              + provider_id     = (known after apply)
              + resource_group  = "test-rg"
              + subscription_id = "ffffffff-aaaa-1414-eeee-00000000000"
              + tenant_id       = "ffffffff-aaaa-1414-eeee-00000000000"
              + vnet_id         = "test-vnet"
            }
        }
      + provider_type   = "azure"
      + status          = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + network_peers_list = {
      + cluster_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + data            = [
          + {
              + audit           = {
                  + created_at  = "2024-08-23 23:30:39.790107885 +0000 UTC"
                  + created_by  = "s10qrydhDaic9GsWZ6BYpJfSK7wARDCv"
                  + modified_at = "2024-08-23 23:35:39.359925093 +0000 UTC"
                  + modified_by = "ffffffff-aaaa-1414-eeee-00000000000"
                  + version     = 6
                }
              + id              = "ffffffff-aaaa-1414-eeee-00000000000"
              + name            = "VNETPeerTFTestAZURE"
              + provider_config = {
                  + aws_config   = null
                  + azure_config = {
                      + cidr            = "10.6.0.0/16"
                      + provider_id     = ""
                      + resource_group  = "\"test-rg\""
                      + subscription_id = "\"ffffffff-aaaa-1414-eeee-00000000000\""
                      + tenant_id       = "\"ffffffff-aaaa-1414-eeee-00000000000\""
                      + vnet_id         = "\"test-vnet\""
                    }
                  + gcp_config   = null
                }
              + status          = {
                  + reasoning = ""
                  + state     = "failed"
                }
            },
        ]
      + organization_id = "ffffffff-aaaa-1414-eeee-00000000000"
      + project_id      = "ffffffff-aaaa-1414-eeee-00000000000"
    }
  + new_network_peer   = {
      + audit           = (known after apply)
      + cluster_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + commands        = (known after apply)
      + id              = (known after apply)
      + name            = "VNETPeerTFTestAZURE"
      + organization_id = "ffffffff-aaaa-1414-eeee-00000000000"
      + project_id      = "ffffffff-aaaa-1414-eeee-00000000000"
      + provider_config = {
          + aws_config   = null
          + azure_config = {
              + cidr            = "10.6.0.0/16"
              + provider_id     = (known after apply)
              + resource_group  = "test-rg"
              + subscription_id = "ffffffff-aaaa-1414-eeee-00000000000"
              + tenant_id       = "ffffffff-aaaa-1414-eeee-00000000000"
              + vnet_id         = "test-vnet"
            }
          + gcp_config   = null
        }
      + provider_type   = "azure"
      + status          = (known after apply)
    }
  + peer_id            = (known after apply)

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

couchbase-capella_network_peer.new_network_peer: Creating...
couchbase-capella_network_peer.new_network_peer: Still creating... [10s elapsed]
couchbase-capella_network_peer.new_network_peer: Still creating... [20s elapsed]
couchbase-capella_network_peer.new_network_peer: Still creating... [30s elapsed]
couchbase-capella_network_peer.new_network_peer: Still creating... [40s elapsed]
couchbase-capella_network_peer.new_network_peer: Creation complete after 43s [id=ffffffff-aaaa-1414-eeee-00000000000]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

network_peers_list = {
  "cluster_id" = "ffffffff-aaaa-1414-eeee-00000000000"
  "data" = tolist([
    {
      "audit" = {
        "created_at" = "2024-08-23 23:30:39.790107885 +0000 UTC"
        "created_by" = "s10qrydhDaic9GsWZ6BYpJfSK7wARDCv"
        "modified_at" = "2024-08-23 23:35:39.359925093 +0000 UTC"
        "modified_by" = "ffffffff-aaaa-1414-eeee-00000000000"
        "version" = 6
      }
      "id" = "ffffffff-aaaa-1414-eeee-00000000000"
      "name" = "VNETPeerTFTestAZURE"
      "provider_config" = {
        "aws_config" = null /* object */
        "azure_config" = {
          "cidr" = "10.6.0.0/16"
          "provider_id" = ""
          "resource_group" = "\"test-rg\""
          "subscription_id" = "\"ffffffff-aaaa-1414-eeee-00000000000\""
          "tenant_id" = "\"ffffffff-aaaa-1414-eeee-00000000000\""
          "vnet_id" = "\"test-vnet\""
        }
        "gcp_config" = null /* object */
      }
      "status" = {
        "reasoning" = ""
        "state" = "failed"
      }
    },
  ])
  "organization_id" = "ffffffff-aaaa-1414-eeee-00000000000"
  "project_id" = "ffffffff-aaaa-1414-eeee-00000000000"
}
new_network_peer = {
  "audit" = {
    "created_at" = "2024-08-24 00:01:23.524305127 +0000 UTC"
    "created_by" = "s10qrydhDaic9GsWZ6BYpJfSK7wARDCv"
    "modified_at" = "2024-08-24 00:02:05.606678591 +0000 UTC"
    "modified_by" = "s10qrydhDaic9GsWZ6BYpJfSK7wARDCv"
    "version" = 2
  }
  "cluster_id" = "ffffffff-aaaa-1414-eeee-00000000000"
  "commands" = toset([])
  "id" = "ffffffff-aaaa-1414-eeee-00000000000"
  "name" = "VNETPeerTFTestAZURE"
  "organization_id" = "ffffffff-aaaa-1414-eeee-00000000000"
  "project_id" = "ffffffff-aaaa-1414-eeee-00000000000"
  "provider_config" = {
    "aws_config" = null /* object */
    "azure_config" = {
      "cidr" = "10.6.0.0/16"
      "provider_id" = "/subscriptions/ffffffff-aaaa-1414-eeee-00000000000/resourceGroups/rg-ffffffff-aaaa-1414-eeee-00000000000/providers/Microsoft.Network/virtualNetworks/cc-ffffffff-aaaa-1414-eeee-00000000000/virtualNetworkPeerings/cc-ffffffff-aaaa-1414-eeee-00000000000-test-vnet"
      "resource_group" = "test-rg"
      "subscription_id" = "ffffffff-aaaa-1414-eeee-00000000000"
      "tenant_id" = "ffffffff-aaaa-1414-eeee-00000000000"
      "vnet_id" = "test-vnet"
    }
    "gcp_config" = null /* object */
  }
  "provider_type" = "azure"
  "status" = {
    "reasoning" = ""
    "state" = "complete"
  }
}
peer_id = "ffffffff-aaaa-1414-eeee-00000000000"

Network peering record -

Screen Shot 2024-08-23 at 4 47 15 PM

Remaining all operations are in the README files.

NOTE: Getting_started folder already has an example for VPC Peering hence not updating that again.

Testing

Required Checklist: