Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random errors when applying Private DNS resources #1674

Closed
l2fprod opened this issue Jul 13, 2020 · 5 comments
Closed

Random errors when applying Private DNS resources #1674

l2fprod opened this issue Jul 13, 2020 · 5 comments
Assignees

Comments

@l2fprod
Copy link
Member

l2fprod commented Jul 13, 2020

using

Terraform v0.12.28
+ provider.ibm v1.8.1

I have one Private DNS instance, one zone and 4 VPCs.

resource "ibm_resource_instance" "pdns" {
  name              = "${var.basename}-dns"
  resource_group_id = data.terraform_remote_state.account_structure.outputs.resource_group.id
  location          = "global"
  service           = "dns-svcs"
  plan              = "standard-dns"
  tags              = var.tags
}

resource "ibm_dns_zone" "pdns_zone" {
  name        = "native.cloud"
  instance_id = ibm_resource_instance.pdns.guid
  description = "For all VSIs in the solution"
  label       = "localdomain"
}

locals {
  vpcs = [
    {
      vpc : data.terraform_remote_state.vpc_structure.outputs.vpc_a.vpc,
      workload : data.terraform_remote_state.vpc_workload.outputs.vpc_a_workload
    },
    {
      vpc : data.terraform_remote_state.vpc_structure.outputs.vpc_b.vpc,
      workload : data.terraform_remote_state.vpc_workload.outputs.vpc_b_workload
    },
    {
      vpc : data.terraform_remote_state.vpc_structure.outputs.vpc_c.vpc,
      workload : data.terraform_remote_state.vpc_workload.outputs.vpc_c_workload
    },
    {
      vpc : data.terraform_remote_state.vpc_structure.outputs.vpc_d.vpc,
      workload : data.terraform_remote_state.vpc_workload.outputs.vpc_d_workload
    }
  ]
}

locals {
  all_vsis = flatten([
    for vpc in local.vpcs : vpc.workload.vpc_instances
  ])
}

resource "ibm_dns_permitted_network" "vpc" {
  for_each    = { for vpc in local.vpcs : vpc.vpc.id => vpc }
  instance_id = ibm_resource_instance.pdns.guid
  zone_id     = ibm_dns_zone.pdns_zone.zone_id
  vpc_crn     = each.value.vpc.crn
  type        = "vpc"
}

On first apply, the service is created, the zone too but it fails to create the 4 permitted networks:

Terraform will perform the following actions:

  # ibm_dns_permitted_network.vpc["r006-0f5c3afb-67f5-4fbf-aee6-fcb48f765247"] will be created
  + resource "ibm_dns_permitted_network" "vpc" {
      + created_on           = (known after apply)
      + id                   = (known after apply)
      + instance_id          = (known after apply)
      + modified_on          = (known after apply)
      + permitted_network_id = (known after apply)
      + state                = (known after apply)
      + type                 = "vpc"
      + vpc_crn              = "crn:v1:bluemix:public:is:us-south:a/123::vpc:r006-0f5c3afb-67f5-4fbf-aee6-fcb48f765247"
      + zone_id              = (known after apply)
    }

  # ibm_dns_permitted_network.vpc["r006-4cefc369-aea1-4489-9e9e-37c0a313ea8a"] will be created
  + resource "ibm_dns_permitted_network" "vpc" {
      + created_on           = (known after apply)
      + id                   = (known after apply)
      + instance_id          = (known after apply)
      + modified_on          = (known after apply)
      + permitted_network_id = (known after apply)
      + state                = (known after apply)
      + type                 = "vpc"
      + vpc_crn              = "crn:v1:bluemix:public:is:us-south:a/123::vpc:r006-4cefc369-aea1-4489-9e9e-37c0a313ea8a"
      + zone_id              = (known after apply)
    }

  # ibm_dns_permitted_network.vpc["r006-9e3402dc-2e82-482b-969a-fd0c1bd533f0"] will be created
  + resource "ibm_dns_permitted_network" "vpc" {
      + created_on           = (known after apply)
      + id                   = (known after apply)
      + instance_id          = (known after apply)
      + modified_on          = (known after apply)
      + permitted_network_id = (known after apply)
      + state                = (known after apply)
      + type                 = "vpc"
      + vpc_crn              = "crn:v1:bluemix:public:is:us-south:a/123::vpc:r006-9e3402dc-2e82-482b-969a-fd0c1bd533f0"
      + zone_id              = (known after apply)
    }

  # ibm_dns_permitted_network.vpc["r006-f6bed8d7-ba7d-46e1-8419-cfff7fce2547"] will be created
  + resource "ibm_dns_permitted_network" "vpc" {
      + created_on           = (known after apply)
      + id                   = (known after apply)
      + instance_id          = (known after apply)
      + modified_on          = (known after apply)
      + permitted_network_id = (known after apply)
      + state                = (known after apply)
      + type                 = "vpc"
      + vpc_crn              = "crn:v1:bluemix:public:is:us-south:a/123::vpc:r006-f6bed8d7-ba7d-46e1-8419-cfff7fce2547"
      + zone_id              = (known after apply)
    }

  # ibm_dns_zone.pdns_zone will be created
  + resource "ibm_dns_zone" "pdns_zone" {
      + created_on  = (known after apply)
      + description = "For all VSIs in the solution"
      + id          = (known after apply)
      + instance_id = (known after apply)
      + label       = "localdomain"
      + modified_on = (known after apply)
      + name        = "native.cloud"
      + state       = (known after apply)
      + zone_id     = (known after apply)
    }

  # ibm_resource_instance.pdns will be created
  + resource "ibm_resource_instance" "pdns" {
      + crn                     = (known after apply)
      + guid                    = (known after apply)
      + id                      = (known after apply)
      + location                = "global"
      + name                    = "fredl-dns"
      + plan                    = "standard-dns"
      + resource_controller_url = (known after apply)
      + resource_crn            = (known after apply)
      + resource_group_id       = "80fbd81922474c52af7dfa52a952ef1c"
      + resource_group_name     = (known after apply)
      + resource_name           = (known after apply)
      + resource_status         = (known after apply)
      + service                 = "dns-svcs"
      + status                  = (known after apply)
      + tags                    = [
          + "cloud-native",
          + "terraform",
        ]
    }

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

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


ibm_resource_instance.pdns: Creating...
ibm_resource_instance.pdns: Still creating... [10s elapsed]
ibm_resource_instance.pdns: Creation complete after 19s [id=crn:v1:bluemix:public:dns-svcs:global:a/123:452f40f7-8bea-4f8f-9e80-ca2a16b441f2::]
ibm_dns_zone.pdns_zone: Creating...
ibm_dns_zone.pdns_zone: Creation complete after 0s [id=452f40f7-8bea-4f8f-9e80-ca2a16b441f2/native.cloud:cc360ef5-05eb-4460-971e-ed35772259aa]
ibm_dns_permitted_network.vpc["r006-0f5c3afb-67f5-4fbf-aee6-fcb48f765247"]: Creating...
ibm_dns_permitted_network.vpc["r006-f6bed8d7-ba7d-46e1-8419-cfff7fce2547"]: Creating...
ibm_dns_permitted_network.vpc["r006-9e3402dc-2e82-482b-969a-fd0c1bd533f0"]: Creating...
ibm_dns_permitted_network.vpc["r006-4cefc369-aea1-4489-9e9e-37c0a313ea8a"]: Creating...
ibm_dns_permitted_network.vpc["r006-f6bed8d7-ba7d-46e1-8419-cfff7fce2547"]: Creation complete after 1s [id=452f40f7-8bea-4f8f-9e80-ca2a16b441f2/native.cloud:cc360ef5-05eb-4460-971e-ed35772259aa/r006-f6bed8d7-ba7d-46e1-8419-cfff7fce2547]

