Skip to content

Commit d153753

Browse files
ondrej-smolaianaya89
authored andcommitted
feat: support for aws permission boundary (#157)
build(deps): bump golangci/golangci-lint-action from 7.0.0 to 8.0.0 (#161) Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 7.0.0 to 8.0.0. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](golangci/golangci-lint-action@1481404...4afd733) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-version: 8.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ignacio Anaya <[email protected]> fix: make resource_prefix computed fix: set resource_prefix after create fix: set resource_prefix after update
1 parent f347078 commit d153753

File tree

12 files changed

+136
-66
lines changed

12 files changed

+136
-66
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- run: go mod download
2525
- run: go build -v .
2626
- name: Run linters
27-
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
27+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
2828
with:
2929
version: latest
3030

docs/data-sources/env_aws.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ Bring Your Own Cloud (BYOC) AWS environment data source.
6666
- `maintenance_windows` (Attributes List) List of maintenance windows during which automatic maintenance is permitted. By default updates are applied as soon as they are available. (see [below for nested schema](#nestedatt--maintenance_windows))
6767
- `node_groups` (Attributes Set) List of node groups. At least one required. (see [below for nested schema](#nestedatt--node_groups))
6868
- `peering_connections` (Attributes List) AWS environment VPC peering configuration. (see [below for nested schema](#nestedatt--peering_connections))
69+
- `permissions_boundary_policy_arn` (String) Policy ARN that sets the maximum permissions for the IAM roles created by the environment. **[IMMUTABLE]**
6970
- `region` (String) AWS region ([docs](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html#Concepts.RegionsAndAvailabilityZones.Regions)). **[IMMUTABLE]**
7071

7172
Examples:
7273
- "us-east-1"
7374
- "sa-east-1"
75+
- `resource_prefix` (String) Resource prefix used for provisioned resources **[IMMUTABLE]**
7476
- `skip_deprovision_on_destroy` (Boolean) Set to `true` will delete without waiting for environment deprovisioning. Use this with precaution, it may end up with dangling resources in your cloud provider (default `false`).
7577
- `spec_revision` (Number) Spec revision
7678
- `tags` (Attributes List) Tags to apply to AWS resources. (see [below for nested schema](#nestedatt--tags))

docs/resources/env_aws.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ resource "aws_vpc_peering_connection_accepter" "peer" {
258258
- `maintenance_windows` (Attributes List) List of maintenance windows during which automatic maintenance is permitted. By default updates are applied as soon as they are available. (see [below for nested schema](#nestedatt--maintenance_windows))
259259
- `nat` (Boolean) Enable AWS NAT Gateway. **[IMMUTABLE]**
260260
- `peering_connections` (Attributes List) AWS environment VPC peering configuration. (see [below for nested schema](#nestedatt--peering_connections))
261+
- `permissions_boundary_policy_arn` (String) Policy ARN that sets the maximum permissions for the IAM roles created by the environment. **[IMMUTABLE]**
262+
- `resource_prefix` (String) Resource prefix used for provisioned resources **[IMMUTABLE]**
261263
- `skip_deprovision_on_destroy` (Boolean) Set to `true` will delete without waiting for environment deprovisioning. Use this with precaution, it may end up with dangling resources in your cloud provider (default `false`).
262264
- `tags` (Attributes List) Tags to apply to AWS resources. (see [below for nested schema](#nestedatt--tags))
263265
- `zones` (List of String) Explicit list of AWS availability zones. At least 2 required.

internal/provider/common/docs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ const ENDPOINT_SERVICE_NAME_DESCRIPTION = "VPC endpoint service name in $endpoin
138138
const ENDPOINT_ALIAS_DESCRIPTION = "By default, VPC endpoints get assigned $endpoint_service_id.$env_name.altinity.cloud DNS record. Alias allows to override DNS record name to `$alias.$env_name.altinity.cloud`."
139139
const ENDPOINT_PRIVATE_DNS_DESCRIPTION = "`true` indicates whether to associate a private hosted zone with the specified VPC (default `false`)."
140140
const CLOUD_CONNECT_DESCRIPTION = "`true` indicates that cloud resources are to be managed via altinity/cloud-connect and `false` means direct management (default `true`). **[IMMUTABLE]**"
141+
const PERMISSIONS_BOUNDARY_POLICY_ARN_DESCRIPTION = "Policy ARN that sets the maximum permissions for the IAM roles created by the environment. **[IMMUTABLE]**"
142+
const RESOURCE_PREFIX_DESCRIPTION = "Resource prefix used for provisioned resources **[IMMUTABLE]**"
141143
const NAT_DESCRIPTION = "Enable AWS NAT Gateway. **[IMMUTABLE]**"
142144

143145
// GCP descriptions.

internal/provider/env/aws/model.go

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@ import (
99
)
1010

1111
type AWSEnvResourceModel struct {
12-
Id types.String `tfsdk:"id"`
13-
Name types.String `tfsdk:"name"`
14-
CustomDomain types.String `tfsdk:"custom_domain"`
15-
LoadBalancingStrategy types.String `tfsdk:"load_balancing_strategy"`
16-
Region types.String `tfsdk:"region"`
17-
NAT types.Bool `tfsdk:"nat"`
18-
CIDR types.String `tfsdk:"cidr"`
19-
AWSAccountID types.String `tfsdk:"aws_account_id"`
20-
Zones types.List `tfsdk:"zones"`
21-
LoadBalancers *LoadBalancersModel `tfsdk:"load_balancers"`
22-
NodeGroups []common.NodeGroupsModel `tfsdk:"node_groups"`
23-
PeeringConnections []AWSEnvPeeringConnectionModel `tfsdk:"peering_connections"`
24-
Endpoints []AWSEnvEndpointModel `tfsdk:"endpoints"`
25-
Tags []common.KeyValueModel `tfsdk:"tags"`
26-
CloudConnect types.Bool `tfsdk:"cloud_connect"`
27-
MaintenanceWindows []common.MaintenanceWindowModel `tfsdk:"maintenance_windows"`
12+
Id types.String `tfsdk:"id"`
13+
Name types.String `tfsdk:"name"`
14+
CustomDomain types.String `tfsdk:"custom_domain"`
15+
LoadBalancingStrategy types.String `tfsdk:"load_balancing_strategy"`
16+
Region types.String `tfsdk:"region"`
17+
PermissionsBoundaryPolicyArn types.String `tfsdk:"permissions_boundary_policy_arn"`
18+
ResourcePrefix types.String `tfsdk:"resource_prefix"`
19+
NAT types.Bool `tfsdk:"nat"`
20+
CIDR types.String `tfsdk:"cidr"`
21+
AWSAccountID types.String `tfsdk:"aws_account_id"`
22+
Zones types.List `tfsdk:"zones"`
23+
LoadBalancers *LoadBalancersModel `tfsdk:"load_balancers"`
24+
NodeGroups []common.NodeGroupsModel `tfsdk:"node_groups"`
25+
PeeringConnections []AWSEnvPeeringConnectionModel `tfsdk:"peering_connections"`
26+
Endpoints []AWSEnvEndpointModel `tfsdk:"endpoints"`
27+
Tags []common.KeyValueModel `tfsdk:"tags"`
28+
CloudConnect types.Bool `tfsdk:"cloud_connect"`
29+
MaintenanceWindows []common.MaintenanceWindowModel `tfsdk:"maintenance_windows"`
2830

2931
SpecRevision types.Int64 `tfsdk:"spec_revision"`
3032
ForceDestroy types.Bool `tfsdk:"force_destroy"`
@@ -102,20 +104,22 @@ func (e AWSEnvResourceModel) toSDK() (sdk.CreateAWSEnvInput, sdk.UpdateAWSEnvInp
102104
create := sdk.CreateAWSEnvInput{
103105
Name: e.Name.ValueString(),
104106
Spec: &sdk.CreateAWSEnvSpecInput{
105-
CustomDomain: e.CustomDomain.ValueStringPointer(),
106-
LoadBalancingStrategy: loadBalancingStrategy,
107-
LoadBalancers: LoadBalancers,
108-
NodeGroups: nodeGroups,
109-
Region: e.Region.ValueString(),
110-
Nat: e.NAT.ValueBoolPointer(),
111-
AWSAccountID: e.AWSAccountID.ValueString(),
112-
Cidr: e.CIDR.ValueString(),
113-
Zones: zones,
114-
PeeringConnections: peeringConnections,
115-
Endpoints: endpoints,
116-
Tags: tags,
117-
CloudConnect: &cloudConnect,
118-
MaintenanceWindows: maintenanceWindows,
107+
CustomDomain: e.CustomDomain.ValueStringPointer(),
108+
LoadBalancingStrategy: loadBalancingStrategy,
109+
LoadBalancers: LoadBalancers,
110+
NodeGroups: nodeGroups,
111+
Region: e.Region.ValueString(),
112+
Nat: e.NAT.ValueBoolPointer(),
113+
AWSAccountID: e.AWSAccountID.ValueString(),
114+
Cidr: e.CIDR.ValueString(),
115+
Zones: zones,
116+
PeeringConnections: peeringConnections,
117+
Endpoints: endpoints,
118+
Tags: tags,
119+
CloudConnect: &cloudConnect,
120+
MaintenanceWindows: maintenanceWindows,
121+
PermissionsBoundaryPolicyArn: e.PermissionsBoundaryPolicyArn.ValueStringPointer(),
122+
ResourcePrefix: e.ResourcePrefix.ValueStringPointer(),
119123
},
120124
}
121125

@@ -151,6 +155,8 @@ func (model *AWSEnvResourceModel) toModel(env sdk.GetAWSEnv_AWSEnv) {
151155
model.NodeGroups = nodeGroupsToModel(env.Spec.NodeGroups)
152156
model.MaintenanceWindows = maintenanceWindowsToModel(env.Spec.MaintenanceWindows)
153157
model.Zones = common.ListToModel(env.Spec.Zones)
158+
model.PermissionsBoundaryPolicyArn = types.StringPointerValue(env.Spec.PermissionsBoundaryPolicyArn)
159+
model.ResourcePrefix = types.StringValue(env.Spec.ResourcePrefix)
154160

155161
var peeringConnections []AWSEnvPeeringConnectionModel
156162
for _, p := range env.Spec.PeeringConnections {

internal/provider/env/aws/resource.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (r *AWSEnvResource) Create(ctx context.Context, req resource.CreateRequest,
5555
data.Zones = common.ListToModel(apiResp.CreateAWSEnv.Spec.Zones)
5656
data.NodeGroups = nodeGroupsToModel(apiResp.CreateAWSEnv.Spec.NodeGroups)
5757
data.SpecRevision = types.Int64Value(apiResp.CreateAWSEnv.SpecRevision)
58+
data.ResourcePrefix = types.StringValue(apiResp.CreateAWSEnv.Spec.ResourcePrefix)
5859

5960
tflog.Trace(ctx, "created resource", map[string]interface{}{"name": envName})
6061
diags = resp.State.Set(ctx, &data)
@@ -120,6 +121,7 @@ func (r *AWSEnvResource) Update(ctx context.Context, req resource.UpdateRequest,
120121
data.Zones = common.ListToModel(apiResp.UpdateAWSEnv.Spec.Zones)
121122
data.NodeGroups = nodeGroupsToModel(apiResp.UpdateAWSEnv.Spec.NodeGroups)
122123
data.SpecRevision = types.Int64Value(apiResp.UpdateAWSEnv.SpecRevision)
124+
data.ResourcePrefix = types.StringValue(apiResp.UpdateAWSEnv.Spec.ResourcePrefix)
123125

124126
tflog.Trace(ctx, "updated resource", map[string]interface{}{"name": envName})
125127
diags = resp.State.Set(ctx, &data)

internal/provider/env/aws/schema.go

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func (r *AWSEnvResource) Schema(ctx context.Context, req resource.SchemaRequest,
4141
"endpoints": getEndpointsAttribute(false, true, false),
4242
"tags": getTagsAttribute(false, true, false),
4343
"cloud_connect": getCloudConnectAttribute(false, true, true),
44+
"resource_prefix": getResourcePrefixAttribute(false, true, true),
45+
"permissions_boundary_policy_arn": getPermissionsBoundaryPolicyArnAttribute(false, true, false),
46+
4447
"spec_revision": common.SpecRevisionAttribute,
4548
"force_destroy": common.GetForceDestroyAttribute(false, true, true),
4649
"force_destroy_clusters": common.GetForceDestroyClustersAttribute(false, true, true),
@@ -54,23 +57,25 @@ func (d *AWSEnvDataSource) Schema(ctx context.Context, req datasource.SchemaRequ
5457
resp.Schema = dschema.Schema{
5558
MarkdownDescription: heredoc.Doc(`Bring Your Own Cloud (BYOC) AWS environment data source.`),
5659
Attributes: map[string]dschema.Attribute{
57-
"id": common.IDAttribute,
58-
"name": common.NameAttribute,
59-
"custom_domain": common.GetCommonCustomDomainAttribute(false, false, true),
60-
"load_balancers": getLoadBalancersAttribute(false, false, true),
61-
"load_balancing_strategy": common.GetLoadBalancingStrategyAttribute(false, false, true),
62-
"maintenance_windows": common.GetMaintenanceWindowAttribute(false, false, true),
63-
"cidr": common.GetCIDRAttribute(false, false, true),
64-
"zones": getZonesAttribute(false, false, true, common.AWS_ZONES_DESCRIPTION),
65-
"node_groups": common.GetNodeGroupsAttribute(false, false, true),
66-
"aws_account_id": getAWSAccountIDAttribute(false, false, true),
67-
"region": common.GetRegionAttribute(false, false, true, common.AWS_REGION_DESCRIPTION),
68-
"nat": getNATAttribute(false, true, true),
69-
"peering_connections": getPeeringConnectionsAttribute(false, false, true),
70-
"endpoints": getEndpointsAttribute(false, false, true),
71-
"tags": getTagsAttribute(false, false, true),
72-
"cloud_connect": getCloudConnectAttribute(false, false, true),
73-
"spec_revision": common.SpecRevisionAttribute,
60+
"id": common.IDAttribute,
61+
"name": common.NameAttribute,
62+
"custom_domain": common.GetCommonCustomDomainAttribute(false, false, true),
63+
"load_balancers": getLoadBalancersAttribute(false, false, true),
64+
"load_balancing_strategy": common.GetLoadBalancingStrategyAttribute(false, false, true),
65+
"maintenance_windows": common.GetMaintenanceWindowAttribute(false, false, true),
66+
"cidr": common.GetCIDRAttribute(false, false, true),
67+
"zones": getZonesAttribute(false, false, true, common.AWS_ZONES_DESCRIPTION),
68+
"node_groups": common.GetNodeGroupsAttribute(false, false, true),
69+
"aws_account_id": getAWSAccountIDAttribute(false, false, true),
70+
"region": common.GetRegionAttribute(false, false, true, common.AWS_REGION_DESCRIPTION),
71+
"nat": getNATAttribute(false, true, true),
72+
"peering_connections": getPeeringConnectionsAttribute(false, false, true),
73+
"endpoints": getEndpointsAttribute(false, false, true),
74+
"tags": getTagsAttribute(false, false, true),
75+
"cloud_connect": getCloudConnectAttribute(false, false, true),
76+
"permissions_boundary_policy_arn": getPermissionsBoundaryPolicyArnAttribute(false, false, true),
77+
"resource_prefix": getResourcePrefixAttribute(false, false, true),
78+
"spec_revision": common.SpecRevisionAttribute,
7479

7580
// these options are not used in data sources,
7681
// but we need to include them in the schema to avoid conversion errors.
@@ -204,6 +209,30 @@ func getNATAttribute(required, optional, computed bool) rschema.BoolAttribute {
204209
}
205210
}
206211

212+
func getPermissionsBoundaryPolicyArnAttribute(required, optional, computed bool) rschema.StringAttribute {
213+
return rschema.StringAttribute{
214+
Required: required,
215+
Optional: optional,
216+
Computed: computed,
217+
PlanModifiers: []planmodifier.String{
218+
modifiers.ImmutableString("permissions_boundary_policy_arn"),
219+
},
220+
MarkdownDescription: common.PERMISSIONS_BOUNDARY_POLICY_ARN_DESCRIPTION,
221+
}
222+
}
223+
224+
func getResourcePrefixAttribute(required, optional, computed bool) rschema.StringAttribute {
225+
return rschema.StringAttribute{
226+
Required: required,
227+
Optional: optional,
228+
Computed: computed,
229+
PlanModifiers: []planmodifier.String{
230+
modifiers.ImmutableString("resource_prefix"),
231+
},
232+
MarkdownDescription: common.RESOURCE_PREFIX_DESCRIPTION,
233+
}
234+
}
235+
207236
var endpointAttribute = rschema.NestedAttributeObject{
208237
Attributes: map[string]rschema.Attribute{
209238
"service_name": rschema.StringAttribute{

internal/provider/modifiers/inmutable_string.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func (m immutableStringModifier) PlanModifyString(ctx context.Context, req planm
3232
return
3333
}
3434

35+
// Skip check if the property is not present in the current configuration
36+
if req.ConfigValue.IsNull() {
37+
return
38+
}
39+
3540
if req.StateValue.ValueString() != req.PlanValue.ValueString() {
3641
resp.Diagnostics.AddAttributeError(path.Root(m.AttributeName), "Immutable Attribute", fmt.Sprintf("%s is immutable and cannot be modified after creation.", m.AttributeName))
3742
return

0 commit comments

Comments
 (0)