Skip to content

Error when trying to create a common base class for AWS Provider #2855

Open
@suvhotta

Description

@suvhotta

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

cdktf: 0.15.5
aws_provider: hashicorp/aws@~>3.0

Affected Resource(s)

I'm trying to create a common base class for all my stacks using AWS provider as follows:
base.py:

|class AWSBaseStack(TerraformStack):
| def init(self, scope: Construct, ns: str, region):
| super().init(scope, ns)
| AwsProvider(self, "AWS", region=region)

My stack looks like this:

|class EC2Stack(AWSBaseStack):
| def init(self, scope: Construct, ns: str, name: str, ami: str, ssh_sg_id: str, region):
| super().init(scope, ns, region)
| instance = Instance(self, name,
| ami=ami,
| instance_type="t2.micro",
| key_name="test-dev-ew1",
| associate_public_ip_address=True,
| subnet_id="subnet-123x439a17r3567l0",
| security_groups=[f"{ssh_sg_id}"]
| )

| TerraformOutput(self, "ec2-arn", value=instance.arn)

### Actual Behavior It is throwing the following error:
                    │ Error: Required plugins are not installed
                    │ 
                    │ The installed provider plugins are not consistent with the packages selected
                    │ in the dependency lock file:
                    │   - registry.terraform.io/hashicorp/aws: the cached package for registry.terraform.io/hashicorp/aws 3.76.1 (in .terraform/providers) does not match any of the checksums recorded in the dependency lock file
                    │ 
                    │ Terraform uses external plugins to integrate with a variety of different
                    │ infrastructure services. To download the plugins required for this
                    │ configuration, run:
                    │   terraform init
                    ╵

This error disappears when I use the provider normally inside the init method of the stack.

Am I doing anything wrong here? Is this the right way to re-use the aws providers or is there any better way to do the same?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcdktf-cliconfirmedindependently reproduced by an engineer on the teampriority/important-longtermMedium priority, to be worked on within the following 1-2 business quarters.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions