hashicorp / terraform-provider-awscc

Terraform AWS Cloud Control provider
https://registry.terraform.io/providers/hashicorp/awscc/latest/docs
Mozilla Public License 2.0
239 stars 107 forks source link

awscc_batch_scheduling_policy: weightfactor returned by CloudControl API doesn't match configuration/console #1824

Open quixoticmonk opened 2 weeks ago

quixoticmonk commented 2 weeks ago

Community Note

Terraform CLI and Terraform AWS Cloud Control Provider Version

terraform -v
Terraform v1.8.4
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v5.53.0
+ provider registry.terraform.io/hashicorp/awscc v1.2.0

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.


resource "awscc_batch_scheduling_policy" "example" {
  name = "example"
  fairshare_policy = {
    compute_reservation = 1
    share_decay_seconds = 3600

    share_distribution = [
      {
        share_identifier = "A1*"
        weight_factor    = 0.1
      },
      {
        share_identifier = "A2"
        weight_factor    = 0.2
      }
    ]
  }

}

Debug Output

Panic Output

Expected Behavior

Subsequent apply of the resource configuration should have no infrastructure changes identified.

Actual Behavior

Terraform plan and apply shows a change based on the refresh.

Terraform used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # awscc_batch_scheduling_policy.example will be updated in-place
  ~ resource "awscc_batch_scheduling_policy" "example" {
      ~ fairshare_policy = {
          ~ share_distribution  = [
              ~ {
                  ~ weight_factor    = 0.10000000149011612 -> 0.1
                    # (1 unchanged attribute hidden)
                },
              ~ {
                  ~ weight_factor    = 0.20000000298023224 -> 0.2
                    # (1 unchanged attribute hidden)
                },
            ]
            # (2 unchanged attributes hidden)
        }
        id               = "arn:aws:batch:us-east-1:############:scheduling-policy/example"
        name             = "example"
        tags             = {}
        # (1 unchanged attribute hidden)
    }

Terraform state, console and the configuration matches the value of 0.1 while CC API returns 0.10000000149011612 leading to Terraform trying to reconcile.

Steps to Reproduce

  1. terraform apply
  2. terraform apply

Important Factoids

References

quixoticmonk commented 2 weeks ago

Looks like a precision issue on the float. Below would return 0.10000000149011612000

System.out.printf("%.20f", 0.1f);

I have opened an internal service ticket on this.