Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/44964.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_datazone_domain: Add `root_domain_unit_id` attribute
```

```release-note:enhancement
data-source/aws_datazone_domain: Add `root_domain_unit_id` attribute
```
17 changes: 17 additions & 0 deletions internal/service/datazone/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func (r *domainResource) Schema(ctx context.Context, request resource.SchemaRequ
stringplanmodifier.UseStateForUnknown(),
},
},
"root_domain_unit_id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
names.AttrServiceRole: schema.StringAttribute{
CustomType: fwtypes.ARNType,
Optional: true,
Expand Down Expand Up @@ -187,6 +193,16 @@ func (r *domainResource) Create(ctx context.Context, request resource.CreateRequ
return
}

// CreateDomain does not return root_domain_unit_id.
// It must be retrieved via GetDomain.
domain, err := findDomainByID(ctx, conn, data.ID.ValueString())
if err != nil {
response.Diagnostics.AddError(fmt.Sprintf("reading DataZone Domain (%s)", data.ID.ValueString()), err.Error())

return
}
data.RootDomainUnitId = fwflex.StringToFramework(ctx, domain.RootDomainUnitId)

response.Diagnostics.Append(response.State.Set(ctx, data)...)
}

Expand Down Expand Up @@ -385,6 +401,7 @@ type domainResourceModel struct {
KMSKeyIdentifier fwtypes.ARN `tfsdk:"kms_key_identifier"`
Name types.String `tfsdk:"name"`
PortalURL types.String `tfsdk:"portal_url"`
RootDomainUnitId types.String `tfsdk:"root_domain_unit_id"`
ServiceRole fwtypes.ARN `tfsdk:"service_role"`
SkipDeletionCheck types.Bool `tfsdk:"skip_deletion_check"`
SingleSignOn fwtypes.ListNestedObjectValueOf[singleSignOnModel] `tfsdk:"single_sign_on"`
Expand Down
16 changes: 14 additions & 2 deletions internal/service/datazone/domain_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (d *domainDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
Optional: true,
Computed: true,
},
"root_domain_unit_id": schema.StringAttribute{
Computed: true,
},
"portal_url": schema.StringAttribute{
Computed: true,
},
Expand Down Expand Up @@ -124,13 +127,21 @@ func (d *domainDataSource) ConfigValidators(_ context.Context) []datasource.Conf
}
}

func findDomain(ctx context.Context, conn *datazone.Client, filter tfslices.Predicate[*awstypes.DomainSummary]) (*awstypes.DomainSummary, error) {
func findDomain(ctx context.Context, conn *datazone.Client, filter tfslices.Predicate[*awstypes.DomainSummary]) (*datazone.GetDomainOutput, error) {
domain, err := findDomains(ctx, conn, filter)
if err != nil {
return nil, err
}

return tfresource.AssertSingleValueResult(domain)
domain1, err := tfresource.AssertSingleValueResult(domain)
if err != nil {
return nil, err
}
output, err := findDomainByID(ctx, conn, aws.ToString(domain1.Id))
if err != nil {
return nil, err
}
return output, nil
}

func findDomains(ctx context.Context, conn *datazone.Client, filter tfslices.Predicate[*awstypes.DomainSummary]) ([]awstypes.DomainSummary, error) {
Expand Down Expand Up @@ -163,6 +174,7 @@ type domainDataSourceModel struct {
LastUpdatedAt timetypes.RFC3339 `tfsdk:"last_updated_at"`
ManagedAccountID types.String `tfsdk:"managed_account_id"`
Name types.String `tfsdk:"name"`
RootDomainUnitID types.String `tfsdk:"root_domain_unit_id"`
PortalURL types.String `tfsdk:"portal_url"`
Status types.String `tfsdk:"status"`
}
4 changes: 4 additions & 0 deletions internal/service/datazone/domain_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func TestAccDataZoneDomainDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrID, resourceName, names.AttrID),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrName, resourceName, names.AttrName),
resource.TestCheckResourceAttrPair(dataSourceName, "root_domain_unit_id", resourceName, "root_domain_unit_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "portal_url", resourceName, "portal_url"),
resource.TestCheckResourceAttrPair(dataSourceName, "domain_version", resourceName, "domain_version"),
),
},
},
Expand All @@ -54,6 +57,7 @@ func TestAccDataZoneDomainDataSource_name(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrID, resourceName, names.AttrID),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrName, resourceName, names.AttrName),
resource.TestCheckResourceAttrPair(dataSourceName, "root_domain_unit_id", resourceName, "root_domain_unit_id"),
),
},
},
Expand Down
15 changes: 15 additions & 0 deletions internal/service/datazone/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestAccDataZoneDomain_basic(t *testing.T) {
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "datazone", "domain/{id}"),
resource.TestCheckResourceAttr(resourceName, "domain_version", "V1"),
resource.TestCheckNoResourceAttr(resourceName, names.AttrServiceRole),
resource.TestCheckResourceAttrSet(resourceName, "root_domain_unit_id"),
),
},
{
Expand All @@ -52,6 +53,20 @@ func TestAccDataZoneDomain_basic(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{names.AttrApplyImmediately, "user", "skip_deletion_check"},
},
{
Config: testAccDomainConfig_description(rName, "test_description"),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName, &domain),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttrSet(resourceName, "portal_url"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrID),
acctest.CheckResourceAttrRegionalARNFormat(ctx, resourceName, names.AttrARN, "datazone", "domain/{id}"),
resource.TestCheckResourceAttr(resourceName, "domain_version", "V1"),
resource.TestCheckNoResourceAttr(resourceName, names.AttrServiceRole),
resource.TestCheckResourceAttrSet(resourceName, "root_domain_unit_id"),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "test_description"),
),
},
},
})
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/datazone_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ This data source exports the following attributes in addition to the arguments a
* `last_updated_at` - The date and time the Domain was last updated.
* `managed_account_id` - The AWS account ID that owns the Domain.
* `portal_url` - URL of the Domain.
* `root_domain_unit_id` - ID of the root domain unit.
* `status` - Status of the Domain.
1 change: 1 addition & 0 deletions website/docs/r/datazone_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ This resource exports the following attributes in addition to the arguments abov
* `arn` - ARN of the Domain.
* `id` - ID of the Domain.
* `portal_url` - URL of the data portal for the Domain.
* `root_domain_unit_id` - ID of the root domain unit.
* `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).

## Timeouts
Expand Down
Loading