• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/python/pants/backend/terraform/target_types.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

UNCOV
4
from __future__ import annotations
×
5

UNCOV
6
from dataclasses import dataclass
×
7

UNCOV
8
from pants.engine.internals.native_engine import AddressInput
×
UNCOV
9
from pants.engine.rules import collect_rules, rule
×
UNCOV
10
from pants.engine.target import (
×
11
    COMMON_TARGET_FIELDS,
12
    AllTargets,
13
    AsyncFieldMixin,
14
    Dependencies,
15
    DescriptionField,
16
    FieldSet,
17
    MultipleSourcesField,
18
    SingleSourceField,
19
    StringField,
20
    Target,
21
    Targets,
22
    generate_multiple_sources_field_help_message,
23
)
UNCOV
24
from pants.util.strutil import help_text, softwrap
×
25

26

UNCOV
27
class TerraformDependenciesField(Dependencies):
×
UNCOV
28
    pass
×
29

30

UNCOV
31
class TerraformModuleSourcesField(MultipleSourcesField):
×
UNCOV
32
    default = ("*.tf",)
×
UNCOV
33
    expected_file_extensions = (".tf",)
×
UNCOV
34
    ban_subdirectories = True
×
UNCOV
35
    help = generate_multiple_sources_field_help_message(
×
36
        "Example: `sources=['example.tf', 'new_*.tf', '!old_ignore.tf']`"
37
    )
38

39

UNCOV
40
@dataclass(frozen=True)
×
UNCOV
41
class TerraformFieldSet(FieldSet):
×
UNCOV
42
    required_fields = (TerraformModuleSourcesField,)
×
43

UNCOV
44
    sources: TerraformModuleSourcesField
×
UNCOV
45
    dependencies: TerraformDependenciesField
×
46

47

UNCOV
48
class TerraformModuleTarget(Target):
×
UNCOV
49
    alias = "terraform_module"
×
UNCOV
50
    core_fields = (*COMMON_TARGET_FIELDS, TerraformDependenciesField, TerraformModuleSourcesField)
×
UNCOV
51
    help = help_text(
×
52
        """
53
        A single Terraform module corresponding to a directory.
54

55
        There must only be one `terraform_module` in a directory.
56

57
        Use `terraform_modules` to generate `terraform_module` targets for less boilerplate.
58
        """
59
    )
60

61

UNCOV
62
class TerraformRootModuleField(StringField, AsyncFieldMixin):
×
63
    """The module to use as the root module for a Terraform deployment."""
64

UNCOV
65
    required = True
×
UNCOV
66
    alias = "root_module"
×
UNCOV
67
    help = help_text(
×
68
        """
69
        The Terraform module to use as the root module.
70

71
        Example: `root_module=":my_module"`
72
        """
73
    )
74

UNCOV
75
    def to_address_input(self) -> AddressInput:
×
76
        if not self.value:
×
77
            raise ValueError(
×
78
                softwrap(
79
                    f"""
80
            A Terraform deployment must have a nonempty {self.alias} field,
81
             but {self.address} was empty"""
82
                )
83
            )
84
        return AddressInput.parse(
×
85
            self.value,
86
            relative_to=self.address.spec_path,
87
            description_of_origin=f"the `{self.alias} field in the `{TerraformDeploymentTarget.alias}` target {self.address}",
88
        )
89

90

UNCOV
91
class TerraformBackendConfigField(SingleSourceField):
×
UNCOV
92
    default = ".tfbackend"
×
UNCOV
93
    help = "Configuration to be merged with what is in the root module's 'backend' block"
×
94

95

UNCOV
96
class TerraformBackendTarget(Target):
×
UNCOV
97
    alias = "terraform_backend"
×
UNCOV
98
    core_fields = (*COMMON_TARGET_FIELDS, TerraformBackendConfigField)
×
UNCOV
99
    help = "Configuration to be merged with what is in the root module's 'backend' block"
×
100

101

UNCOV
102
class TerraformVarFileSourceField(MultipleSourcesField):
×
UNCOV
103
    default = ("*.tfvars",)
×
UNCOV
104
    expected_file_extensions = (".tfvars",)
×
UNCOV
105
    help = generate_multiple_sources_field_help_message(
×
106
        "Example: `sources=['common.tfvars', 'prod.tfvars']`"
107
    )
108

109

UNCOV
110
class TerraformVarFileTarget(Target):
×
UNCOV
111
    alias = "terraform_var_files"
×
UNCOV
112
    core_fields = (*COMMON_TARGET_FIELDS, TerraformVarFileSourceField)
×
UNCOV
113
    help = "Terraform vars files"
×
114

115

UNCOV
116
class TerraformDeploymentTarget(Target):
×
UNCOV
117
    alias = "terraform_deployment"
×
UNCOV
118
    core_fields = (
×
119
        *COMMON_TARGET_FIELDS,
120
        TerraformDependenciesField,
121
        TerraformRootModuleField,
122
    )
UNCOV
123
    help = "A deployment of Terraform"
×
124

125

UNCOV
126
@dataclass(frozen=True)
×
UNCOV
127
class TerraformDeploymentFieldSet(FieldSet):
×
UNCOV
128
    required_fields = (
×
129
        TerraformDependenciesField,
130
        TerraformRootModuleField,
131
    )
UNCOV
132
    description: DescriptionField
×
UNCOV
133
    root_module: TerraformRootModuleField
×
UNCOV
134
    dependencies: TerraformDependenciesField
×
135

136

UNCOV
137
class AllTerraformDeploymentTargets(Targets):
×
UNCOV
138
    pass
×
139

140

UNCOV
141
@rule
×
UNCOV
142
async def all_terraform_deployment_targets(targets: AllTargets) -> AllTerraformDeploymentTargets:
×
143
    return AllTerraformDeploymentTargets(
×
144
        tgt for tgt in targets if TerraformDeploymentFieldSet.is_applicable(tgt)
145
    )
146

147

UNCOV
148
class LockfileSourceField(SingleSourceField):
×
149
    """Source field for synthesized `_lockfile` targets."""
150

UNCOV
151
    default = ".terraform.lock.hcl"
×
152

153

UNCOV
154
class LockfileDependenciesField(Dependencies):
×
UNCOV
155
    pass
×
156

157

UNCOV
158
class TerraformLockfileTarget(Target):
×
UNCOV
159
    alias = "_terraform_lockfile"
×
UNCOV
160
    core_fields = (*COMMON_TARGET_FIELDS, LockfileSourceField, LockfileDependenciesField)
×
UNCOV
161
    help = help_text(
×
162
        """
163
        A target for lockfiles in order to include them in the dependency graph of other targets.
164

165
        This tracks them so that `--changed-since --changed-dependents` works properly for targets
166
        relying on a particular lockfile.
167
        """
168
    )
169

170

UNCOV
171
def rules():
×
172
    return collect_rules()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc