nix-community / nixops-gce

NixOps Google Cloud Backend
25 stars 8 forks source link

Setting region for resources.gceStaticIPs.<name> seems to be broken #21

Open rprije opened 2 years ago

rprije commented 2 years ago

I have a GCE static IP I'm trying to define like this:

  resources.gceStaticIPs.<name> = credentials // {
    name = "<name>";
    ipAddress = "<ip address>";
    region = "<region>";
  };

Without the region attribute, this passes validation. With region included I get the following error:

Traceback (most recent call last):
  File "/nix/store/55bgjfnjsgaqwfiy5rzfgcklv6b3m2fp-python3.8-nixops-2.0.0/bin/.nixops-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/1z9i3wk9a9z8cldgh28khkwfpk938hrl-python3-3.8.9-env/lib/python3.8/site-packages/nixops/__main__.py", line 710, in main
    args.op(args)
  File "/nix/store/1z9i3wk9a9z8cldgh28khkwfpk938hrl-python3-3.8.9-env/lib/python3.8/site-packages/nixops/script_defs.py", line 338, in op_info
    do_eval(depl)
  File "/nix/store/1z9i3wk9a9z8cldgh28khkwfpk938hrl-python3-3.8.9-env/lib/python3.8/site-packages/nixops/script_defs.py", line 246, in do_eval
    depl.evaluate()
  File "/nix/store/1z9i3wk9a9z8cldgh28khkwfpk938hrl-python3-3.8.9-env/lib/python3.8/site-packages/nixops/deployment.py", line 571, in evaluate
    defn = _create_definition(
  File "/nix/store/1z9i3wk9a9z8cldgh28khkwfpk938hrl-python3-3.8.9-env/lib/python3.8/site-packages/nixops/deployment.py", line 1797, in _create_definition
    return cls(name, nixops.resources.ResourceEval(config))
  File "/nix/store/1z9i3wk9a9z8cldgh28khkwfpk938hrl-python3-3.8.9-env/lib/python3.8/site-packages/nixops_gcp/resources/gce_static_ip.py", line 30, in __init__
    self.config.ip_address = self.config.ipAddress
  File "/nix/store/1z9i3wk9a9z8cldgh28khkwfpk938hrl-python3-3.8.9-env/lib/python3.8/site-packages/nixops/util.py", line 187, in __setattr__
    raise AttributeError(f"{self.__class__.__name__} is immutable")
AttributeError: GceStaticIpOptions is immutable

I suspect with low confidence this is because of https://github.com/nix-community/nixops-gce/blob/712453027486e62e087b9c91e4a8a171eebb6ddd/nixops_gcp/resources/gce_static_ip.py#L29

which maybe conflicts with how ImmutableValidatedObject already slurps this attribute into its dict and sets itself immutable. I think perhaps name doesn't have this problem, because it sets that value to self.addr_name and likewise ipAddress doesn't have the problem because that is set to self.config.ip_address both of which have different attribute names to the original set so would not conflict with what ImmutableValidatedObject automatically brings in.