aws / amazon-ec2-metadata-mock

A tool to simulate Amazon EC2 instance metadata
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
Apache License 2.0
266 stars 44 forks source link

marketplaceProductCodes field is typed as a string instead of a list of strings #179

Closed okofish closed 2 years ago

okofish commented 2 years ago

Describe the bug The marketplaceProductCodes field in the instance identity document structure is typed as a string. This doesn't match the structure of the real document, in which it is a list of strings (as documented).

Steps to reproduce

  1. Create a file overrides.json with the following contents:

    {
    "dynamic": {
        "values": {
            "instance-identity-document": {
                "accountId": "123456789012",
                "architecture": "x86_64",
                "availabilityZone": "us-east-1a",
                "billingProducts": null,
                "devpayProductCodes": null,
                "marketplaceProductCodes": [
                    "4i20ezfza3p7xx2kt2g8weu2u"
                ],
                "imageId": "ami-02f471c4f805553d3",
                "instanceId": "i-048bcb15d2686eec7",
                "instanceType": "t2.nano",
                "kernelId": null,
                "pendingTime": "2022-06-23T06:21:55Z",
                "privateIp": "172.31.85.190",
                "ramdiskId": null,
                "region": "us-east-1",
                "version": "2017-09-30"
            }
        }
    }
    }
  2. Run ec2-metadata-mock -c overrides.json.

The program exits with an error message about the type of the marketplaceProductCodes field.

Expected outcome The application starts up and serves the supplied instance identity document.

Application Logs

$ ec2-metadata-mock -c overrides.json 
Using configuration from file:  overrides.json
Error: Fatal error while attempting to load viper config: 1 error(s) decoding:

* 'dynamic.values.instance-identity-document.MarketplaceProductCodes' expected type 'string', got unconvertible type '[]interface {}', value: '[4i20ezfza3p7xx2kt2g8weu2u]'
Usage:
  ec2-metadata-mock <command> [arguments] [flags]
  ec2-metadata-mock [command]

Examples:
  ec2-metadata-mock --mock-delay-sec 10 mocks all metadata paths
  ec2-metadata-mock spot --action terminate     mocks spot ITN only

Available Commands:
  completion  generate the autocompletion script for the specified shell
  events      Mock EC2 maintenance events
  help        Help about any command
  spot        Mock EC2 Spot interruption notice

Flags:
  -c, --config-file string              config file for cli input parameters in json format (default: $HOME/aemm-config.json)
  -h, --help                            help for ec2-metadata-mock
  -n, --hostname string                 the HTTP hostname for the mock url (default: 0.0.0.0)
  -I, --imdsv2                          whether to enable IMDSv2 only, requiring a session token when submitting requests (default: false, meaning both IMDS v1 and v2 are enabled)
  -d, --mock-delay-sec int              spot itn delay in seconds, relative to the application start time (default: 0 seconds)
  -x, --mock-ip-count int               number of IPs in a cluster that can receive a Spot Interrupt Notice and/or Scheduled Event (default 2)
      --mock-trigger-time string        spot itn trigger time in RFC3339 format. This takes priority over mock-delay-sec (default: none)
  -p, --port string                     the HTTP port where the mock runs (default: 1338)
      --rebalance-delay-sec int         rebalance rec delay in seconds, relative to the application start time (default: 0 seconds)
      --rebalance-trigger-time string   rebalance rec trigger time in RFC3339 format. This takes priority over rebalance-delay-sec (default: none)
  -s, --save-config-to-file             whether to save processed config from all input sources in .ec2-metadata-mock/.aemm-config-used.json in $HOME or working dir, if homedir is not found (default: false)
  -v, --version                         version for ec2-metadata-mock

Use "ec2-metadata-mock [command] --help" for more information about a command.

panic: Fatal error while executing the root command: Fatal error while attempting to load viper config: 1 error(s) decoding:

* 'dynamic.values.instance-identity-document.MarketplaceProductCodes' expected type 'string', got unconvertible type '[]interface {}', value: '[4i20ezfza3p7xx2kt2g8weu2u]'

goroutine 1 [running]:
main.main()
        /amazon-ec2-metadata-mock/cmd/amazon-ec2-metadata-mock.go:25 +0x73

Environment

brycahta commented 2 years ago

Appreciate the call out; fix on the way