Error: There was an internal error occurred, please try again later.

  on main.tf line 44, in resource "ibm_dns_permitted_network" "vpc":
  44: resource "ibm_dns_permitted_network" "vpc" {



Error: There was an internal error occurred, please try again later.

  on main.tf line 44, in resource "ibm_dns_permitted_network" "vpc":
  44: resource "ibm_dns_permitted_network" "vpc" {



Error: The permittedNetwork doesn't exist.

  on main.tf line 44, in resource "ibm_dns_permitted_network" "vpc":
  44: resource "ibm_dns_permitted_network" "vpc" {

In the UI, the service is created and two of the VPCs added:

image

If I apply again, it tries to change to create some of the existing entries:

data.terraform_remote_state.vpc_workload: Refreshing state...
data.terraform_remote_state.account_structure: Refreshing state...
data.terraform_remote_state.vpc_structure: Refreshing state...
ibm_resource_instance.pdns: Refreshing state... [id=crn:v1:bluemix:public:dns-svcs:global:a/bfbfea4eadfc486e88755e6b5c1e51bf:452f40f7-8bea-4f8f-9e80-ca2a16b441f2::]
ibm_dns_zone.pdns_zone: Refreshing state... [id=452f40f7-8bea-4f8f-9e80-ca2a16b441f2/native.cloud:cc360ef5-05eb-4460-971e-ed35772259aa]
ibm_dns_permitted_network.vpc["r006-4cefc369-aea1-4489-9e9e-37c0a313ea8a"]: Refreshing state... [id=452f40f7-8bea-4f8f-9e80-ca2a16b441f2/native.cloud:cc360ef5-05eb-4460-971e-ed35772259aa/r006-4cefc369-aea1-4489-9e9e-37c0a313ea8a]
ibm_dns_permitted_network.vpc["r006-f6bed8d7-ba7d-46e1-8419-cfff7fce2547"]: Refreshing state... [id=452f40f7-8bea-4f8f-9e80-ca2a16b441f2/native.cloud:cc360ef5-05eb-4460-971e-ed35772259aa/r006-f6bed8d7-ba7d-46e1-8419-cfff7fce2547]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # ibm_dns_permitted_network.vpc["r006-0f5c3afb-67f5-4fbf-aee6-fcb48f765247"] will be created
  + resource "ibm_dns_permitted_network" "vpc" {
      + created_on           = (known after apply)
      + id                   = (known after apply)
      + instance_id          = "452f40f7-8bea-4f8f-9e80-ca2a16b441f2"
      + modified_on          = (known after apply)
      + permitted_network_id = (known after apply)
      + state                = (known after apply)
      + type                 = "vpc"
      + vpc_crn              = "crn:v1:bluemix:public:is:us-south:a/bfbfea4eadfc486e88755e6b5c1e51bf::vpc:r006-0f5c3afb-67f5-4fbf-aee6-fcb48f765247"
      + zone_id              = "native.cloud:cc360ef5-05eb-4460-971e-ed35772259aa"
    }

  # ibm_dns_permitted_network.vpc["r006-4cefc369-aea1-4489-9e9e-37c0a313ea8a"] will be created
  + resource "ibm_dns_permitted_network" "vpc" {
      + created_on           = (known after apply)
      + id                   = (known after apply)
      + instance_id          = "452f40f7-8bea-4f8f-9e80-ca2a16b441f2"
      + modified_on          = (known after apply)
      + permitted_network_id = (known after apply)
      + state                = (known after apply)
      + type                 = "vpc"
      + vpc_crn              = "crn:v1:bluemix:public:is:us-south:a/bfbfea4eadfc486e88755e6b5c1e51bf::vpc:r006-4cefc369-aea1-4489-9e9e-37c0a313ea8a"
      + zone_id              = "native.cloud:cc360ef5-05eb-4460-971e-ed35772259aa"
    }

  # ibm_dns_permitted_network.vpc["r006-9e3402dc-2e82-482b-969a-fd0c1bd533f0"] will be created
  + resource "ibm_dns_permitted_network" "vpc" {
      + created_on           = (known after apply)
      + id                   = (known after apply)
      + instance_id          = "452f40f7-8bea-4f8f-9e80-ca2a16b441f2"
      + modified_on          = (known after apply)
      + permitted_network_id = (known after apply)
      + state                = (known after apply)
      + type                 = "vpc"
      + vpc_crn              = "crn:v1:bluemix:public:is:us-south:a/bfbfea4eadfc486e88755e6b5c1e51bf::vpc:r006-9e3402dc-2e82-482b-969a-fd0c1bd533f0"
      + zone_id              = "native.cloud:cc360ef5-05eb-4460-971e-ed35772259aa"
    }

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

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

  Enter a value:

and fails with


ibm_dns_permitted_network.vpc["r006-4cefc369-aea1-4489-9e9e-37c0a313ea8a"]: Creating...
ibm_dns_permitted_network.vpc["r006-0f5c3afb-67f5-4fbf-aee6-fcb48f765247"]: Creating...
ibm_dns_permitted_network.vpc["r006-9e3402dc-2e82-482b-969a-fd0c1bd533f0"]: Creating...
ibm_dns_permitted_network.vpc["r006-0f5c3afb-67f5-4fbf-aee6-fcb48f765247"]: Creation complete after 1s [id=452f40f7-8bea-4f8f-9e80-ca2a16b441f2/native.cloud:cc360ef5-05eb-4460-971e-ed35772259aa/r006-0f5c3afb-67f5-4fbf-aee6-fcb48f765247]

Error: The VPC was already associated to the same DNS zone name.

  on main.tf line 44, in resource "ibm_dns_permitted_network" "vpc":
  44: resource "ibm_dns_permitted_network" "vpc" {



Error: The VPC was already associated to the same DNS zone name.

  on main.tf line 44, in resource "ibm_dns_permitted_network" "vpc":
  44: resource "ibm_dns_permitted_network" "vpc" {

But in the UI, one of the entries was created:

image


I've tried the same config manually in the UI and it works so something is going wrong when used from Terraform

@MalarvizhiK
Copy link
Member

I am trying to recreate the issue.

@MalarvizhiK
Copy link
Member

I am able to recreate the issue. I added concurrency logic in code (with lock in instance_id and zone_id) and tested the permitted networks. It seems to be working fine. I will raise a PR.

@MalarvizhiK
Copy link
Member

@hkantare
Copy link
Collaborator

@hkantare
Copy link
Collaborator

closing the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants