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

Panic when reading already created AWS elastigroup with onDemandCount set ("risk": null) #123

Open
alvarof2 opened this issue Nov 17, 2020 · 0 comments
Assignees
Labels
kind/bug Categorizes an issue or PR as related to a bug.

Comments

@alvarof2
Copy link

Terraform Version

terraform -v
Terraform v0.13.5
+ provider registry.terraform.io/-/local v2.0.0
+ provider registry.terraform.io/-/spotinst v1.27.0
+ provider registry.terraform.io/hashicorp/local v2.0.0
+ provider registry.terraform.io/spotinst/spotinst v1.29.0

Affected Resource(s)

  • spotinst_elastigroup_aws

Terraform Configuration Files

resource "spotinst_elastigroup_aws" "elastic_search_warm" {
  name        = "ElasticSearch-warm"
  description = "Imported from auto scaling group: ElasticSearch-warm"
  product     = "Linux/UNIX"

  min_size         = 3
  max_size         = 21
  desired_capacity = 19
  capacity_unit    = "instance"

  region = "eu-west-1"
  subnet_ids = [
    "subnet-dae37c81",
    "subnet-64affc03",
    "subnet-4aba9f03",
  ]

  image_id             = "ami-0c050c28ba68b201b"
  iam_instance_profile = "arn:aws:iam::927637044349:instance-profile/ecsInstanceRole"
  key_name             = "my-key"
  security_groups = [
    "sg-62548719",
    "sg-69b86912",
  ]
  user_data         = data.local_file.cloud_config_elastic_search_warm.content_base64
  enable_monitoring = false
  ebs_optimized     = true
  placement_tenancy = "default"

  instance_types_ondemand = "i3.large"
  instance_types_spot = [
    "i3.large",
    "i3.xlarge",
  ]
  instance_types_preferred_spot = [
    "i3.large",
  ]

  orientation                = "balanced"
  fallback_to_ondemand       = true
  ondemand_count             = 4
  utilize_reserved_instances = true
  draining_timeout           = 120


  lifetime_period = "days"

  revert_to_spot {
    perform_at = "always"
  }

  health_check_type         = "EC2"
  health_check_grace_period = 300

  tags {
    key   = "Environment"
    value = "Shared"
  }
  tags {
    key   = "ESCluster"
    value = "empathyops"
  }
  tags {
    key   = "Name"
    value = "ElasticSearch"
  }
  tags {
    key   = "Service"
    value = "ElasticSearch-warm"
  }
  tags {
    key   = "Monitoring"
    value = "prometheus"
  }
  tags {
    key   = "Management"
    value = "Spotinst"
  }
}

Debug Output

Debug gist

Panic Output

Panic gist

Expected Behavior

Terraform executes as intended and produces a plan

Actual Behavior

Panic crash

Steps to Reproduce

  1. The elastigroup was already created through the GUI with ondemand_count: 4
  2. Trying to migrate its definition to Terraform, just execute terraform plan

Important Factoids

The elastigroup was already created through the GUI with ondemand_count: 4, which gives this json as its configuration:

...
    "strategy": {
      "risk": null,
      "onDemandCount": 4,
      "availabilityVsCost": "balanced",
      "drainingTimeout": 120,
      "utilizeReservedInstances": true,
      "fallbackToOd": true,
      "scalingStrategy": null,
      "persistence": {},
      "revertToSpot": {
        "performAt": "always"
      }
...

Changing the elastigroup configuration to e.g. spot_instances: 80 (no ondemand_count) makes "risk": 80 in above JSON, and the terraform plan works perfectly.

Hope this is not misleading, but I think the problem is in these lines in fields_spotinst_elastigroup_aws_strategy.go:

			var value *float64 = nil
			if elastigroup.Strategy != nil && elastigroup.Strategy.Risk != nil {
				value = elastigroup.Strategy.Risk
			}
			if err := resourceData.Set(string(SpotPercentage), spotinst.Int(int(*value))); err != nil {
				return fmt.Errorf(string(commons.FailureFieldReadPattern), string(SpotPercentage), err)
			}

As elastigroup.Strategy.Risk is null, value var remains nil and the cast in spotinst.Int(int(*value)) produces the panic. I think this is why changing the elastigroup configuration with a defined value for risk makes it work.

Community Note

  • Please vote on this issue by adding a 👍 reaction to help the community and maintainers prioritize this request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
@alvarof2 alvarof2 added the kind/bug Categorizes an issue or PR as related to a bug. label Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes an issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants