akamai / terraform-provider-akamai

Terraform Akamai provider
https://www.terraform.io/docs/providers/akamai/
Mozilla Public License 2.0
110 stars 99 forks source link

Inconsistent creation and removal of DNS records #26

Closed bogdan-grozoiu closed 4 years ago

bogdan-grozoiu commented 5 years ago

Terraform Version

Terraform v0.12.5 Akamai Provider v0.1.1

Affected Resource(s)

Terraform Configuration Files

terraform {
  required_version = ">= 0.12"
}

# Initialize the Akamai provider
provider "akamai" {
  version = "0.1.1"
  edgerc = "~/.edgerc"
  dns_section = "default"
}

########################
# 84 DNS records defined
########################

Expected Behavior

The Akamai Provider to create all the DNS records in the DNS Zone and also to completely remove them.

Actual Behavior

The Akamai Provider creates all the DNS records in the DNS Zone and also reports as successful their removal, without removing all of them.

Steps to Reproduce

  1. terraform init
    
    Initializing the backend...

Initializing provider plugins...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work.

If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.


2. `terraform plan`

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


Note: You didn't specify an "-out" parameter to save this plan, so Terraform can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run.

Note: _the zone already contains 4 DNS records, none of them part of the 84 records defined in the HCL code_

3. `terraform apply`
We should have 84 (new) + 4 (exisiting and different) = 88 DNS records
In reality we have about ~53 resources created.
Checking the zone version, the active version is not the last one.
I'm manually activating the last version.
Rerun `terraform apply`.
In the end I get 87 resources ( 4 (initial ones) + 83 (new) ) (sometimes 88) created (instead of 88 - don’t know which one is missing, but anyhow...)

4. `terraform plan` (just to double check)

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your configuration and real physical resources that exist. As a result, no actions need to be performed.


4. `terraform destroy`

Destroy complete! Resources: 84 destroyed.


Note: So we should have 88 (total) - 84 (removed) = 4 (expected)
In reality only 77 resources are removed and 11 are still in the zone.

P.S.: The version 0.1.2 of the provider is unusable.
dshafik commented 5 years ago

We believe that this is caused by race conditions with the API due to the volume of requests, so we are going to add some brief delays in here to help it out.

martinstibbe commented 4 years ago

Using a count resource in large record counts used to skip a mutex of one api call causing this to happen it appears to work in .12 release of Terraform tried with 150 records at a time

Can you please verify if this is still an issue (see example below)

Thanks

resource "akamai_dns_record" "a_record" { count = 150 zone = "${local.zone}" name = "www-${count.index}.akavadev1.net" recordtype = "A" active = true ttl = 300 target = ["10.0.0.${count.index}"] }

akamai_dns_record.a_record[48]: Creation complete after 8s [id=akavadev1.net-www-48.akavadev1.net-

Apply complete! Resources: 150 added, 0 changed, 0 destroyed. akamai_dns_record.a_record[7]: Destruction complete after 3s

Destroy complete! Resources: 150 destroyed.