Hi there! I am trying to implement an API Gateway by using AWS Classic registry (pulumi-aws). I am h...
b
Hi there! I am trying to implement an API Gateway by using AWS Classic registry (pulumi-aws). I am having some headache with the API Deployment part. I started with this code:
Copy code
self._deployment = aws.apigateway.Deployment(f"{logic_name}-deployment",
            rest_api=self._args.api.id,
            triggers= self.compute_deploy_triggers(),
            opts=ResourceOptions(
                parent=self,
            )
        )

        self._stage = aws.apigateway.Stage(f"{logic_name}-stage",
            rest_api=self._args.api.id,
            stage_name=self._args.stage_name,
            # deployment=self._deployment.id,
            opts=ResourceOptions(
                parent=self
            )
        )
This is inside a ComponentResource, so the RestAPI and stage name are saved as _args. The issue is that with this configuration, whenever the deployment gets replaced i have this error:
sdk-v2/provider2.go572 sdk.helper_schema: deleting API Gateway Deployment (xxxxx): operation error API Gateway: DeleteDeployment, https response error StatusCode: 400, RequestID: xxxx, BadRequestException: Active stages pointing to this deployment must be moved or deleted: provider=aws@6.83.0
I have tried to work with some pulumi Resource Options, by changing the stage as follows:
Copy code
self._stage = aws.apigateway.Stage(f"{logic_name}-stage",
            rest_api=self._args.api.id,
            stage_name=self._args.stage_name,
            deployment=self._deployment.id,
            opts=ResourceOptions(
                parent=self,
                depends_on=[self._deployment],
                delete_before_replace=True,
                replace_on_changes=["deployment"],
            )
        )
Doing this solves this error, as both resources are deleted before being re-created. In doing so, I break another piece of code though, because there is a usage-plan that uses the stage and when I replace it the usage plan doesn't react and updates it, therefore the only way is to also update the usage plan like this:
Copy code
self.usage_plan = aws.apigateway.UsagePlan("usage-plan",
            api_stages=[
                aws.apigateway.UsagePlanApiStageArgs(
                    api_id=api.id,
                    stage=self._stage.stage_name
                )
            ],
            #
            opts=ResourceOptions(
                parent=self,
                replace_on_changes=["api_stages"]
            )
        )
All this seems kinda clunky for what I honestly thought was a trivial thing to implement. I am used to work in Terraform where it is way easier to create the same stuff. Am I missing something obvious maybe? Do you guys have implemented the same architecture in a easier way? Thank you in advance 🙂
l
That all looks correct, except the UsagePlan should be automatically deleted by Pulumi before the Stage even without your opts, since the
stage_name
property is an output of the Stage resource. Unless you've got some code to change that? Is
_stage
the actual Stage resource, and
stage_name
is an Output?
b
Thank you for your help @little-cartoon-10569! I think so. The only code part I have actually simplified above is that the stage is inside a ComponentResource and the usage plan is outside of that. Therefore, I have a "get_stage()" method that returns that "self._stage" (which is a _pulumi_aws.apigateway.Stage_ resource) and then I do a:
Copy code
stage=component.get_stage().stage_name
Inside the usage_plan. Could it be something wrong with that?
l
If you're returning an output, then it should be good. That's what holds the dependency info.
b
You mean that the "get_stage()" method should return an Output[T] or that the .stage_name should be ? Just to be sure.
l
The output that came back from when the resource was created should never be resolved. Keep passing resource output properties around as outputs, and all will be well.
👍 1