in internal/services/azapi_resource.go [111:380]
func (r *AzapiResource) Schema(ctx context.Context, _ resource.SchemaRequest, response *resource.SchemaResponse) {
response.Schema = schema.Schema{
MarkdownDescription: "This resource can manage any Azure Resource Manager resource.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
MarkdownDescription: docstrings.ID(),
},
"name": schema.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
MarkdownDescription: "Specifies the name of the azure resource. Changing this forces a new resource to be created.",
},
"parent_id": schema.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
myvalidator.StringIsResourceID(),
},
MarkdownDescription: docstrings.ParentID(),
},
"type": schema.StringAttribute{
Required: true,
Validators: []validator.String{
myvalidator.StringIsResourceType(),
},
MarkdownDescription: docstrings.Type(),
},
"location": schema.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
myplanmodifier.UseStateWhen(func(a, b types.String) bool {
return location.Normalize(a.ValueString()) == location.Normalize(b.ValueString())
}),
},
MarkdownDescription: docstrings.Location(),
},
// The body attribute is a dynamic attribute that only allows users to specify the resource body as an HCL object
"body": schema.DynamicAttribute{
Optional: true,
Computed: true,
// in the previous version, the default value is string "{}", now it's a dynamic value {}
Default: defaults.DynamicDefault(types.ObjectValueMust(map[string]attr.Type{}, map[string]attr.Value{})),
PlanModifiers: []planmodifier.Dynamic{
myplanmodifier.DynamicUseStateWhen(dynamic.SemanticallyEqual),
},
MarkdownDescription: docstrings.Body(),
Validators: []validator.Dynamic{
myvalidator.DynamicIsNotStringValidator(),
},
},
"sensitive_body": schema.DynamicAttribute{
Optional: true,
WriteOnly: true,
MarkdownDescription: docstrings.SensitiveBody(),
},
"replace_triggers_external_values": schema.DynamicAttribute{
Optional: true,
MarkdownDescription: "Will trigger a replace of the resource when the value changes and is not `null`. This can be used by practitioners to force a replace of the resource when certain values change, e.g. changing the SKU of a virtual machine based on the value of variables or locals. " +
"The value is a `dynamic`, so practitioners can compose the input however they wish. For a \"break glass\" set the value to `null` to prevent the plan modifier taking effect. \n" +
"If you have `null` values that you do want to be tracked as affecting the resource replacement, include these inside an object. \n" +
"Advanced use cases are possible and resource replacement can be triggered by values external to the resource, for example when a dependent resource changes.\n\n" +
"e.g. to replace a resource when either the SKU or os_type attributes change:\n" +
"\n" +
"```hcl\n" +
"resource \"azapi_resource\" \"example\" {\n" +
" name = var.name\n" +
" type = \"Microsoft.Network/publicIPAddresses@2023-11-01\"\n" +
" parent_id = \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example\"\n" +
" body = {\n" +
" properties = {\n" +
" sku = var.sku\n" +
" zones = var.zones\n" +
" }\n" +
" }\n" +
"\n" +
" replace_triggers_external_values = [\n" +
" var.sku,\n" +
" var.zones,\n" +
" ]\n" +
"}\n" +
"```\n",
PlanModifiers: []planmodifier.Dynamic{
planmodifierdynamic.RequiresReplaceIfNotNull(),
},
},
"replace_triggers_refs": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
MarkdownDescription: "A list of paths in the current Terraform configuration. When the values at these paths change, the resource will be replaced.",
},
"ignore_casing": schema.BoolAttribute{
Optional: true,
Computed: true,
Default: defaults.BoolDefault(false),
MarkdownDescription: docstrings.IgnoreCasing(),
},
"ignore_missing_property": schema.BoolAttribute{
Optional: true,
Computed: true,
Default: defaults.BoolDefault(true),
MarkdownDescription: docstrings.IgnoreMissingProperty(),
},
"response_export_values": schema.DynamicAttribute{
Optional: true,
PlanModifiers: []planmodifier.Dynamic{
myplanmodifier.DynamicUseStateWhen(dynamic.SemanticallyEqual),
},
MarkdownDescription: docstrings.ResponseExportValues(),
},
"locks": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
Validators: []validator.List{
listvalidator.ValueStringsAre(myvalidator.StringIsNotEmpty()),
},
MarkdownDescription: docstrings.Locks(),
},
"schema_validation_enabled": schema.BoolAttribute{
Optional: true,
Computed: true,
Default: defaults.BoolDefault(true),
MarkdownDescription: docstrings.SchemaValidationEnabled(),
},
"output": schema.DynamicAttribute{
Computed: true,
MarkdownDescription: docstrings.Output("azapi_resource"),
},
"tags": schema.MapAttribute{
ElementType: types.StringType,
Optional: true,
Computed: true,
Validators: []validator.Map{
tags.Validator(),
},
MarkdownDescription: "A mapping of tags which should be assigned to the Azure resource.",
},
"retry": retry.RetrySchema(ctx),
"create_headers": schema.MapAttribute{
ElementType: types.StringType,
Optional: true,
MarkdownDescription: "A mapping of headers to be sent with the create request.",
},
"create_query_parameters": schema.MapAttribute{
ElementType: types.ListType{
ElemType: types.StringType,
},
Optional: true,
MarkdownDescription: "A mapping of query parameters to be sent with the create request.",
},
"update_headers": schema.MapAttribute{
ElementType: types.StringType,
Optional: true,
MarkdownDescription: "A mapping of headers to be sent with the update request.",
},
"update_query_parameters": schema.MapAttribute{
ElementType: types.ListType{
ElemType: types.StringType,
},
Optional: true,
MarkdownDescription: "A mapping of query parameters to be sent with the update request.",
},
"delete_headers": schema.MapAttribute{
ElementType: types.StringType,
Optional: true,
MarkdownDescription: "A mapping of headers to be sent with the delete request.",
},
"delete_query_parameters": schema.MapAttribute{
ElementType: types.ListType{
ElemType: types.StringType,
},
Optional: true,
MarkdownDescription: "A mapping of query parameters to be sent with the delete request.",
},
"read_headers": schema.MapAttribute{
ElementType: types.StringType,
Optional: true,
MarkdownDescription: "A mapping of headers to be sent with the read request.",
},
"read_query_parameters": schema.MapAttribute{
ElementType: types.ListType{
ElemType: types.StringType,
},
Optional: true,
MarkdownDescription: "A mapping of query parameters to be sent with the read request.",
},
},
Blocks: map[string]schema.Block{
"identity": schema.ListNestedBlock{
NestedObject: schema.NestedBlockObject{
Validators: []validator.Object{myvalidator.IdentityValidator()},
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{
Required: true,
Validators: []validator.String{stringvalidator.OneOf(
string(identity.SystemAssignedUserAssigned),
string(identity.UserAssigned),
string(identity.SystemAssigned),
string(identity.None),
)},
MarkdownDescription: docstrings.IdentityType(),
},
"identity_ids": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
Validators: []validator.List{
listvalidator.ValueStringsAre(myvalidator.StringIsUserAssignedIdentityID()),
},
MarkdownDescription: docstrings.IdentityIds(),
},
"principal_id": schema.StringAttribute{
Computed: true,
MarkdownDescription: docstrings.IdentityPrincipalID(),
},
"tenant_id": schema.StringAttribute{
Computed: true,
MarkdownDescription: docstrings.IdentityTenantID(),
},
},
},
},
"timeouts": timeouts.Block(ctx, timeouts.Opts{
Create: true,
Update: true,
Read: true,
Delete: true,
}),
},
Version: 2,
}
}