In the implementation of a Terraform Provider, how do I differentiate between an empty string and a null value?

I am currently working on building a Terraform Provider (doesn’t use the Terraform Plugin Framework, instead the legacy SDK terraform-plugin-sdk/v2 v2.26.1) in which I would like to fix a problem I’m seeing with a resource.

In the resource, I have a bunch of attributes of the TypeString datatype. From the customer’s end, when the configuration of the resource is written, these attributes can either be specified as valid non empty strings, or as empty strings "", or do not need to be specified at all.

What I would like to achieve is two fold (both of these are needed to flag some cases I need in my project)

  • (1) to add a function in the read method of the resource (which shall be called upon terraform plans subsequently run after the first terraform apply) which can identify if these attributes are specified as empty strings in the configuration of the resource, but not when they’re not specified in the configuration at all.
  • (2) in addition to this, this function would also need to compare how the attributes were specified upon the first terraform apply (for example, flag cases in which the attribute was earlier not specified in the configuration at all, and then terraform apply was done, after which this attribute was added to the configuration with the value “”).

First Problem (1)

Upon using functions such as d.Get(), d.GetOk, d.GetChange (where d is an object of type *schema.ResourceData) in the read function of the resource, they don’t seem to get the value of this attribute from the configuration of the resource specified by the customer, like they do when we use them in create function with d.Get().

However, my requirement is to have a function which can directly get the value of an attribute from the configuration of the resource (and not from the state). I don’t seem to find an exclusive function which can get values of attributes only from the configuration specified by the customer. Such a function will help me find if the current value of the attribute in the configuration is an empty string, or if the attribute does not exist at all.

Second Problem (2)

In order to find the existing value of these attributes in the state, interestingly, what I see is when the attributes are not specified in the configuration of the resource and terraform apply works, they are saved as null in the state; however, if they are actually specified as empty strings and terraform apply works, they are saved as empty strings in the state.

However, when I use functions such as d.GetOk() or d.Get() or d.GetChange(), in all cases, Terraform seems to not be able to identify the difference between both cases; if the attribute in the state has a null value, or if it has an empty string value.

This is understandable, because all of the functions I’ve stated above return interfaces, and for an interface which does not have a rigid type, be it an empty string or null, everything is the same. However, I need something to suffice my requirement here too.

The closest I’ve been able to get to fix the second issue is by using a function called d.State(). This seems to be printing the state of the resource, but not those attributes which have null values (though it does seem to print attributes which have empty string values), so I might still be able to use this solve my problem, but if there is no other alternative.

Help, please!

Would really appreciate if Terraform experts can help me with this 🙂 thank you in advance!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

In the implementation of a Terraform Provider, how do I differentiate between an empty string and a null value?

I am currently working on building a Terraform Provider (doesn’t use the Terraform Plugin Framework, instead the legacy SDK terraform-plugin-sdk/v2 v2.26.1) in which I would like to fix a problem I’m seeing with a resource.

In the resource, I have a bunch of attributes of the TypeString datatype. From the customer’s end, when the configuration of the resource is written, these attributes can either be specified as valid non empty strings, or as empty strings "", or do not need to be specified at all.

What I would like to achieve is two fold (both of these are needed to flag some cases I need in my project)

  • (1) to add a function in the read method of the resource (which shall be called upon terraform plans subsequently run after the first terraform apply) which can identify if these attributes are specified as empty strings in the configuration of the resource, but not when they’re not specified in the configuration at all.
  • (2) in addition to this, this function would also need to compare how the attributes were specified upon the first terraform apply (for example, flag cases in which the attribute was earlier not specified in the configuration at all, and then terraform apply was done, after which this attribute was added to the configuration with the value “”).

First Problem (1)

Upon using functions such as d.Get(), d.GetOk, d.GetChange (where d is an object of type *schema.ResourceData) in the read function of the resource, they don’t seem to get the value of this attribute from the configuration of the resource specified by the customer, like they do when we use them in create function with d.Get().

However, my requirement is to have a function which can directly get the value of an attribute from the configuration of the resource (and not from the state). I don’t seem to find an exclusive function which can get values of attributes only from the configuration specified by the customer. Such a function will help me find if the current value of the attribute in the configuration is an empty string, or if the attribute does not exist at all.

Second Problem (2)

In order to find the existing value of these attributes in the state, interestingly, what I see is when the attributes are not specified in the configuration of the resource and terraform apply works, they are saved as null in the state; however, if they are actually specified as empty strings and terraform apply works, they are saved as empty strings in the state.

However, when I use functions such as d.GetOk() or d.Get() or d.GetChange(), in all cases, Terraform seems to not be able to identify the difference between both cases; if the attribute in the state has a null value, or if it has an empty string value.

This is understandable, because all of the functions I’ve stated above return interfaces, and for an interface which does not have a rigid type, be it an empty string or null, everything is the same. However, I need something to suffice my requirement here too.

The closest I’ve been able to get to fix the second issue is by using a function called d.State(). This seems to be printing the state of the resource, but not those attributes which have null values (though it does seem to print attributes which have empty string values), so I might still be able to use this solve my problem, but if there is no other alternative.

Help, please!

Would really appreciate if Terraform experts can help me with this 🙂 thank you in advance!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật